Skip to content

Commit 2477964

Browse files
committed
v9.5.1 add Tables
1 parent 39bbfe8 commit 2477964

4 files changed

Lines changed: 56 additions & 5 deletions

File tree

Engine/Scene.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
class Scene_Control:
55
"""Управления отображаемыми сценами"""
66

7-
def __init__(self, update_time=0, frame_time=0.001):
7+
def __init__(self, update_time=0, frame_time=0.05):
88
self.scenes_list = {}
99
self.selected = ""
1010
self.prev = ""

Engine/Symbol.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
from Engine.Color import Color
2+
3+
14
class Symbol:
25
"""Описывает символ в консоли"""
36
def __init__(self, char:str=" ", background_color:str="", text_color:str=""):
4-
self.text_color = text_color
5-
self.background_color = background_color
7+
self.text_color = text_color or Color.default
8+
self.background_color = background_color or Color.default
69
self.char = char

Engine/Window.py

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,4 +160,49 @@ def text(self, x:int, y:int, text:str="TEXT", background_color:str="", text_colo
160160
return
161161

162162
for i in range(len(text)):
163-
self.buffer[y][x + i] = Symbol(background_color=background_color, text_color=text_color, char=text[i])
163+
self.point(x + i, y, Symbol(background_color=background_color, text_color=text_color, char=text[i]))
164+
165+
def table(self, x, y, data, header):
166+
if not data:
167+
print("[ERROR][WINDOW][TABLE] Data empty")
168+
return
169+
170+
data = data.copy()
171+
header = header.copy()
172+
173+
for i, row in enumerate(data):
174+
for j, cell in enumerate(row):
175+
data[i][j] = str(cell)
176+
177+
max_widths = []
178+
for title in header:
179+
max_widths.append(len(title))
180+
181+
for i, row in enumerate(data):
182+
for j, cell in enumerate(row):
183+
max_widths[j] = max(max_widths[j], len(cell))
184+
185+
width = sum(max_widths) + len(max_widths) + 1
186+
187+
# Нормализация длины заголовка
188+
for i, title in enumerate(header):
189+
header[i] += " " * (max_widths[i] - len(title))
190+
191+
# Нормализация длины информации
192+
for i, row in enumerate(data):
193+
for j, cell in enumerate(row):
194+
data[i][j] += " " * (max_widths[j] - len(data[i][j]))
195+
196+
out_strings = []
197+
198+
out_strings.append("-" * width)
199+
out_strings.append("|" + "|".join(header) + "|")
200+
out_strings.append("-" * width)
201+
202+
for row in data:
203+
out_strings.append("|" + "|".join(row) + "|")
204+
205+
out_strings.append("-" * width)
206+
207+
for i, string in enumerate(out_strings):
208+
self.text(x, y + i, string)

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
- [FractalCE](https://github.com/Sinus44/FractalCE)
1212
- [Console-TicTacToe](https://github.com/Sinus44/Console-TicTacToe)
1313
- [EBMConsoleViewer](https://github.com/Sinus44/EBMConsoleViewer)
14-
- [1_Neural-Network](https://github.com/Sinus44/1_Neural-Network)
1514

1615

1716
# Тестировалось на:
@@ -321,6 +320,10 @@
321320
Описание:
322321
Текст
323322

323+
### table()
324+
325+
326+
324327
## Class Element
325328
Описание:
326329
[GUI] База для GUI элементов

0 commit comments

Comments
 (0)