pygame-widget-kit 0.0.2__tar.gz → 0.0.3__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.
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/PKG-INFO +11 -3
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/README.md +10 -2
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/pyproject.toml +1 -1
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/main.py +14 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/Button.py +64 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/Select.py +5 -2
- pygame_widget_kit-0.0.3/src/pygame_widget_kit/Slider.py +164 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/UIComponent.py +5 -2
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/UIManager.py +1 -1
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/Widget.py +1 -1
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/__init__.py +1 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/PKG-INFO +11 -3
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/SOURCES.txt +1 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/LICENSE +0 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/setup.cfg +0 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/Radio.py +0 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/Text.py +0 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/TextInput.py +0 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/dependency_links.txt +0 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/requires.txt +0 -0
- {pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pygame-widget-kit
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: A GUI framework built on Pygame. Designed as a retained-mode UI system with a component tree, extensible widgets, and focus management.
|
|
5
5
|
Author-email: Sinan Orgu <sinanorguuu@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -33,9 +33,9 @@ PyPI: https://pypi.org/project/pygame-widget-kit/
|
|
|
33
33
|
- Retained-mode component tree with nested children
|
|
34
34
|
- Event routing with hover, focus, and active state handling
|
|
35
35
|
- Modal/dropdown support via `UIManager`
|
|
36
|
-
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`
|
|
36
|
+
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`
|
|
37
37
|
- Text input filtering modes (text, number, hex, binary, octal)
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
|
|
40
40
|
## Installation
|
|
41
41
|
|
|
@@ -135,6 +135,14 @@ def main():
|
|
|
135
135
|
root.add_child(radio_value)
|
|
136
136
|
|
|
137
137
|
radio_last_value = radio.get_value()
|
|
138
|
+
slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
|
|
139
|
+
slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
|
|
140
|
+
slider.change_bind(update_slider_label,slider,slider_value)
|
|
141
|
+
|
|
142
|
+
root.add_child(slider)
|
|
143
|
+
root.add_child(slider_value)
|
|
144
|
+
|
|
145
|
+
|
|
138
146
|
|
|
139
147
|
running = True
|
|
140
148
|
while running:
|
|
@@ -11,9 +11,9 @@ PyPI: https://pypi.org/project/pygame-widget-kit/
|
|
|
11
11
|
- Retained-mode component tree with nested children
|
|
12
12
|
- Event routing with hover, focus, and active state handling
|
|
13
13
|
- Modal/dropdown support via `UIManager`
|
|
14
|
-
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`
|
|
14
|
+
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`
|
|
15
15
|
- Text input filtering modes (text, number, hex, binary, octal)
|
|
16
|
-
|
|
16
|
+
|
|
17
17
|
|
|
18
18
|
## Installation
|
|
19
19
|
|
|
@@ -113,6 +113,14 @@ def main():
|
|
|
113
113
|
root.add_child(radio_value)
|
|
114
114
|
|
|
115
115
|
radio_last_value = radio.get_value()
|
|
116
|
+
slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
|
|
117
|
+
slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
|
|
118
|
+
slider.change_bind(update_slider_label,slider,slider_value)
|
|
119
|
+
|
|
120
|
+
root.add_child(slider)
|
|
121
|
+
root.add_child(slider_value)
|
|
122
|
+
|
|
123
|
+
|
|
116
124
|
|
|
117
125
|
running = True
|
|
118
126
|
while running:
|
|
@@ -13,6 +13,10 @@ def update_label_from_input(input_box: TextInput, label: Text):
|
|
|
13
13
|
def update_select_label(select: Select, label: Text):
|
|
14
14
|
label.set_text(f"Selected: {select.selected_value}")
|
|
15
15
|
|
|
16
|
+
def update_slider_label(slider:Slider,label:Text):
|
|
17
|
+
label.set_text(f"Slider Value: {round(slider.value,2)}")
|
|
18
|
+
|
|
19
|
+
|
|
16
20
|
|
|
17
21
|
def main():
|
|
18
22
|
pygame.init()
|
|
@@ -85,6 +89,16 @@ def main():
|
|
|
85
89
|
|
|
86
90
|
radio_last_value = radio.get_value()
|
|
87
91
|
|
|
92
|
+
slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
|
|
93
|
+
slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
|
|
94
|
+
slider.change_bind(update_slider_label,slider,slider_value)
|
|
95
|
+
|
|
96
|
+
root.add_child(slider)
|
|
97
|
+
root.add_child(slider_value)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
88
102
|
running = True
|
|
89
103
|
while running:
|
|
90
104
|
clock.tick(60)
|
|
@@ -2,6 +2,34 @@ import pygame
|
|
|
2
2
|
from .Text import *
|
|
3
3
|
from .UIComponent import *
|
|
4
4
|
from functools import partial
|
|
5
|
+
import tkinter as tk
|
|
6
|
+
from tkinter import filedialog
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
import multiprocessing
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def file_choser_process(queue):
|
|
13
|
+
try:
|
|
14
|
+
root = tk.Tk()
|
|
15
|
+
root.withdraw()
|
|
16
|
+
|
|
17
|
+
root.attributes('-topmost', True)
|
|
18
|
+
|
|
19
|
+
root.lift()
|
|
20
|
+
root.focus_force()
|
|
21
|
+
|
|
22
|
+
dosya_yolu = filedialog.askopenfilename(
|
|
23
|
+
title="Chose File",
|
|
24
|
+
filetypes=[("Tüm Dosyalar", "*.*")]
|
|
25
|
+
)
|
|
26
|
+
|
|
27
|
+
queue.put(dosya_yolu)
|
|
28
|
+
|
|
29
|
+
root.destroy()
|
|
30
|
+
except Exception as e:
|
|
31
|
+
queue.put(None)
|
|
32
|
+
|
|
5
33
|
|
|
6
34
|
|
|
7
35
|
class Button(UIComponent):
|
|
@@ -63,4 +91,40 @@ class Button(UIComponent):
|
|
|
63
91
|
self.click_function()
|
|
64
92
|
else:
|
|
65
93
|
print("Button clicked")
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
class ChooseFileButton(Button):
|
|
99
|
+
def __init__(self, text_str="Button", pos=(0, 0), size=(200, 40), style=None, z_index=0, color=(175, 175, 175), border_color=(100, 100, 100), hover_color=(150, 150, 150), text_color=(0, 0, 0), padding=(20, 10)):
|
|
100
|
+
super().__init__(text_str, pos, size, style, z_index, color, border_color, hover_color, text_color, padding)
|
|
101
|
+
|
|
102
|
+
self.chosen_file_path = None
|
|
103
|
+
|
|
104
|
+
def on_click(self, event):
|
|
105
|
+
print("Dosya seçici ayrı işlemde başlatılıyor...")
|
|
106
|
+
|
|
107
|
+
q = multiprocessing.Queue()
|
|
108
|
+
|
|
109
|
+
p = multiprocessing.Process(target=file_choser_process, args=(q,))
|
|
110
|
+
|
|
111
|
+
p.start()
|
|
112
|
+
p.join()
|
|
113
|
+
if not q.empty():
|
|
114
|
+
sonuc = q.get()
|
|
115
|
+
if sonuc:
|
|
116
|
+
secilen_dosya = sonuc
|
|
117
|
+
print(f"Gelen dosya: {secilen_dosya}")
|
|
118
|
+
self.chosen_file_path = secilen_dosya
|
|
119
|
+
self.text.set_text(secilen_dosya)
|
|
120
|
+
if self.click_function is not None:
|
|
121
|
+
self.click_function()
|
|
122
|
+
else:
|
|
123
|
+
print("islem iptal")
|
|
124
|
+
else:
|
|
125
|
+
print("İşlem iptal edildi veya hata oluştu.")
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
|
|
66
130
|
|
|
@@ -5,6 +5,7 @@ from .Button import *
|
|
|
5
5
|
from functools import partial
|
|
6
6
|
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
class SelectOption(Button):
|
|
9
10
|
def __init__(self,value:str, rect, parent_select:"Select", color=(200,200,200),border_color = (127,127,127)):
|
|
10
11
|
super().__init__(text_str=value,pos=(rect[0],rect[1]),size=(rect[2],rect[3]), color=color,padding=(5,5),text_color=(0,0,0),border_color=border_color)
|
|
@@ -116,10 +117,12 @@ class Select(UIComponent):
|
|
|
116
117
|
self.on_option_change()
|
|
117
118
|
|
|
118
119
|
def on_click(self, event):
|
|
119
|
-
self.
|
|
120
|
+
if self.enabled:
|
|
121
|
+
self.toggle()
|
|
120
122
|
|
|
121
123
|
def draw(self, surface: pygame.Surface):
|
|
122
|
-
|
|
124
|
+
if self.visible == False:
|
|
125
|
+
return
|
|
123
126
|
super().draw(surface)
|
|
124
127
|
|
|
125
128
|
cx = self.absolute_rect[0] + self.absolute_rect[2] - 15
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
from .UIComponent import *
|
|
3
|
+
from functools import partial
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class Slider(UIComponent):
|
|
7
|
+
def __init__(
|
|
8
|
+
self,
|
|
9
|
+
pos=(0, 0),
|
|
10
|
+
size=(200, 20),
|
|
11
|
+
min_value=0,
|
|
12
|
+
max_value=100,
|
|
13
|
+
value=None,
|
|
14
|
+
style=None,
|
|
15
|
+
z_index=0,
|
|
16
|
+
color=(200, 200, 200),
|
|
17
|
+
border_color=(120, 120, 120),
|
|
18
|
+
hover_color=(220, 220, 220),
|
|
19
|
+
handle_color=(80, 80, 80),
|
|
20
|
+
handle_hover_color=None,
|
|
21
|
+
handle_border_color=None,
|
|
22
|
+
):
|
|
23
|
+
self.min_value = min_value
|
|
24
|
+
self.max_value = max_value
|
|
25
|
+
self.value = min_value if value is None else value
|
|
26
|
+
|
|
27
|
+
self.size = size
|
|
28
|
+
|
|
29
|
+
self.handle_color = handle_color
|
|
30
|
+
self.handle_hover_color = (
|
|
31
|
+
handle_hover_color
|
|
32
|
+
if handle_hover_color is not None
|
|
33
|
+
else tuple(min(c + 30, 255) for c in handle_color)
|
|
34
|
+
)
|
|
35
|
+
self.handle_active_color = tuple(max(c - 40, 0) for c in handle_color)
|
|
36
|
+
self.handle_border_color = handle_border_color
|
|
37
|
+
|
|
38
|
+
self.dragging = False
|
|
39
|
+
self.drag_offset = 0
|
|
40
|
+
self.change_function = None
|
|
41
|
+
|
|
42
|
+
rect = (pos[0], pos[1], self.size[0], self.size[1])
|
|
43
|
+
super().__init__(rect, style, z_index, color, border_color, hover_color)
|
|
44
|
+
|
|
45
|
+
self.handle_width = min(self.rect[2], self.rect[3])
|
|
46
|
+
self.handle_height = self.rect[3]
|
|
47
|
+
|
|
48
|
+
self.set_value(self.value)
|
|
49
|
+
|
|
50
|
+
def change_bind(self, func, *args):
|
|
51
|
+
self.change_function = partial(func, *args)
|
|
52
|
+
|
|
53
|
+
def on_change(self):
|
|
54
|
+
if self.change_function is not None:
|
|
55
|
+
self.change_function()
|
|
56
|
+
|
|
57
|
+
def set_value(self, value):
|
|
58
|
+
if self.max_value == self.min_value:
|
|
59
|
+
if self.value != self.min_value:
|
|
60
|
+
self.value = self.min_value
|
|
61
|
+
self.on_change()
|
|
62
|
+
return
|
|
63
|
+
|
|
64
|
+
old_value = self.value
|
|
65
|
+
if value < self.min_value:
|
|
66
|
+
value = self.min_value
|
|
67
|
+
elif value > self.max_value:
|
|
68
|
+
value = self.max_value
|
|
69
|
+
|
|
70
|
+
self.value = value
|
|
71
|
+
if self.value != old_value:
|
|
72
|
+
self.on_change()
|
|
73
|
+
|
|
74
|
+
def get_value(self):
|
|
75
|
+
return self.value
|
|
76
|
+
|
|
77
|
+
def _get_track_range(self):
|
|
78
|
+
x = self.absolute_rect[0]
|
|
79
|
+
w = self.rect[2]
|
|
80
|
+
handle_w = self.handle_width
|
|
81
|
+
min_center = x + handle_w / 2
|
|
82
|
+
max_center = x + w - handle_w / 2
|
|
83
|
+
return min_center, max_center
|
|
84
|
+
|
|
85
|
+
def _value_to_center(self):
|
|
86
|
+
min_center, max_center = self._get_track_range()
|
|
87
|
+
if max_center <= min_center or self.max_value == self.min_value:
|
|
88
|
+
return min_center
|
|
89
|
+
|
|
90
|
+
ratio = (self.value - self.min_value) / (self.max_value - self.min_value)
|
|
91
|
+
ratio = max(0, min(1, ratio))
|
|
92
|
+
return min_center + ratio * (max_center - min_center)
|
|
93
|
+
|
|
94
|
+
def _get_handle_rect(self):
|
|
95
|
+
center_x = self._value_to_center()
|
|
96
|
+
handle_x = int(center_x - self.handle_width / 2)
|
|
97
|
+
handle_y = int(self.absolute_rect[1] + (self.rect[3] - self.handle_height) / 2)
|
|
98
|
+
return pygame.Rect(handle_x, handle_y, self.handle_width, self.handle_height)
|
|
99
|
+
|
|
100
|
+
def _set_value_from_mouse(self, mouse_x, use_offset):
|
|
101
|
+
min_center, max_center = self._get_track_range()
|
|
102
|
+
if max_center <= min_center or self.max_value == self.min_value:
|
|
103
|
+
self.set_value(self.min_value)
|
|
104
|
+
return
|
|
105
|
+
|
|
106
|
+
center_x = mouse_x - (self.drag_offset if use_offset else 0)
|
|
107
|
+
if center_x < min_center:
|
|
108
|
+
center_x = min_center
|
|
109
|
+
elif center_x > max_center:
|
|
110
|
+
center_x = max_center
|
|
111
|
+
|
|
112
|
+
ratio = (center_x - min_center) / (max_center - min_center)
|
|
113
|
+
self.set_value(self.min_value + ratio * (self.max_value - self.min_value))
|
|
114
|
+
|
|
115
|
+
def _begin_drag(self):
|
|
116
|
+
mouse_x, mouse_y = pygame.mouse.get_pos()
|
|
117
|
+
handle_rect = self._get_handle_rect()
|
|
118
|
+
|
|
119
|
+
if handle_rect.collidepoint(mouse_x, mouse_y):
|
|
120
|
+
self.drag_offset = mouse_x - handle_rect.centerx
|
|
121
|
+
else:
|
|
122
|
+
self.drag_offset = 0
|
|
123
|
+
self._set_value_from_mouse(mouse_x, use_offset=False)
|
|
124
|
+
|
|
125
|
+
self.dragging = True
|
|
126
|
+
|
|
127
|
+
def on_click(self, event):
|
|
128
|
+
if not self.visible or not self.enabled:
|
|
129
|
+
return
|
|
130
|
+
|
|
131
|
+
if not self.dragging:
|
|
132
|
+
self._set_value_from_mouse(event.pos[0], use_offset=False)
|
|
133
|
+
|
|
134
|
+
self.dragging = False
|
|
135
|
+
self.drag_offset = 0
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
def draw(self, surface: pygame.Surface):
|
|
139
|
+
if not self.visible:
|
|
140
|
+
return
|
|
141
|
+
|
|
142
|
+
if self.active and self.enabled:
|
|
143
|
+
if not self.dragging:
|
|
144
|
+
self._begin_drag()
|
|
145
|
+
mouse_x, _ = pygame.mouse.get_pos()
|
|
146
|
+
self._set_value_from_mouse(mouse_x, use_offset=True)
|
|
147
|
+
else:
|
|
148
|
+
self.dragging = False
|
|
149
|
+
self.drag_offset = 0
|
|
150
|
+
|
|
151
|
+
super().draw(surface)
|
|
152
|
+
|
|
153
|
+
handle_color = self.handle_color
|
|
154
|
+
if not self.enabled:
|
|
155
|
+
handle_color = tuple(c // 2 for c in handle_color)
|
|
156
|
+
elif self.active:
|
|
157
|
+
handle_color = self.handle_active_color
|
|
158
|
+
elif self.hovered:
|
|
159
|
+
handle_color = self.handle_hover_color
|
|
160
|
+
|
|
161
|
+
handle_rect = self._get_handle_rect()
|
|
162
|
+
pygame.draw.rect(surface, handle_color, handle_rect, 0)
|
|
163
|
+
if self.handle_border_color:
|
|
164
|
+
pygame.draw.rect(surface, self.handle_border_color, handle_rect, 2)
|
|
@@ -115,12 +115,15 @@ class UIComponent:
|
|
|
115
115
|
pygame.draw.rect(surface, fill_color, self.absolute_rect, 0)
|
|
116
116
|
|
|
117
117
|
if self.show_border:
|
|
118
|
+
|
|
118
119
|
border_color = self.color
|
|
119
120
|
|
|
120
121
|
|
|
121
122
|
if self.focused:
|
|
122
|
-
border_color =self.border_color
|
|
123
|
-
|
|
123
|
+
border_color = self.border_color
|
|
124
|
+
|
|
125
|
+
if border_color:
|
|
126
|
+
pygame.draw.rect(surface, border_color, self.absolute_rect, 2)
|
|
124
127
|
|
|
125
128
|
self.draw_child(surface)
|
|
126
129
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pygame-widget-kit
|
|
3
|
-
Version: 0.0.
|
|
3
|
+
Version: 0.0.3
|
|
4
4
|
Summary: A GUI framework built on Pygame. Designed as a retained-mode UI system with a component tree, extensible widgets, and focus management.
|
|
5
5
|
Author-email: Sinan Orgu <sinanorguuu@gmail.com>
|
|
6
6
|
License: MIT
|
|
@@ -33,9 +33,9 @@ PyPI: https://pypi.org/project/pygame-widget-kit/
|
|
|
33
33
|
- Retained-mode component tree with nested children
|
|
34
34
|
- Event routing with hover, focus, and active state handling
|
|
35
35
|
- Modal/dropdown support via `UIManager`
|
|
36
|
-
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`
|
|
36
|
+
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`
|
|
37
37
|
- Text input filtering modes (text, number, hex, binary, octal)
|
|
38
|
-
|
|
38
|
+
|
|
39
39
|
|
|
40
40
|
## Installation
|
|
41
41
|
|
|
@@ -135,6 +135,14 @@ def main():
|
|
|
135
135
|
root.add_child(radio_value)
|
|
136
136
|
|
|
137
137
|
radio_last_value = radio.get_value()
|
|
138
|
+
slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
|
|
139
|
+
slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
|
|
140
|
+
slider.change_bind(update_slider_label,slider,slider_value)
|
|
141
|
+
|
|
142
|
+
root.add_child(slider)
|
|
143
|
+
root.add_child(slider_value)
|
|
144
|
+
|
|
145
|
+
|
|
138
146
|
|
|
139
147
|
running = True
|
|
140
148
|
while running:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/requires.txt
RENAMED
|
File without changes
|
{pygame_widget_kit-0.0.2 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/top_level.txt
RENAMED
|
File without changes
|