EasyPythonUI 0.1.0__tar.gz
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.
- easypythonui-0.1.0/EasyPythonUI.egg-info/PKG-INFO +6 -0
- easypythonui-0.1.0/EasyPythonUI.egg-info/SOURCES.txt +10 -0
- easypythonui-0.1.0/EasyPythonUI.egg-info/dependency_links.txt +1 -0
- easypythonui-0.1.0/EasyPythonUI.egg-info/requires.txt +1 -0
- easypythonui-0.1.0/EasyPythonUI.egg-info/top_level.txt +1 -0
- easypythonui-0.1.0/PKG-INFO +6 -0
- easypythonui-0.1.0/novaui/__init__.py +33 -0
- easypythonui-0.1.0/novaui/core.py +41 -0
- easypythonui-0.1.0/novaui/parser.py +58 -0
- easypythonui-0.1.0/novaui/widgets.py +74 -0
- easypythonui-0.1.0/pyproject.toml +12 -0
- easypythonui-0.1.0/setup.cfg +4 -0
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
pyproject.toml
|
|
2
|
+
EasyPythonUI.egg-info/PKG-INFO
|
|
3
|
+
EasyPythonUI.egg-info/SOURCES.txt
|
|
4
|
+
EasyPythonUI.egg-info/dependency_links.txt
|
|
5
|
+
EasyPythonUI.egg-info/requires.txt
|
|
6
|
+
EasyPythonUI.egg-info/top_level.txt
|
|
7
|
+
novaui/__init__.py
|
|
8
|
+
novaui/core.py
|
|
9
|
+
novaui/parser.py
|
|
10
|
+
novaui/widgets.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
pygame-ce
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
novaui
|
|
@@ -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
|
|
@@ -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()
|
|
@@ -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
|
|
@@ -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)
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=61.0"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "EasyPythonUI"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "UI-библиотека для Python"
|
|
9
|
+
requires-python = ">=3.8"
|
|
10
|
+
dependencies = [
|
|
11
|
+
"pygame-ce"
|
|
12
|
+
]
|