EasyPythonUI 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,6 @@
1
+ Metadata-Version: 2.4
2
+ Name: EasyPythonUI
3
+ Version: 0.1.0
4
+ Summary: UI-библиотека для Python
5
+ Requires-Python: >=3.8
6
+ Requires-Dist: pygame-ce
@@ -0,0 +1,8 @@
1
+ novaui/__init__.py,sha256=X7NxM8hwIu0vLuR2kW-jsyxYznIwInYaw_mcxYKtC4E,1315
2
+ novaui/core.py,sha256=vcrmiBNel7z4nVT3F1CtmjUZgptuf86bBeh41k6r2Oc,1438
3
+ novaui/parser.py,sha256=tgSsTtWZiaBNLEQIimh2HSpCIBQt-3GUW24kHMXtVnI,1945
4
+ novaui/widgets.py,sha256=0bbOiGPJcI6IYfDjLzf4HDJ2tLhc9q6ofLvYoa9ScqY,2755
5
+ easypythonui-0.1.0.dist-info/METADATA,sha256=ytN4jy1YSMZVVwjL7JzhZvNGDybJfzlN8F2oZBb5CRU,157
6
+ easypythonui-0.1.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
7
+ easypythonui-0.1.0.dist-info/top_level.txt,sha256=Pxkeo1lDG86GAvpQxhixaiUn8KauwKFyCHWKbJOUvwk,7
8
+ easypythonui-0.1.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (84.2.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1 @@
1
+ novaui
novaui/__init__.py ADDED
@@ -0,0 +1,33 @@
1
+ from . import core
2
+ from .widgets import Button, Text
3
+
4
+ def app(title="NovaUI", size="500 x 500", color="white"):
5
+ return core.App(title, size, color)
6
+
7
+ def btn(label, size="150 x 50", action=None, pos="left u 10", color="blue", text_color="white"):
8
+ widget = Button(label, size, action, pos, color, text_color)
9
+ if core._active_app:
10
+ core._active_app.add(widget)
11
+ return widget
12
+
13
+ def text(content, size="16", pos="left u 10", color="black"):
14
+ widget = Text(content, size, pos, color)
15
+ if core._active_app:
16
+ core._active_app.add(widget)
17
+ return widget
18
+
19
+ def set(target, new_value=None):
20
+ """
21
+ Использование:
22
+ 1) text = novaui.set(text, "Новый текст")
23
+ 2) novaui.set("Новый текст") — обновит последний созданный текст
24
+ """
25
+ if new_value is None and isinstance(target, str):
26
+ # Если передали только строку, ищем последний текстовый виджет
27
+ if core._active_app:
28
+ for w in reversed(core._active_app.widgets):
29
+ if isinstance(w, Text):
30
+ return w.set_value(target)
31
+ elif hasattr(target, "set_value"):
32
+ return target.set_value(new_value)
33
+ return target
novaui/core.py ADDED
@@ -0,0 +1,41 @@
1
+ import pygame
2
+ from .parser import parse_size, parse_color
3
+
4
+ _active_app = None
5
+
6
+ class App:
7
+ def __init__(self, title="NovaUI", size="500 x 500", color="white"):
8
+ global _active_app
9
+ pygame.init()
10
+ self.width, self.height = parse_size(size)
11
+ self.screen = pygame.display.set_mode((self.width, self.height))
12
+ pygame.display.set_caption(title)
13
+ self.bg_color = parse_color(color)
14
+ self.clock = pygame.time.Clock()
15
+ self.widgets = []
16
+ self.last_bottom = 0 # Нижняя граница последнего добавленного элемента
17
+ _active_app = self
18
+
19
+ def add(self, widget):
20
+ widget.place(self.width, self.last_bottom)
21
+ self.last_bottom = widget.rect.bottom # Запоминаем низ для следующего элемента
22
+ self.widgets.append(widget)
23
+ return widget
24
+
25
+ def run(self):
26
+ running = True
27
+ while running:
28
+ for event in pygame.event.get():
29
+ if event.type == pygame.QUIT:
30
+ running = False
31
+ for widget in self.widgets:
32
+ widget.handle_event(event)
33
+
34
+ self.screen.fill(self.bg_color)
35
+ for widget in self.widgets:
36
+ widget.draw(self.screen)
37
+
38
+ pygame.display.flip()
39
+ self.clock.tick(60)
40
+
41
+ pygame.quit()
novaui/parser.py ADDED
@@ -0,0 +1,58 @@
1
+ COLORS = {
2
+ "black": (20, 20, 24),
3
+ "white": (245, 245, 250),
4
+ "red": (235, 64, 52),
5
+ "green": (46, 204, 113),
6
+ "blue": (88, 101, 242),
7
+ "gray": (128, 128, 135),
8
+ "yellow": (241, 196, 15),
9
+ }
10
+
11
+ def parse_size(size_str):
12
+ parts = size_str.lower().replace(" ", "").split("x")
13
+ return int(parts[0]), int(parts[1])
14
+
15
+ def parse_color(color_val):
16
+ if isinstance(color_val, tuple):
17
+ return color_val
18
+ return COLORS.get(color_val.lower(), (88, 101, 242))
19
+
20
+ def calculate_layout(pos_str, widget_w, win_w, prev_bottom):
21
+ """
22
+ Рассчитывает (x, y) с учётом:
23
+ - center, left, right (выравнивание по горизонтали)
24
+ - l <число> (сдвиг влево/вправо от базовой позиции)
25
+ - u <число> (отступ вниз от нижнего края ПРЕДЫДУЩЕГО элемента)
26
+ """
27
+ align = "left"
28
+ offset_x = 0
29
+ offset_y = 0
30
+
31
+ if pos_str:
32
+ tokens = pos_str.lower().split()
33
+ i = 0
34
+ while i < len(tokens):
35
+ tok = tokens[i]
36
+ if tok in ("center", "left", "right"):
37
+ align = tok
38
+ i += 1
39
+ elif tok == "l" and i + 1 < len(tokens):
40
+ offset_x += int(tokens[i + 1])
41
+ i += 2
42
+ elif tok == "u" and i + 1 < len(tokens):
43
+ offset_y += int(tokens[i + 1])
44
+ i += 2
45
+ else:
46
+ i += 1
47
+
48
+ # Базовый X в зависимости от выравнивания
49
+ if align == "center":
50
+ x = (win_w - widget_w) // 2 + offset_x
51
+ elif align == "right":
52
+ x = (win_w - widget_w) - offset_x
53
+ else: # "left"
54
+ x = offset_x
55
+
56
+ # Y считается от нижней границы предыдущего элемента
57
+ y = prev_bottom + offset_y
58
+ return x, y
novaui/widgets.py ADDED
@@ -0,0 +1,74 @@
1
+ import pygame
2
+ from .parser import parse_size, parse_color, calculate_layout
3
+
4
+ class Widget:
5
+ def __init__(self, pos_str=""):
6
+ self.pos_str = pos_str
7
+ self.rect = pygame.Rect(0, 0, 0, 0)
8
+ self.win_w = 500
9
+ self.prev_bottom = 0
10
+
11
+ def place(self, win_w, prev_bottom):
12
+ self.win_w = win_w
13
+ self.prev_bottom = prev_bottom
14
+ x, y = calculate_layout(self.pos_str, self.rect.width, win_w, prev_bottom)
15
+ self.rect.topleft = (x, y)
16
+
17
+ def handle_event(self, event):
18
+ pass
19
+
20
+ def draw(self, surface):
21
+ pass
22
+
23
+
24
+ class Text(Widget):
25
+ def __init__(self, content, size="16", pos="left u 10", color="black"):
26
+ super().__init__(pos)
27
+ self.font = pygame.font.SysFont("segoeui", int(size))
28
+ self.color = parse_color(color)
29
+ self._text = str(content)
30
+ self._render()
31
+
32
+ def _render(self):
33
+ self.surface = self.font.render(self._text, True, self.color)
34
+ self.rect.size = self.surface.get_size()
35
+ # Пересчитываем X, если текст выровнен по центру или правому краю
36
+ x, y = calculate_layout(self.pos_str, self.rect.width, self.win_w, self.prev_bottom)
37
+ self.rect.topleft = (x, y)
38
+
39
+ def set_value(self, new_text):
40
+ self._text = str(new_text)
41
+ self._render()
42
+ return self
43
+
44
+ def draw(self, surface):
45
+ surface.blit(self.surface, self.rect.topleft)
46
+
47
+
48
+ class Button(Widget):
49
+ def __init__(self, label, size="150 x 50", action=None, pos="left u 10", color="blue", text_color="white"):
50
+ super().__init__(pos)
51
+ w, h = parse_size(size)
52
+ self.rect.size = (w, h)
53
+ self.label = str(label)
54
+ self.action = action
55
+ self.base_color = parse_color(color)
56
+ self.hover_color = tuple(min(255, c + 25) for c in self.base_color)
57
+ self.text_color = parse_color(text_color)
58
+ self.font = pygame.font.SysFont("segoeui", 18, bold=True)
59
+ self.is_hovered = False
60
+
61
+ def handle_event(self, event):
62
+ if event.type == pygame.MOUSEMOTION:
63
+ self.is_hovered = self.rect.collidepoint(event.pos)
64
+ elif event.type == pygame.MOUSEBUTTONDOWN and event.button == 1:
65
+ if self.is_hovered and self.action:
66
+ self.action()
67
+
68
+ def draw(self, surface):
69
+ current_color = self.hover_color if self.is_hovered else self.base_color
70
+ pygame.draw.rect(surface, current_color, self.rect, border_radius=10)
71
+
72
+ text_surf = self.font.render(self.label, True, self.text_color)
73
+ text_rect = text_surf.get_rect(center=self.rect.center)
74
+ surface.blit(text_surf, text_rect)