pygame-widget-kit 0.0.1__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.3/PKG-INFO +202 -0
- pygame_widget_kit-0.0.3/README.md +180 -0
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/pyproject.toml +1 -1
- pygame_widget_kit-0.0.3/src/main.py +123 -0
- pygame_widget_kit-0.0.3/src/pygame_widget_kit/Button.py +130 -0
- pygame_widget_kit-0.0.3/src/pygame_widget_kit/Radio.py +125 -0
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/Select.py +49 -41
- pygame_widget_kit-0.0.3/src/pygame_widget_kit/Slider.py +164 -0
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/Text.py +4 -3
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/TextInput.py +72 -28
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/UIComponent.py +10 -7
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/UIManager.py +1 -1
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/Widget.py +3 -1
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit/__init__.py +3 -1
- pygame_widget_kit-0.0.3/src/pygame_widget_kit.egg-info/PKG-INFO +202 -0
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/SOURCES.txt +3 -0
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/top_level.txt +1 -0
- pygame_widget_kit-0.0.1/PKG-INFO +0 -24
- pygame_widget_kit-0.0.1/README.md +0 -2
- pygame_widget_kit-0.0.1/src/pygame_widget_kit/Button.py +0 -48
- pygame_widget_kit-0.0.1/src/pygame_widget_kit.egg-info/PKG-INFO +0 -24
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/LICENSE +0 -0
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/setup.cfg +0 -0
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/dependency_links.txt +0 -0
- {pygame_widget_kit-0.0.1 → pygame_widget_kit-0.0.3}/src/pygame_widget_kit.egg-info/requires.txt +0 -0
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pygame-widget-kit
|
|
3
|
+
Version: 0.0.3
|
|
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
|
+
Author-email: Sinan Orgu <sinanorguuu@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/sinanorgu/pygame-widget-kit
|
|
8
|
+
Project-URL: Repository, https://github.com/sinanorgu/pygame-widget-kit
|
|
9
|
+
Project-URL: Issues, https://github.com/sinanorgu/pygame-widget-kit/issues
|
|
10
|
+
Keywords: pygame,ui,gui,toolkit,widgets,interface,game-development,inputbox,buttons
|
|
11
|
+
Classifier: Development Status :: 3 - Alpha
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: pygame
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
16
|
+
Classifier: Operating System :: OS Independent
|
|
17
|
+
Requires-Python: >=3.7
|
|
18
|
+
Description-Content-Type: text/markdown
|
|
19
|
+
License-File: LICENSE
|
|
20
|
+
Requires-Dist: pygame>=2.0.0
|
|
21
|
+
Dynamic: license-file
|
|
22
|
+
|
|
23
|
+
# pygame-widget-kit
|
|
24
|
+
|
|
25
|
+
[](https://pypi.org/project/pygame-widget-kit/)
|
|
26
|
+
|
|
27
|
+
A GUI framework built on Pygame. pygame-widget-kit is a retained-mode UI system with a component tree, event routing, focus and modal management, and extensible widgets such as Select/Dropdown and TextInput with mouse-based text selection and clipboard support.
|
|
28
|
+
|
|
29
|
+
PyPI: https://pypi.org/project/pygame-widget-kit/
|
|
30
|
+
|
|
31
|
+
## Features
|
|
32
|
+
|
|
33
|
+
- Retained-mode component tree with nested children
|
|
34
|
+
- Event routing with hover, focus, and active state handling
|
|
35
|
+
- Modal/dropdown support via `UIManager`
|
|
36
|
+
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`
|
|
37
|
+
- Text input filtering modes (text, number, hex, binary, octal)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
## Installation
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install pygame-widget-kit
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Pygame is listed as a dependency (pygame >= 2.0.0). Make sure you call `pygame.init()` before creating widgets.
|
|
47
|
+
|
|
48
|
+
## Usage
|
|
49
|
+
|
|
50
|
+
```python
|
|
51
|
+
|
|
52
|
+
import pygame
|
|
53
|
+
from pygame_widget_kit import *
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
SCREEN_WIDTH = 900
|
|
57
|
+
SCREEN_HEIGHT = 720
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def update_label_from_input(input_box: TextInput, label: Text):
|
|
61
|
+
label.set_text(f"Label: {input_box.text_value}")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def update_select_label(select: Select, label: Text):
|
|
65
|
+
label.set_text(f"Selected: {select.selected_value}")
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def main():
|
|
69
|
+
pygame.init()
|
|
70
|
+
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
71
|
+
clock = pygame.time.Clock()
|
|
72
|
+
|
|
73
|
+
root = Widget((0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), border_color=None)
|
|
74
|
+
ui = UIManager(root)
|
|
75
|
+
|
|
76
|
+
title = Text("pygame-widget-kit demo", pos=(24, 20), text_color=(0, 0, 0))
|
|
77
|
+
root.add_child(title)
|
|
78
|
+
|
|
79
|
+
input_box = TextInput(rect=(24, 70, 220, 36), initial_text="")
|
|
80
|
+
update_button = Button("Update label", pos=(256, 70), size=(160, 36))
|
|
81
|
+
value_label = Text("Label: (empty)", pos=(432, 76), text_color=(0, 0, 0))
|
|
82
|
+
update_button.click_bind(update_label_from_input, input_box, value_label)
|
|
83
|
+
|
|
84
|
+
root.add_child(input_box)
|
|
85
|
+
root.add_child(update_button)
|
|
86
|
+
root.add_child(value_label)
|
|
87
|
+
|
|
88
|
+
input_types_title = Text("input types:", pos=(24, 150), text_color=(0, 0, 0))
|
|
89
|
+
root.add_child(input_types_title)
|
|
90
|
+
|
|
91
|
+
input_rows = [
|
|
92
|
+
("Allow all:", ALLOW_ALL_CHARS),
|
|
93
|
+
("Text only:", TEXT_ONLY),
|
|
94
|
+
("Number only:", NUMBER_ONLY),
|
|
95
|
+
("Hex only:", HEX_ONLY),
|
|
96
|
+
("Binary only:", BINARY_ONLY),
|
|
97
|
+
]
|
|
98
|
+
|
|
99
|
+
input_label_x = 24
|
|
100
|
+
input_box_x = 200
|
|
101
|
+
input_row_y = 190
|
|
102
|
+
input_row_gap = 44
|
|
103
|
+
|
|
104
|
+
for index, (label_text, mode) in enumerate(input_rows):
|
|
105
|
+
row_y = input_row_y + index * input_row_gap
|
|
106
|
+
row_label = Text(label_text, pos=(input_label_x, row_y + 6), text_color=(0, 0, 0))
|
|
107
|
+
row_input = TextInput(rect=(input_box_x, row_y, 240, 34), allowed_char_mode=mode)
|
|
108
|
+
root.add_child(row_label)
|
|
109
|
+
root.add_child(row_input)
|
|
110
|
+
|
|
111
|
+
select_label = Text("Select:", pos=(24, 430), text_color=(0, 0, 0))
|
|
112
|
+
select = Select(
|
|
113
|
+
rect=(100, 424, 160, 32),
|
|
114
|
+
options=["Easy", "Hard", "Expert"],
|
|
115
|
+
default_index=0,
|
|
116
|
+
z_index=2
|
|
117
|
+
)
|
|
118
|
+
select_value = Text("Selected: Easy", pos=(280, 430), text_color=(0, 0, 0))
|
|
119
|
+
select.bind_on_option_chance(update_select_label, select, select_value)
|
|
120
|
+
|
|
121
|
+
root.add_child(select_label)
|
|
122
|
+
root.add_child(select)
|
|
123
|
+
root.add_child(select_value)
|
|
124
|
+
|
|
125
|
+
radio_label = Text("Radio:", pos=(24, 490), text_color=(0, 0, 0))
|
|
126
|
+
radio = Radio(
|
|
127
|
+
(100, 486, 150, 28),
|
|
128
|
+
options=["OPTION A","OPTION B","OPTION C"],
|
|
129
|
+
default_index=0,
|
|
130
|
+
)
|
|
131
|
+
radio_value = Text("Radio: A", pos=(280, 490), text_color=(0, 0, 0))
|
|
132
|
+
|
|
133
|
+
root.add_child(radio_label)
|
|
134
|
+
root.add_child(radio)
|
|
135
|
+
root.add_child(radio_value)
|
|
136
|
+
|
|
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
|
+
|
|
146
|
+
|
|
147
|
+
running = True
|
|
148
|
+
while running:
|
|
149
|
+
clock.tick(60)
|
|
150
|
+
for event in pygame.event.get():
|
|
151
|
+
if event.type == pygame.QUIT:
|
|
152
|
+
running = False
|
|
153
|
+
ui.handle_event(event)
|
|
154
|
+
|
|
155
|
+
current_radio_value = radio.get_value()
|
|
156
|
+
if current_radio_value != radio_last_value:
|
|
157
|
+
radio_value.set_text(f"Radio: {current_radio_value}")
|
|
158
|
+
radio_last_value = current_radio_value
|
|
159
|
+
|
|
160
|
+
screen.fill((250, 250, 250))
|
|
161
|
+
root.draw(screen)
|
|
162
|
+
pygame.display.flip()
|
|
163
|
+
|
|
164
|
+
pygame.quit()
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
if __name__ == "__main__":
|
|
168
|
+
main()
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
## Usage notes
|
|
175
|
+
|
|
176
|
+
- Use `UIManager` to handle events and manage focus/active state.
|
|
177
|
+
- Call `root.add_child(...)` to build a component tree. Child positions are relative to their parent.
|
|
178
|
+
- `TextInput` handles caret blink in `draw`, so you only need to call `draw` each frame.
|
|
179
|
+
- `Select` uses modal behavior through `UIManager`; clicks outside the dropdown close it.
|
|
180
|
+
- `Select` expects `options` as a list of strings and exposes `selected_value`.
|
|
181
|
+
- `Radio` expects `options` as a list of `(label, value)` tuples and exposes `get_value()`.
|
|
182
|
+
|
|
183
|
+
## TextInput allowed_char_mode
|
|
184
|
+
|
|
185
|
+
- `ALLOW_ALL_CHARS`
|
|
186
|
+
- `TEXT_ONLY`
|
|
187
|
+
- `NUMBER_ONLY`
|
|
188
|
+
- `HEX_ONLY`
|
|
189
|
+
- `BINARY_ONLY`
|
|
190
|
+
- `OCTAL_ONLY`
|
|
191
|
+
|
|
192
|
+
## Creating custom widgets
|
|
193
|
+
|
|
194
|
+
Subclass `UIComponent` and override any of the following hooks:
|
|
195
|
+
|
|
196
|
+
- `draw(surface)` for custom rendering
|
|
197
|
+
- `handle_event(event)` for keyboard/mouse logic
|
|
198
|
+
- `on_click(event)` for click behavior
|
|
199
|
+
|
|
200
|
+
## License
|
|
201
|
+
|
|
202
|
+
MIT
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
# pygame-widget-kit
|
|
2
|
+
|
|
3
|
+
[](https://pypi.org/project/pygame-widget-kit/)
|
|
4
|
+
|
|
5
|
+
A GUI framework built on Pygame. pygame-widget-kit is a retained-mode UI system with a component tree, event routing, focus and modal management, and extensible widgets such as Select/Dropdown and TextInput with mouse-based text selection and clipboard support.
|
|
6
|
+
|
|
7
|
+
PyPI: https://pypi.org/project/pygame-widget-kit/
|
|
8
|
+
|
|
9
|
+
## Features
|
|
10
|
+
|
|
11
|
+
- Retained-mode component tree with nested children
|
|
12
|
+
- Event routing with hover, focus, and active state handling
|
|
13
|
+
- Modal/dropdown support via `UIManager`
|
|
14
|
+
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`
|
|
15
|
+
- Text input filtering modes (text, number, hex, binary, octal)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
## Installation
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install pygame-widget-kit
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
Pygame is listed as a dependency (pygame >= 2.0.0). Make sure you call `pygame.init()` before creating widgets.
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
```python
|
|
29
|
+
|
|
30
|
+
import pygame
|
|
31
|
+
from pygame_widget_kit import *
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
SCREEN_WIDTH = 900
|
|
35
|
+
SCREEN_HEIGHT = 720
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def update_label_from_input(input_box: TextInput, label: Text):
|
|
39
|
+
label.set_text(f"Label: {input_box.text_value}")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def update_select_label(select: Select, label: Text):
|
|
43
|
+
label.set_text(f"Selected: {select.selected_value}")
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
def main():
|
|
47
|
+
pygame.init()
|
|
48
|
+
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
49
|
+
clock = pygame.time.Clock()
|
|
50
|
+
|
|
51
|
+
root = Widget((0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), border_color=None)
|
|
52
|
+
ui = UIManager(root)
|
|
53
|
+
|
|
54
|
+
title = Text("pygame-widget-kit demo", pos=(24, 20), text_color=(0, 0, 0))
|
|
55
|
+
root.add_child(title)
|
|
56
|
+
|
|
57
|
+
input_box = TextInput(rect=(24, 70, 220, 36), initial_text="")
|
|
58
|
+
update_button = Button("Update label", pos=(256, 70), size=(160, 36))
|
|
59
|
+
value_label = Text("Label: (empty)", pos=(432, 76), text_color=(0, 0, 0))
|
|
60
|
+
update_button.click_bind(update_label_from_input, input_box, value_label)
|
|
61
|
+
|
|
62
|
+
root.add_child(input_box)
|
|
63
|
+
root.add_child(update_button)
|
|
64
|
+
root.add_child(value_label)
|
|
65
|
+
|
|
66
|
+
input_types_title = Text("input types:", pos=(24, 150), text_color=(0, 0, 0))
|
|
67
|
+
root.add_child(input_types_title)
|
|
68
|
+
|
|
69
|
+
input_rows = [
|
|
70
|
+
("Allow all:", ALLOW_ALL_CHARS),
|
|
71
|
+
("Text only:", TEXT_ONLY),
|
|
72
|
+
("Number only:", NUMBER_ONLY),
|
|
73
|
+
("Hex only:", HEX_ONLY),
|
|
74
|
+
("Binary only:", BINARY_ONLY),
|
|
75
|
+
]
|
|
76
|
+
|
|
77
|
+
input_label_x = 24
|
|
78
|
+
input_box_x = 200
|
|
79
|
+
input_row_y = 190
|
|
80
|
+
input_row_gap = 44
|
|
81
|
+
|
|
82
|
+
for index, (label_text, mode) in enumerate(input_rows):
|
|
83
|
+
row_y = input_row_y + index * input_row_gap
|
|
84
|
+
row_label = Text(label_text, pos=(input_label_x, row_y + 6), text_color=(0, 0, 0))
|
|
85
|
+
row_input = TextInput(rect=(input_box_x, row_y, 240, 34), allowed_char_mode=mode)
|
|
86
|
+
root.add_child(row_label)
|
|
87
|
+
root.add_child(row_input)
|
|
88
|
+
|
|
89
|
+
select_label = Text("Select:", pos=(24, 430), text_color=(0, 0, 0))
|
|
90
|
+
select = Select(
|
|
91
|
+
rect=(100, 424, 160, 32),
|
|
92
|
+
options=["Easy", "Hard", "Expert"],
|
|
93
|
+
default_index=0,
|
|
94
|
+
z_index=2
|
|
95
|
+
)
|
|
96
|
+
select_value = Text("Selected: Easy", pos=(280, 430), text_color=(0, 0, 0))
|
|
97
|
+
select.bind_on_option_chance(update_select_label, select, select_value)
|
|
98
|
+
|
|
99
|
+
root.add_child(select_label)
|
|
100
|
+
root.add_child(select)
|
|
101
|
+
root.add_child(select_value)
|
|
102
|
+
|
|
103
|
+
radio_label = Text("Radio:", pos=(24, 490), text_color=(0, 0, 0))
|
|
104
|
+
radio = Radio(
|
|
105
|
+
(100, 486, 150, 28),
|
|
106
|
+
options=["OPTION A","OPTION B","OPTION C"],
|
|
107
|
+
default_index=0,
|
|
108
|
+
)
|
|
109
|
+
radio_value = Text("Radio: A", pos=(280, 490), text_color=(0, 0, 0))
|
|
110
|
+
|
|
111
|
+
root.add_child(radio_label)
|
|
112
|
+
root.add_child(radio)
|
|
113
|
+
root.add_child(radio_value)
|
|
114
|
+
|
|
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
|
+
|
|
124
|
+
|
|
125
|
+
running = True
|
|
126
|
+
while running:
|
|
127
|
+
clock.tick(60)
|
|
128
|
+
for event in pygame.event.get():
|
|
129
|
+
if event.type == pygame.QUIT:
|
|
130
|
+
running = False
|
|
131
|
+
ui.handle_event(event)
|
|
132
|
+
|
|
133
|
+
current_radio_value = radio.get_value()
|
|
134
|
+
if current_radio_value != radio_last_value:
|
|
135
|
+
radio_value.set_text(f"Radio: {current_radio_value}")
|
|
136
|
+
radio_last_value = current_radio_value
|
|
137
|
+
|
|
138
|
+
screen.fill((250, 250, 250))
|
|
139
|
+
root.draw(screen)
|
|
140
|
+
pygame.display.flip()
|
|
141
|
+
|
|
142
|
+
pygame.quit()
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
if __name__ == "__main__":
|
|
146
|
+
main()
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
```
|
|
151
|
+
|
|
152
|
+
## Usage notes
|
|
153
|
+
|
|
154
|
+
- Use `UIManager` to handle events and manage focus/active state.
|
|
155
|
+
- Call `root.add_child(...)` to build a component tree. Child positions are relative to their parent.
|
|
156
|
+
- `TextInput` handles caret blink in `draw`, so you only need to call `draw` each frame.
|
|
157
|
+
- `Select` uses modal behavior through `UIManager`; clicks outside the dropdown close it.
|
|
158
|
+
- `Select` expects `options` as a list of strings and exposes `selected_value`.
|
|
159
|
+
- `Radio` expects `options` as a list of `(label, value)` tuples and exposes `get_value()`.
|
|
160
|
+
|
|
161
|
+
## TextInput allowed_char_mode
|
|
162
|
+
|
|
163
|
+
- `ALLOW_ALL_CHARS`
|
|
164
|
+
- `TEXT_ONLY`
|
|
165
|
+
- `NUMBER_ONLY`
|
|
166
|
+
- `HEX_ONLY`
|
|
167
|
+
- `BINARY_ONLY`
|
|
168
|
+
- `OCTAL_ONLY`
|
|
169
|
+
|
|
170
|
+
## Creating custom widgets
|
|
171
|
+
|
|
172
|
+
Subclass `UIComponent` and override any of the following hooks:
|
|
173
|
+
|
|
174
|
+
- `draw(surface)` for custom rendering
|
|
175
|
+
- `handle_event(event)` for keyboard/mouse logic
|
|
176
|
+
- `on_click(event)` for click behavior
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
from pygame_widget_kit import *
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
SCREEN_WIDTH = 900
|
|
6
|
+
SCREEN_HEIGHT = 720
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def update_label_from_input(input_box: TextInput, label: Text):
|
|
10
|
+
label.set_text(f"Label: {input_box.text_value}")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
def update_select_label(select: Select, label: Text):
|
|
14
|
+
label.set_text(f"Selected: {select.selected_value}")
|
|
15
|
+
|
|
16
|
+
def update_slider_label(slider:Slider,label:Text):
|
|
17
|
+
label.set_text(f"Slider Value: {round(slider.value,2)}")
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def main():
|
|
22
|
+
pygame.init()
|
|
23
|
+
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
24
|
+
clock = pygame.time.Clock()
|
|
25
|
+
|
|
26
|
+
root = Widget((0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), border_color=None)
|
|
27
|
+
ui = UIManager(root)
|
|
28
|
+
|
|
29
|
+
title = Text("pygame-widget-kit demo", pos=(24, 20), text_color=(0, 0, 0))
|
|
30
|
+
root.add_child(title)
|
|
31
|
+
|
|
32
|
+
input_box = TextInput(rect=(24, 70, 220, 36), initial_text="")
|
|
33
|
+
update_button = Button("Update label", pos=(256, 70), size=(160, 36))
|
|
34
|
+
value_label = Text("Label: (empty)", pos=(432, 76), text_color=(0, 0, 0))
|
|
35
|
+
update_button.click_bind(update_label_from_input, input_box, value_label)
|
|
36
|
+
|
|
37
|
+
root.add_child(input_box)
|
|
38
|
+
root.add_child(update_button)
|
|
39
|
+
root.add_child(value_label)
|
|
40
|
+
|
|
41
|
+
input_types_title = Text("input types:", pos=(24, 150), text_color=(0, 0, 0))
|
|
42
|
+
root.add_child(input_types_title)
|
|
43
|
+
|
|
44
|
+
input_rows = [
|
|
45
|
+
("Allow all:", ALLOW_ALL_CHARS),
|
|
46
|
+
("Text only:", TEXT_ONLY),
|
|
47
|
+
("Number only:", NUMBER_ONLY),
|
|
48
|
+
("Hex only:", HEX_ONLY),
|
|
49
|
+
("Binary only:", BINARY_ONLY),
|
|
50
|
+
]
|
|
51
|
+
|
|
52
|
+
input_label_x = 24
|
|
53
|
+
input_box_x = 200
|
|
54
|
+
input_row_y = 190
|
|
55
|
+
input_row_gap = 44
|
|
56
|
+
|
|
57
|
+
for index, (label_text, mode) in enumerate(input_rows):
|
|
58
|
+
row_y = input_row_y + index * input_row_gap
|
|
59
|
+
row_label = Text(label_text, pos=(input_label_x, row_y + 6), text_color=(0, 0, 0))
|
|
60
|
+
row_input = TextInput(rect=(input_box_x, row_y, 240, 34), allowed_char_mode=mode)
|
|
61
|
+
root.add_child(row_label)
|
|
62
|
+
root.add_child(row_input)
|
|
63
|
+
|
|
64
|
+
select_label = Text("Select:", pos=(24, 430), text_color=(0, 0, 0))
|
|
65
|
+
select = Select(
|
|
66
|
+
rect=(100, 424, 160, 32),
|
|
67
|
+
options=["Easy", "Hard", "Expert"],
|
|
68
|
+
default_index=0,
|
|
69
|
+
z_index=2
|
|
70
|
+
)
|
|
71
|
+
select_value = Text("Selected: Easy", pos=(280, 430), text_color=(0, 0, 0))
|
|
72
|
+
select.bind_on_option_chance(update_select_label, select, select_value)
|
|
73
|
+
|
|
74
|
+
root.add_child(select_label)
|
|
75
|
+
root.add_child(select)
|
|
76
|
+
root.add_child(select_value)
|
|
77
|
+
|
|
78
|
+
radio_label = Text("Radio:", pos=(24, 490), text_color=(0, 0, 0))
|
|
79
|
+
radio = Radio(
|
|
80
|
+
(100, 486, 150, 28),
|
|
81
|
+
options=["OPTION A","OPTION B","OPTION C"],
|
|
82
|
+
default_index=0,
|
|
83
|
+
)
|
|
84
|
+
radio_value = Text("Radio: A", pos=(280, 490), text_color=(0, 0, 0))
|
|
85
|
+
|
|
86
|
+
root.add_child(radio_label)
|
|
87
|
+
root.add_child(radio)
|
|
88
|
+
root.add_child(radio_value)
|
|
89
|
+
|
|
90
|
+
radio_last_value = radio.get_value()
|
|
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
|
+
|
|
102
|
+
running = True
|
|
103
|
+
while running:
|
|
104
|
+
clock.tick(60)
|
|
105
|
+
for event in pygame.event.get():
|
|
106
|
+
if event.type == pygame.QUIT:
|
|
107
|
+
running = False
|
|
108
|
+
ui.handle_event(event)
|
|
109
|
+
|
|
110
|
+
current_radio_value = radio.get_value()
|
|
111
|
+
if current_radio_value != radio_last_value:
|
|
112
|
+
radio_value.set_text(f"Radio: {current_radio_value}")
|
|
113
|
+
radio_last_value = current_radio_value
|
|
114
|
+
|
|
115
|
+
screen.fill((250, 250, 250))
|
|
116
|
+
root.draw(screen)
|
|
117
|
+
pygame.display.flip()
|
|
118
|
+
|
|
119
|
+
pygame.quit()
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
if __name__ == "__main__":
|
|
123
|
+
main()
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import pygame
|
|
2
|
+
from .Text import *
|
|
3
|
+
from .UIComponent import *
|
|
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
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class Button(UIComponent):
|
|
36
|
+
def __init__(self, text_str = "Button",
|
|
37
|
+
pos = (0,0),
|
|
38
|
+
size = (200,40),
|
|
39
|
+
style=None,
|
|
40
|
+
z_index=0,
|
|
41
|
+
color=(175,175,175),
|
|
42
|
+
border_color = (100,100,100),
|
|
43
|
+
hover_color=(150,150,150),
|
|
44
|
+
text_color = (0,0,0),
|
|
45
|
+
padding = (20,10)
|
|
46
|
+
):
|
|
47
|
+
self.text_str = text_str
|
|
48
|
+
self.size = size
|
|
49
|
+
self.text_color =text_color
|
|
50
|
+
self.padding = padding
|
|
51
|
+
self.text = Text(self.text_str,pos = self.padding,text_color=text_color,bg_color=None)
|
|
52
|
+
|
|
53
|
+
self.click_function = None
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
rect = (pos[0],pos[1],self.size[0],self.size[1])
|
|
57
|
+
|
|
58
|
+
super().__init__(rect, style, z_index, color, border_color, hover_color)
|
|
59
|
+
self.add_child(self.text)
|
|
60
|
+
|
|
61
|
+
def click_bind(self, func, *args):
|
|
62
|
+
self.click_function = partial(func, *args)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def draw(self, surface):
|
|
66
|
+
if self.visible == False:
|
|
67
|
+
return
|
|
68
|
+
|
|
69
|
+
color = self.color
|
|
70
|
+
if self.hovered:
|
|
71
|
+
color=self.hover_color
|
|
72
|
+
|
|
73
|
+
if color is not None:
|
|
74
|
+
pygame.draw.rect(surface,color,self.absolute_rect,0)
|
|
75
|
+
if self.border_color:
|
|
76
|
+
pygame.draw.rect(surface,self.border_color,self.absolute_rect,2)
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
self.text.draw(surface)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def handle_event(self, event):
|
|
83
|
+
if event.type == pygame.MOUSEBUTTONDOWN:
|
|
84
|
+
self.active = True
|
|
85
|
+
|
|
86
|
+
elif event.type == pygame.MOUSEBUTTONUP:
|
|
87
|
+
self.active = False
|
|
88
|
+
|
|
89
|
+
def on_click(self, event):
|
|
90
|
+
if self.click_function is not None:
|
|
91
|
+
self.click_function()
|
|
92
|
+
else:
|
|
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
|
+
|
|
130
|
+
|