UIElements 1.0.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.
- UIElements/button.py +67 -0
- UIElements/checkbox.py +51 -0
- UIElements/inputBox.py +117 -0
- UIElements/inputfield.py +84 -0
- UIElements/notification.py +47 -0
- UIElements/scroller.py +61 -0
- uielements-1.0.0.dist-info/METADATA +6 -0
- uielements-1.0.0.dist-info/RECORD +10 -0
- uielements-1.0.0.dist-info/WHEEL +5 -0
- uielements-1.0.0.dist-info/top_level.txt +1 -0
UIElements/button.py
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
|
|
3
|
+
from Decorators.functions.validateType import ValidateType
|
|
4
|
+
|
|
5
|
+
from PygameTools.Event.eventListener import EventListener #type: ignore
|
|
6
|
+
from PygameTools.Event.isEventObject import IsEventObject #type: ignore
|
|
7
|
+
|
|
8
|
+
@IsEventObject()
|
|
9
|
+
class Button:
|
|
10
|
+
|
|
11
|
+
def __init__(self, left: int, top: int, width: int, height: int, method: callable, label: str="", font: str=None, font_size: int=20, image: pygame.Surface=None):
|
|
12
|
+
|
|
13
|
+
self.rect = pygame.Rect(left, top, width, height)
|
|
14
|
+
self.border = pygame.Rect(left - 5, top - 5, width + 10, height + 10)
|
|
15
|
+
|
|
16
|
+
self.font = pygame.font.Font(font, font_size)
|
|
17
|
+
|
|
18
|
+
self.color = (150, 150, 150)
|
|
19
|
+
|
|
20
|
+
self.function = method
|
|
21
|
+
|
|
22
|
+
self.label = label
|
|
23
|
+
|
|
24
|
+
if image is not None:
|
|
25
|
+
self.image = pygame.transform.scale(image, self.rect.size)
|
|
26
|
+
|
|
27
|
+
else:
|
|
28
|
+
self.image = None
|
|
29
|
+
|
|
30
|
+
@ValidateType()
|
|
31
|
+
def set_image(self, image: pygame.Surface):
|
|
32
|
+
self.image = pygame.transform.scale(image, self.rect.size)
|
|
33
|
+
|
|
34
|
+
def set_pos(self, attrName: str, pos: tuple[int, int]):
|
|
35
|
+
if hasattr(self.border, attrName):
|
|
36
|
+
setattr(self.border, attrName, pos)
|
|
37
|
+
|
|
38
|
+
self.rect.center = self.border.center
|
|
39
|
+
|
|
40
|
+
def set_border(self, attrName: str, pos: tuple[int, int]):
|
|
41
|
+
if hasattr(self.border, attrName):
|
|
42
|
+
setattr(self.border, attrName, pos)
|
|
43
|
+
|
|
44
|
+
self.rect.center = self.border.center
|
|
45
|
+
|
|
46
|
+
def set_color(self, color: tuple[int, int, int]):
|
|
47
|
+
self.color = color
|
|
48
|
+
|
|
49
|
+
@EventListener(pygame.MOUSEBUTTONDOWN)
|
|
50
|
+
def click(self, event: pygame.event.Event):
|
|
51
|
+
|
|
52
|
+
if self.rect.collidepoint(event.pos):
|
|
53
|
+
return self.function()
|
|
54
|
+
|
|
55
|
+
def draw(self, screen: pygame.Surface, label_pos: tuple[int, int], draw_border: bool=True):
|
|
56
|
+
|
|
57
|
+
pygame.draw.rect(screen, self.color, self.rect)
|
|
58
|
+
if draw_border:
|
|
59
|
+
pygame.draw.rect(screen, (255, 255, 255), self.border, 5)
|
|
60
|
+
|
|
61
|
+
render = self.font.render(self.label, True, (0, 0, 0))
|
|
62
|
+
rect = render.get_rect(center=label_pos)
|
|
63
|
+
|
|
64
|
+
screen.blit(render, rect)
|
|
65
|
+
|
|
66
|
+
if self.image is not None:
|
|
67
|
+
screen.blit(self.image, self.rect)
|
UIElements/checkbox.py
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
|
|
3
|
+
from PygameTools.Event.eventListener import EventListener #type: ignore
|
|
4
|
+
from PygameTools.Event.isEventObject import IsEventObject #type: ignore
|
|
5
|
+
|
|
6
|
+
@IsEventObject()
|
|
7
|
+
class Checkox:
|
|
8
|
+
|
|
9
|
+
def __init__(self, left: int, top: int, width: int, height: int, label: str="", default_value: bool=False, font: str=None, font_size: int=20):
|
|
10
|
+
|
|
11
|
+
self.rect = pygame.Rect(left, top, width, height)
|
|
12
|
+
self.border = pygame.Rect(left - 5, top - 5, width + 10, height + 10)
|
|
13
|
+
|
|
14
|
+
self.value = default_value
|
|
15
|
+
self.color = (255, 255, 255)
|
|
16
|
+
self.border_color = (0, 0, 0)
|
|
17
|
+
|
|
18
|
+
self.label = label
|
|
19
|
+
|
|
20
|
+
self.font = pygame.Font(font, font_size)
|
|
21
|
+
|
|
22
|
+
def toggle(self):
|
|
23
|
+
self.value = not self.value
|
|
24
|
+
|
|
25
|
+
def get_value(self):
|
|
26
|
+
return self.value
|
|
27
|
+
|
|
28
|
+
@EventListener(pygame.MOUSEBUTTONDOWN)
|
|
29
|
+
def click(self, event: pygame.event.Event):
|
|
30
|
+
|
|
31
|
+
if event.type != pygame.MOUSEBUTTONDOWN:
|
|
32
|
+
return
|
|
33
|
+
|
|
34
|
+
if self.rect.collidepoint(event.pos):
|
|
35
|
+
self.toggle()
|
|
36
|
+
|
|
37
|
+
def draw(self, screen: pygame.Surface, label_pos: tuple[int, int], label_color: tuple[int, int, int]):
|
|
38
|
+
|
|
39
|
+
pygame.draw.rect(screen, self.color, self.rect)
|
|
40
|
+
pygame.draw.rect(screen, self.border_color, self.border, 5)
|
|
41
|
+
|
|
42
|
+
labelRender = self.font.render(self.label, True, label_color)
|
|
43
|
+
labelRect = labelRender.get_rect(center=label_pos)
|
|
44
|
+
|
|
45
|
+
screen.blit(labelRender, labelRect)
|
|
46
|
+
|
|
47
|
+
if self.value is True:
|
|
48
|
+
render = self.font.render("X", True, (0, 0, 0))
|
|
49
|
+
rect = render.get_rect(center=self.rect.center)
|
|
50
|
+
|
|
51
|
+
screen.blit(render, rect)
|
UIElements/inputBox.py
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
|
|
3
|
+
from Decorators.functions.validateType import ValidateType
|
|
4
|
+
|
|
5
|
+
from PygameTools.Event.eventListener import EventListener #type: ignore
|
|
6
|
+
from PygameTools.Event.isEventObject import IsEventObject #type: ignore
|
|
7
|
+
|
|
8
|
+
@IsEventObject()
|
|
9
|
+
class InputBox:
|
|
10
|
+
|
|
11
|
+
def __init__(self, left: int, top: int, width: int, height: int, font: str=None, font_size: int=20):
|
|
12
|
+
|
|
13
|
+
self.rect = pygame.Rect(left, top, width, height)
|
|
14
|
+
|
|
15
|
+
self.font = pygame.Font(font, font_size)
|
|
16
|
+
|
|
17
|
+
pygame.key.start_text_input()
|
|
18
|
+
|
|
19
|
+
self.selected = False
|
|
20
|
+
|
|
21
|
+
self.value = ""
|
|
22
|
+
|
|
23
|
+
self.color = (10, 10, 10)
|
|
24
|
+
self.selected_color = (255, 255, 0)
|
|
25
|
+
|
|
26
|
+
self.font_color = (0, 0, 0)
|
|
27
|
+
|
|
28
|
+
@ValidateType()
|
|
29
|
+
def set_pos(self, attrName: str, pos: tuple[int, int]):
|
|
30
|
+
|
|
31
|
+
if hasattr(self.rect, attrName):
|
|
32
|
+
setattr(self.rect, attrName, pos)
|
|
33
|
+
|
|
34
|
+
@ValidateType()
|
|
35
|
+
def set_color(self, color: tuple[int, int, int]):
|
|
36
|
+
self.color = color
|
|
37
|
+
|
|
38
|
+
def reset_value(self):
|
|
39
|
+
self.value = ""
|
|
40
|
+
|
|
41
|
+
@ValidateType()
|
|
42
|
+
def set_font_color(self, color: tuple[int, int, int]):
|
|
43
|
+
self.font_color = color
|
|
44
|
+
|
|
45
|
+
@EventListener([pygame.KEYDOWN, pygame.TEXTINPUT])
|
|
46
|
+
def write(self, event: pygame.event.Event):
|
|
47
|
+
|
|
48
|
+
if not self.selected:
|
|
49
|
+
return
|
|
50
|
+
|
|
51
|
+
if event.type == pygame.KEYDOWN:
|
|
52
|
+
|
|
53
|
+
match event.key:
|
|
54
|
+
|
|
55
|
+
case pygame.K_RETURN:
|
|
56
|
+
self.value += "\n"
|
|
57
|
+
|
|
58
|
+
case pygame.K_BACKSPACE:
|
|
59
|
+
self.value = self.value[:-1]
|
|
60
|
+
|
|
61
|
+
elif event.type == pygame.TEXTINPUT:
|
|
62
|
+
self.value += event.text
|
|
63
|
+
|
|
64
|
+
@EventListener(pygame.MOUSEBUTTONDOWN)
|
|
65
|
+
def select(self, event: pygame.event.Event):
|
|
66
|
+
|
|
67
|
+
if event.type != pygame.MOUSEBUTTONDOWN:
|
|
68
|
+
return
|
|
69
|
+
|
|
70
|
+
if self.rect.collidepoint(event.pos):
|
|
71
|
+
self.selected = True
|
|
72
|
+
|
|
73
|
+
else:
|
|
74
|
+
self.selected = False
|
|
75
|
+
|
|
76
|
+
def renderText(self, screen: pygame.Surface):
|
|
77
|
+
|
|
78
|
+
lines = self.value.split("\n")
|
|
79
|
+
|
|
80
|
+
start_x = self.rect.left + 10
|
|
81
|
+
start_y = self.rect.top + 10
|
|
82
|
+
|
|
83
|
+
max_width = self.rect.width - 20
|
|
84
|
+
|
|
85
|
+
for line in lines:
|
|
86
|
+
|
|
87
|
+
words = line.split(" ")
|
|
88
|
+
current_line = ""
|
|
89
|
+
|
|
90
|
+
for word in words:
|
|
91
|
+
|
|
92
|
+
test_line = f"{current_line} {word}".strip()
|
|
93
|
+
|
|
94
|
+
if self.font.size(test_line)[0] <= max_width:
|
|
95
|
+
current_line = test_line
|
|
96
|
+
|
|
97
|
+
else:
|
|
98
|
+
render = self.font.render(current_line, True, self.font_color)
|
|
99
|
+
rect = render.get_rect(topleft=(start_x, start_y))
|
|
100
|
+
|
|
101
|
+
start_y += rect.height + 10
|
|
102
|
+
screen.blit(render, rect)
|
|
103
|
+
|
|
104
|
+
current_line = word
|
|
105
|
+
|
|
106
|
+
if current_line:
|
|
107
|
+
render = self.font.render(current_line, True, self.font_color)
|
|
108
|
+
rect = render.get_rect(topleft=(start_x, start_y))
|
|
109
|
+
|
|
110
|
+
start_y += rect.height + 10
|
|
111
|
+
screen.blit(render, rect)
|
|
112
|
+
|
|
113
|
+
def draw(self, screen: pygame.Surface):
|
|
114
|
+
|
|
115
|
+
pygame.draw.rect(screen, self.color if not self.selected else self.selected_color, self.rect, 2)
|
|
116
|
+
|
|
117
|
+
self.renderText(screen)
|
UIElements/inputfield.py
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
import string
|
|
3
|
+
|
|
4
|
+
from PygameTools.Event.eventListener import EventListener #type: ignore
|
|
5
|
+
from PygameTools.Event.isEventObject import IsEventObject #type: ignore
|
|
6
|
+
|
|
7
|
+
@IsEventObject()
|
|
8
|
+
class InputField:
|
|
9
|
+
|
|
10
|
+
def __init__(self, left: int, top: int, width: int, height: int, label: str="", font: str=None, font_size: int=20):
|
|
11
|
+
|
|
12
|
+
self.rect = pygame.Rect(left, top, width, height)
|
|
13
|
+
self.border = pygame.Rect(left - 5, top - 5, width + 10, height + 10)
|
|
14
|
+
|
|
15
|
+
pygame.key.start_text_input()
|
|
16
|
+
|
|
17
|
+
self.label = label
|
|
18
|
+
|
|
19
|
+
self.font = pygame.Font(font, font_size)
|
|
20
|
+
|
|
21
|
+
self.selected_color = (255, 255, 0)
|
|
22
|
+
self.background = (0, 0, 0)
|
|
23
|
+
|
|
24
|
+
self.selected = False
|
|
25
|
+
|
|
26
|
+
self.value = ""
|
|
27
|
+
|
|
28
|
+
def reset_value(self):
|
|
29
|
+
self.value = ""
|
|
30
|
+
|
|
31
|
+
def set_background(self, color: tuple[int, int, int]):
|
|
32
|
+
self.background = color
|
|
33
|
+
|
|
34
|
+
def set_selected_color(self, color: tuple[int, int, int]):
|
|
35
|
+
self.selected_color = color
|
|
36
|
+
|
|
37
|
+
@EventListener(pygame.MOUSEBUTTONDOWN)
|
|
38
|
+
def select(self, event: pygame.event.Event):
|
|
39
|
+
|
|
40
|
+
if self.rect.collidepoint(event.pos):
|
|
41
|
+
self.selected = True
|
|
42
|
+
|
|
43
|
+
else:
|
|
44
|
+
self.selected = False
|
|
45
|
+
|
|
46
|
+
@EventListener([pygame.KEYDOWN, pygame.TEXTINPUT])
|
|
47
|
+
def write(self, event: pygame.event.Event):
|
|
48
|
+
|
|
49
|
+
if self.selected:
|
|
50
|
+
if event.type == pygame.KEYDOWN:
|
|
51
|
+
|
|
52
|
+
match event.key:
|
|
53
|
+
|
|
54
|
+
case pygame.K_BACKSPACE:
|
|
55
|
+
self.value = self.value[:-1]
|
|
56
|
+
|
|
57
|
+
case pygame.K_ESCAPE:
|
|
58
|
+
self.selected = False
|
|
59
|
+
|
|
60
|
+
elif event.type == pygame.TEXTINPUT:
|
|
61
|
+
|
|
62
|
+
self.value += event.text
|
|
63
|
+
|
|
64
|
+
def draw(self, screen: pygame.Surface, label_pos: tuple[int, int], censured: bool=False):
|
|
65
|
+
|
|
66
|
+
pygame.draw.rect(screen, self.background, self.rect)
|
|
67
|
+
pygame.draw.rect(screen, self.selected_color if self.selected else (255, 255,255), self.border, 5)
|
|
68
|
+
|
|
69
|
+
if censured:
|
|
70
|
+
value = "*" * len(self.value)
|
|
71
|
+
|
|
72
|
+
else:
|
|
73
|
+
value = self.value
|
|
74
|
+
|
|
75
|
+
nameRender = self.font.render(self.label, True, (0, 0, 0))
|
|
76
|
+
nameRect = nameRender.get_rect(center=label_pos)
|
|
77
|
+
|
|
78
|
+
render = self.font.render(value, True, (255, 255, 255))
|
|
79
|
+
rect = render.get_rect()
|
|
80
|
+
rect.left = self.rect.left + 5
|
|
81
|
+
rect.centery = self.rect.centery
|
|
82
|
+
|
|
83
|
+
screen.blit(render, rect)
|
|
84
|
+
screen.blit(nameRender, nameRect)
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
|
|
3
|
+
from .button import Button
|
|
4
|
+
|
|
5
|
+
class Notification:
|
|
6
|
+
|
|
7
|
+
def __init__(self, name: str, message: str, closeMethod: callable, left: int, top: int, width: int, height: int, font: str=None, font_size: int=20):
|
|
8
|
+
|
|
9
|
+
self.name = name
|
|
10
|
+
self.message = message
|
|
11
|
+
|
|
12
|
+
self.rect = pygame.Rect(left, top, width, height)
|
|
13
|
+
self.upRect = pygame.Rect(left, top, width, 35)
|
|
14
|
+
|
|
15
|
+
self.font = pygame.Font(font, font_size)
|
|
16
|
+
self.smallFont = pygame.Font(None, 25)
|
|
17
|
+
|
|
18
|
+
self.isOpen = True
|
|
19
|
+
|
|
20
|
+
self.closeButton = Button(0, 0, 50, 50, lambda: closeMethod(), "X", None, 30)
|
|
21
|
+
self.closeButton.set_border("topright", self.upRect.topright)
|
|
22
|
+
self.closeButton.set_color((255, 0, 0))
|
|
23
|
+
|
|
24
|
+
def set_pos(self, attrName: str, pos: tuple[int, int]):
|
|
25
|
+
if hasattr(self.rect, attrName):
|
|
26
|
+
setattr(self.rect, attrName, pos)
|
|
27
|
+
|
|
28
|
+
def draw(self, screen: pygame.Surface):
|
|
29
|
+
|
|
30
|
+
if self.isOpen:
|
|
31
|
+
pygame.draw.rect(screen, (255, 255, 255), self.rect)
|
|
32
|
+
pygame.draw.rect(screen, (0, 0, 255), self.upRect)
|
|
33
|
+
|
|
34
|
+
self.closeButton.draw(screen, self.closeButton.rect.center, False)
|
|
35
|
+
|
|
36
|
+
nameRender = self.smallFont.render(self.name, True, (255, 255, 255))
|
|
37
|
+
nameRect = nameRender.get_rect()
|
|
38
|
+
nameRect.left = self.upRect.left + 10
|
|
39
|
+
nameRect.centery = self.upRect.centery
|
|
40
|
+
|
|
41
|
+
messageRender = self.font.render(self.message, True, (0, 0, 0))
|
|
42
|
+
messageRect = messageRender.get_rect()
|
|
43
|
+
messageRect.left = self.rect.left + 10
|
|
44
|
+
messageRect.centery = self.rect.centery
|
|
45
|
+
|
|
46
|
+
screen.blit(nameRender, nameRect)
|
|
47
|
+
screen.blit(messageRender, messageRect)
|
UIElements/scroller.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
|
|
3
|
+
from .button import Button
|
|
4
|
+
|
|
5
|
+
class Scroller:
|
|
6
|
+
|
|
7
|
+
def __init__(self, left: int, top: int, width: int, height: int, content: list[str], font: str=None, font_size: int=20):
|
|
8
|
+
|
|
9
|
+
self.font = pygame.Font(font, font_size)
|
|
10
|
+
self.topleft = (left, top)
|
|
11
|
+
self.content = content
|
|
12
|
+
self.font_size = font_size
|
|
13
|
+
self.button = Button(0, 0, width, height, lambda: self.toggle(), "", font, font_size)
|
|
14
|
+
self.background_color = (150, 150, 150)
|
|
15
|
+
self.text_color = (0, 0, 0)
|
|
16
|
+
self.border_color = (255, 255, 255)
|
|
17
|
+
|
|
18
|
+
self.button.rect.topleft = self.topleft
|
|
19
|
+
self.button.border.topleft = self.topleft
|
|
20
|
+
|
|
21
|
+
self.open = False
|
|
22
|
+
self.value = self.content[0]
|
|
23
|
+
|
|
24
|
+
self.button.label = self.value
|
|
25
|
+
|
|
26
|
+
self.items = []
|
|
27
|
+
|
|
28
|
+
def toggle(self):
|
|
29
|
+
|
|
30
|
+
self.open = not self.open
|
|
31
|
+
|
|
32
|
+
def set_value(self, value: str):
|
|
33
|
+
self.value = value
|
|
34
|
+
self.button.label = self.value
|
|
35
|
+
self.open = False
|
|
36
|
+
|
|
37
|
+
def set_pos(self, attrName: str, pos: tuple[int, int]):
|
|
38
|
+
self.button.set_pos(attrName, pos)
|
|
39
|
+
|
|
40
|
+
def draw(self, surface: pygame.Surface):
|
|
41
|
+
|
|
42
|
+
self.button.background_color = self.background_color
|
|
43
|
+
self.button.text_color = self.text_color
|
|
44
|
+
self.button.border_color = self.border_color
|
|
45
|
+
self.button.draw(surface, self.button.rect.center)
|
|
46
|
+
|
|
47
|
+
start_y = self.button.rect.bottom
|
|
48
|
+
|
|
49
|
+
if self.open:
|
|
50
|
+
self.items.clear()
|
|
51
|
+
for i, item in enumerate(self.content):
|
|
52
|
+
item_button = Button(0, 0, self.button.rect.width, self.button.rect.height, lambda item=item: self.set_value(item), item, self.font, self.font_size)
|
|
53
|
+
item_button.background_color = self.background_color
|
|
54
|
+
item_button.text_color = self.text_color
|
|
55
|
+
item_button.border_color = self.border_color
|
|
56
|
+
item_button.rect.topleft = (self.button.rect.left, start_y + i * item_button.rect.height)
|
|
57
|
+
item_button.border.topleft = item_button.rect.topleft
|
|
58
|
+
self.items.append(item_button)
|
|
59
|
+
|
|
60
|
+
for button in self.items:
|
|
61
|
+
button.draw(surface, button.rect.center)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
UIElements/button.py,sha256=8hPSTD_zjVCgFnLMftfq3xfwGDKLjHh5zCc-0HNo17U,2200
|
|
2
|
+
UIElements/checkbox.py,sha256=N2d3K51FoFj7_FwpB2zbFX76YslRl1ZxDIAvdObKwL4,1659
|
|
3
|
+
UIElements/inputBox.py,sha256=u9o5pL5Ho866_yqxVuf89ItLGaieFIQoJNfS2yW8JR0,3266
|
|
4
|
+
UIElements/inputfield.py,sha256=VVG4toXYP4YCokesay-y9foJJZyCVzj9g2J2y0aLbGc,2521
|
|
5
|
+
UIElements/notification.py,sha256=vEDVaZwNNV1gkD0HFer1ftxp6C8BxGxnc4nGVmY_DYg,1756
|
|
6
|
+
UIElements/scroller.py,sha256=rtoV9qrs_zhvY7jZMNi49UZY09y2rARFAg2KvdsD8Tc,2226
|
|
7
|
+
uielements-1.0.0.dist-info/METADATA,sha256=DQJIRglr0fqPgLQZZUo7VT5SnuVGss3uPXYP6OJ61KE,197
|
|
8
|
+
uielements-1.0.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
9
|
+
uielements-1.0.0.dist-info/top_level.txt,sha256=d360kKFA-oOkzGCS4nnKeca00vKunvK7v9B6IQWSBMA,11
|
|
10
|
+
uielements-1.0.0.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
UIElements
|