pygame-widget-kit 0.0.5__tar.gz → 0.0.7__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.7/MANIFEST.in +13 -0
- pygame_widget_kit-0.0.7/PKG-INFO +421 -0
- pygame_widget_kit-0.0.7/README.md +399 -0
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/pyproject.toml +32 -2
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/Animation.py +293 -0
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit/Button.py +63 -16
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/CodeEditor.py +258 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/Input.py +221 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/Layout.py +787 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/Loading.py +733 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/Navigation.py +301 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/ProgressBar.py +585 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/Radio.py +217 -0
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit/Select.py +22 -5
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit/Slider.py +55 -14
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit/Text.py +14 -6
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit/TextArea.py +17 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/TextEditSession.py +53 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/TextInput.py +2418 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/ToggleButton.py +173 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/UIComponent.py +219 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit/UIManager.py +464 -0
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit/Widget.py +2 -2
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit/__init__.py +8 -0
- pygame_widget_kit-0.0.7/src/pygame_widget_kit.egg-info/PKG-INFO +421 -0
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit.egg-info/SOURCES.txt +10 -1
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit.egg-info/top_level.txt +0 -1
- pygame_widget_kit-0.0.5/PKG-INFO +0 -202
- pygame_widget_kit-0.0.5/README.md +0 -180
- pygame_widget_kit-0.0.5/src/main.py +0 -127
- pygame_widget_kit-0.0.5/src/pygame_widget_kit/Radio.py +0 -125
- pygame_widget_kit-0.0.5/src/pygame_widget_kit/TextInput.py +0 -587
- pygame_widget_kit-0.0.5/src/pygame_widget_kit/UIComponent.py +0 -133
- pygame_widget_kit-0.0.5/src/pygame_widget_kit/UIManager.py +0 -125
- pygame_widget_kit-0.0.5/src/pygame_widget_kit.egg-info/PKG-INFO +0 -202
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/LICENSE +0 -0
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/setup.cfg +0 -0
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit.egg-info/dependency_links.txt +0 -0
- {pygame_widget_kit-0.0.5 → pygame_widget_kit-0.0.7}/src/pygame_widget_kit.egg-info/requires.txt +0 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
# Source distributions must not ship development-only files.
|
|
2
|
+
prune tests
|
|
3
|
+
prune .github
|
|
4
|
+
prune scripts
|
|
5
|
+
prune examples
|
|
6
|
+
prune .venv
|
|
7
|
+
prune htmlcov
|
|
8
|
+
exclude requirements-test.txt
|
|
9
|
+
exclude .coverage
|
|
10
|
+
exclude coverage.*
|
|
11
|
+
exclude test-results*.xml
|
|
12
|
+
exclude src/main.py
|
|
13
|
+
global-exclude __pycache__ *.py[cod] .DS_Store
|
|
@@ -0,0 +1,421 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pygame-widget-kit
|
|
3
|
+
Version: 0.0.7
|
|
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
|
+
- Opt-in keyboard and gamepad navigation, focus scopes, and text editing sessions
|
|
37
|
+
- Built-in widgets: `Button`, `Text`, `Select`, `Radio`, `TextInput`, `Slider`,`TextArea`, `CodeEditor`
|
|
38
|
+
- Text input filtering modes (text, number, hex, binary, octal)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
## Installation
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install pygame-widget-kit
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
Pygame is listed as a dependency (pygame >= 2.0.0). Make sure you call `pygame.init()` before creating widgets.
|
|
48
|
+
|
|
49
|
+
## Usage
|
|
50
|
+
|
|
51
|
+
```python
|
|
52
|
+
|
|
53
|
+
import pygame
|
|
54
|
+
from pygame_widget_kit import *
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
SCREEN_WIDTH = 900
|
|
58
|
+
SCREEN_HEIGHT = 720
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def update_label_from_input(input_box: TextInput, label: Text):
|
|
62
|
+
label.set_text(f"Label: {input_box.text_value}")
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def update_select_label(select: Select, label: Text):
|
|
66
|
+
label.set_text(f"Selected: {select.selected_value}")
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def main():
|
|
70
|
+
pygame.init()
|
|
71
|
+
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
|
|
72
|
+
clock = pygame.time.Clock()
|
|
73
|
+
|
|
74
|
+
root = Widget((0, 0, SCREEN_WIDTH, SCREEN_HEIGHT), border_color=None)
|
|
75
|
+
ui = UIManager(root)
|
|
76
|
+
|
|
77
|
+
title = Text("pygame-widget-kit demo", pos=(24, 20), text_color=(0, 0, 0))
|
|
78
|
+
root.add_child(title)
|
|
79
|
+
|
|
80
|
+
input_box = TextInput(rect=(24, 70, 220, 36), initial_text="")
|
|
81
|
+
update_button = Button("Update label", pos=(256, 70), size=(160, 36))
|
|
82
|
+
value_label = Text("Label: (empty)", pos=(432, 76), text_color=(0, 0, 0))
|
|
83
|
+
update_button.click_bind(update_label_from_input, input_box, value_label)
|
|
84
|
+
|
|
85
|
+
root.add_child(input_box)
|
|
86
|
+
root.add_child(update_button)
|
|
87
|
+
root.add_child(value_label)
|
|
88
|
+
|
|
89
|
+
input_types_title = Text("input types:", pos=(24, 150), text_color=(0, 0, 0))
|
|
90
|
+
root.add_child(input_types_title)
|
|
91
|
+
|
|
92
|
+
input_rows = [
|
|
93
|
+
("Allow all:", ALLOW_ALL_CHARS),
|
|
94
|
+
("Text only:", TEXT_ONLY),
|
|
95
|
+
("Number only:", NUMBER_ONLY),
|
|
96
|
+
("Hex only:", HEX_ONLY),
|
|
97
|
+
("Binary only:", BINARY_ONLY),
|
|
98
|
+
]
|
|
99
|
+
|
|
100
|
+
input_label_x = 24
|
|
101
|
+
input_box_x = 200
|
|
102
|
+
input_row_y = 190
|
|
103
|
+
input_row_gap = 44
|
|
104
|
+
|
|
105
|
+
for index, (label_text, mode) in enumerate(input_rows):
|
|
106
|
+
row_y = input_row_y + index * input_row_gap
|
|
107
|
+
row_label = Text(label_text, pos=(input_label_x, row_y + 6), text_color=(0, 0, 0))
|
|
108
|
+
row_input = TextInput(rect=(input_box_x, row_y, 240, 34), allowed_char_mode=mode)
|
|
109
|
+
root.add_child(row_label)
|
|
110
|
+
root.add_child(row_input)
|
|
111
|
+
|
|
112
|
+
select_label = Text("Select:", pos=(24, 430), text_color=(0, 0, 0))
|
|
113
|
+
select = Select(
|
|
114
|
+
rect=(100, 424, 160, 32),
|
|
115
|
+
options=["Easy", "Hard", "Expert"],
|
|
116
|
+
default_index=0,
|
|
117
|
+
z_index=2
|
|
118
|
+
)
|
|
119
|
+
select_value = Text("Selected: Easy", pos=(280, 430), text_color=(0, 0, 0))
|
|
120
|
+
select.bind_on_option_chance(update_select_label, select, select_value)
|
|
121
|
+
|
|
122
|
+
root.add_child(select_label)
|
|
123
|
+
root.add_child(select)
|
|
124
|
+
root.add_child(select_value)
|
|
125
|
+
|
|
126
|
+
radio_label = Text("Radio:", pos=(24, 490), text_color=(0, 0, 0))
|
|
127
|
+
radio = Radio(
|
|
128
|
+
(100, 486, 150, 28),
|
|
129
|
+
options=["OPTION A","OPTION B","OPTION C"],
|
|
130
|
+
default_index=0,
|
|
131
|
+
)
|
|
132
|
+
radio_value = Text("Radio: A", pos=(280, 490), text_color=(0, 0, 0))
|
|
133
|
+
|
|
134
|
+
root.add_child(radio_label)
|
|
135
|
+
root.add_child(radio)
|
|
136
|
+
root.add_child(radio_value)
|
|
137
|
+
|
|
138
|
+
radio_last_value = radio.get_value()
|
|
139
|
+
slider = Slider((20,580),size=(500,20),min_value=50,max_value=2000)
|
|
140
|
+
slider_value = Text("Sider Value", pos=(20, 600), text_color=(0, 0, 0))
|
|
141
|
+
slider.change_bind(update_slider_label,slider,slider_value)
|
|
142
|
+
|
|
143
|
+
root.add_child(slider)
|
|
144
|
+
root.add_child(slider_value)
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
running = True
|
|
149
|
+
while running:
|
|
150
|
+
clock.tick(60)
|
|
151
|
+
for event in pygame.event.get():
|
|
152
|
+
if event.type == pygame.QUIT:
|
|
153
|
+
running = False
|
|
154
|
+
ui.handle_event(event)
|
|
155
|
+
|
|
156
|
+
current_radio_value = radio.get_value()
|
|
157
|
+
if current_radio_value != radio_last_value:
|
|
158
|
+
radio_value.set_text(f"Radio: {current_radio_value}")
|
|
159
|
+
radio_last_value = current_radio_value
|
|
160
|
+
|
|
161
|
+
screen.fill((250, 250, 250))
|
|
162
|
+
root.draw(screen)
|
|
163
|
+
pygame.display.flip()
|
|
164
|
+
|
|
165
|
+
pygame.quit()
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
if __name__ == "__main__":
|
|
169
|
+
main()
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
## Usage notes
|
|
176
|
+
|
|
177
|
+
- Use `UIManager` to handle events and manage focus/active state.
|
|
178
|
+
- Call `root.add_child(...)` to build a component tree. Child positions are relative to their parent.
|
|
179
|
+
- `TextInput` handles caret blink in `draw`, so you only need to call `draw` each frame.
|
|
180
|
+
- `Select` uses modal behavior through `UIManager`; clicks outside the dropdown close it.
|
|
181
|
+
- `Select` expects `options` as a list of strings and exposes `selected_value`.
|
|
182
|
+
- `Radio` expects `options` as a list of `(label, value)` tuples and exposes `get_value()`.
|
|
183
|
+
|
|
184
|
+
## Keyboard and gamepad navigation
|
|
185
|
+
|
|
186
|
+
Navigation is **disabled by default**. Existing `UIManager(root)` applications
|
|
187
|
+
keep their mouse and text-entry behavior. Enable the additional controls with:
|
|
188
|
+
|
|
189
|
+
```python
|
|
190
|
+
ui = UIManager(root, navigation_enabled=True)
|
|
191
|
+
|
|
192
|
+
# Optional configuration; key/button maps belong to each manager.
|
|
193
|
+
config = NavigationConfig(
|
|
194
|
+
keyboard=True,
|
|
195
|
+
gamepad=True,
|
|
196
|
+
wrap=False,
|
|
197
|
+
repeat_delay=0.4, # seconds before a held direction repeats
|
|
198
|
+
repeat_interval=0.1,
|
|
199
|
+
axis_threshold=0.55,
|
|
200
|
+
axis_release_threshold=0.35,
|
|
201
|
+
)
|
|
202
|
+
# Pass config when constructing the manager:
|
|
203
|
+
# ui = UIManager(root, navigation_enabled=True, navigation_config=config)
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
Default controls:
|
|
207
|
+
|
|
208
|
+
| Input | Behavior |
|
|
209
|
+
| --- | --- |
|
|
210
|
+
| Arrow keys / D-pad / left stick | Move focus; the stick uses a dead zone and a dominant direction. |
|
|
211
|
+
| Tab / Shift+Tab | Next / previous focusable component. |
|
|
212
|
+
| Enter / keypad Enter / Space / controller south button | Activate once on press. |
|
|
213
|
+
| Escape / controller east button | Cancel editing or close the top modal. Unhandled Cancel returns to the application. |
|
|
214
|
+
|
|
215
|
+
The first navigation command selects `root.default_focus` or the first eligible
|
|
216
|
+
control without activating it. Alternatively, call `ui.set_focus(play_button)`
|
|
217
|
+
when opening a menu. Focus changes ignore decorative labels, disabled/hidden
|
|
218
|
+
ancestors, collapsed content, and controls clipped by fixed containers.
|
|
219
|
+
Scrollable lists automatically reveal the focused control. Hover does not move
|
|
220
|
+
keyboard focus; a mouse click does.
|
|
221
|
+
|
|
222
|
+
Use `ui.draw(screen)` for the tree and focus overlay, and call `ui.update(dt)`
|
|
223
|
+
each frame (`dt` in seconds). Built-in controls also show focus when drawn
|
|
224
|
+
through `root.draw(screen)`. Keep one application-owned event loop:
|
|
225
|
+
|
|
226
|
+
```python
|
|
227
|
+
for event in pygame.event.get():
|
|
228
|
+
if event.type == pygame.QUIT:
|
|
229
|
+
running = False
|
|
230
|
+
elif not ui.handle_event(event):
|
|
231
|
+
handle_game_event(event)
|
|
232
|
+
|
|
233
|
+
ui.update(dt)
|
|
234
|
+
screen.fill((30, 30, 40))
|
|
235
|
+
ui.draw(screen)
|
|
236
|
+
pygame.display.flip()
|
|
237
|
+
|
|
238
|
+
# Pause/resume the extra navigation without rebuilding the UI:
|
|
239
|
+
ui.navigation_enabled = False
|
|
240
|
+
ui.set_navigation_enabled(True)
|
|
241
|
+
|
|
242
|
+
# Before pygame.quit(), release handles opened by the manager:
|
|
243
|
+
ui.close()
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
`handle_event()` returns a boolean indicating UI consumption. If gameplay polls
|
|
247
|
+
held keys directly, gate that polling on the game's menu/gameplay state as well.
|
|
248
|
+
The manager never drains the event queue or changes global keyboard repeat to
|
|
249
|
+
implement navigation. Focus loss, device removal, and disabling navigation clear
|
|
250
|
+
held navigation state. Accept and Cancel do not auto-repeat.
|
|
251
|
+
|
|
252
|
+
Set `component.focusable = False` to exclude an interactive control. Use
|
|
253
|
+
`component.tab_index` to change sequential order (lower values first; equal
|
|
254
|
+
values preserve tree order). Directional navigation first tries explicit
|
|
255
|
+
neighbors, then follows nested layout branches. Geometry is the fallback for
|
|
256
|
+
freely positioned controls:
|
|
257
|
+
|
|
258
|
+
```python
|
|
259
|
+
play_button.navigation_neighbors[UIAction.RIGHT] = settings_button
|
|
260
|
+
root.default_focus = play_button
|
|
261
|
+
ui.handle_action(UIAction.DOWN) # one-shot action from another input source
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
Button, ToggleButton, Select, Radio, Slider, TextInput, CodeEditor, and
|
|
265
|
+
CollapsibleContainer participate automatically. Radio is one focus stop;
|
|
266
|
+
arrows normally move past the entire group without changing its value. Accept
|
|
267
|
+
enters editing, up/down previews enabled, visible options, and another Accept
|
|
268
|
+
commits the highlighted option and ends editing. Cancel or focus loss discards
|
|
269
|
+
the preview. The focus outline marks the previewed row while the radio dot
|
|
270
|
+
continues to show the committed value. Mouse clicks still select directly.
|
|
271
|
+
`Radio.highlighted_index` exposes the preview; `selected_index` and `get_value()`
|
|
272
|
+
expose the committed selection. Navigation and previews do not fire option
|
|
273
|
+
callbacks; confirmation or mouse selection does. While editing, directional
|
|
274
|
+
input stays in the group; outside editing, arrows navigate to neighboring
|
|
275
|
+
controls. This uses the same `editing`, `end_edit()` and `handle_ui_action()`
|
|
276
|
+
contracts as other editable controls, without widget-specific manager routing.
|
|
277
|
+
Slider left/right adjusts by `step`
|
|
278
|
+
(default `1`), while up/down leaves the slider. For a slider inside a horizontal
|
|
279
|
+
menu, pass `navigation_edit_mode=True`: Accept enters/leaves adjustment mode,
|
|
280
|
+
Cancel leaves it, and left/right outside that mode moves focus. A collapsible
|
|
281
|
+
section's focus rectangle covers its header.
|
|
282
|
+
|
|
283
|
+
Nested menus follow these rules:
|
|
284
|
+
|
|
285
|
+
| Context | Controls |
|
|
286
|
+
| --- | --- |
|
|
287
|
+
| Expanded vertical section | Down enters its first control, continues through its contents, then reaches the next section header. Up follows the reverse order. |
|
|
288
|
+
| Collapsed section | Up/down skips its contents. Accept opens it; Down then enters the first eligible control. |
|
|
289
|
+
| Section header | Left/right moves directly to a neighboring section/column, preserving open/closed states. Accept toggles the section; Down enters its contents if open. |
|
|
290
|
+
| Section contents | Left returns to the nearest enclosing header when no local horizontal control handles it. Cancel also returns to the header after closing any editor or modal. |
|
|
291
|
+
| Horizontal row | Left/right moves between its controls. Up/down leaves the row and preserves horizontal alignment when entering another row. |
|
|
292
|
+
| Multiple columns | Up/down stays in the current column, including at its boundaries. Horizontal transitions between columns enter a section header rather than an arbitrary nested control. |
|
|
293
|
+
|
|
294
|
+
With `wrap=True`, directional wrapping stays within the corresponding layout
|
|
295
|
+
branch; Tab/Shift+Tab still traverse the full active focus scope. Disabled and
|
|
296
|
+
hidden controls and decorative labels are skipped. Entering a section during its
|
|
297
|
+
opening animation reveals the focused control immediately. Scrollable columns
|
|
298
|
+
remain navigable when nested inside another clipped layout. The grouped demo in
|
|
299
|
+
`src/main.py` makes both columns scrollable so their lower controls are reachable.
|
|
300
|
+
|
|
301
|
+
Select focuses its current option on opening. Directions browse without changing
|
|
302
|
+
the value; Accept selects and Cancel dismisses. For custom dialogs, attach the
|
|
303
|
+
dialog to the tree, then use `ui.push_modal(dialog, initial_focus=button)` and
|
|
304
|
+
`ui.pop_modal(dialog)`. Popping restores the previous valid focus; the caller
|
|
305
|
+
controls dialog visibility/removal. Cancel calls the top modal's `close()` hook,
|
|
306
|
+
or hides and pops a modal without that hook. Nested scopes are supported, and
|
|
307
|
+
legacy `ui.modal = dialog` / `ui.modal = None` assignments still work.
|
|
308
|
+
|
|
309
|
+
Recognized gamepads use SDL controller mappings (south/east correspond to the
|
|
310
|
+
usual accept/back positions, independently of button labels). Other joysticks
|
|
311
|
+
use configurable raw buttons, hat `0`, and axes `(0, 1)`. For example:
|
|
312
|
+
|
|
313
|
+
```python
|
|
314
|
+
config.keyboard_bindings[pygame.K_s] = UIAction.DOWN
|
|
315
|
+
config.joystick_bindings = {2: UIAction.ACCEPT, 3: UIAction.CANCEL}
|
|
316
|
+
config.controller_bindings[pygame.CONTROLLER_BUTTON_Y] = UIAction.ACCEPT
|
|
317
|
+
config.joystick_axes = (0, 1)
|
|
318
|
+
# Optional: restrict the menu to a connected device's instance ID.
|
|
319
|
+
config.controller_id = joystick.get_instance_id()
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
Without `controller_id`, the first device providing a meaningful menu input owns
|
|
323
|
+
gamepad navigation until disconnected or navigation is reset. Device indices are
|
|
324
|
+
used only when opening devices; routing uses instance IDs. Controller-backed
|
|
325
|
+
joystick events are suppressed to avoid duplicate actions. Physical mappings can
|
|
326
|
+
vary for raw joysticks; adjust their bindings for the device.
|
|
327
|
+
|
|
328
|
+
### Text editing and future on-screen keyboards
|
|
329
|
+
|
|
330
|
+
With navigation enabled, focusing a text field selects it; Accept starts editing.
|
|
331
|
+
Clicking it with the mouse starts editing directly. While editing, keyboard
|
|
332
|
+
arrows, spaces and Tab belong to the editor. Enter commits a single-line input
|
|
333
|
+
and inserts a newline in a multiline input. Escape cancels the current session,
|
|
334
|
+
restoring its original text, selection and undo/redo history. Gamepad directions
|
|
335
|
+
stay inside the editing interaction; gamepad Accept commits it.
|
|
336
|
+
|
|
337
|
+
`TextInput.begin_edit()` returns a `TextEditSession` supporting `insert_text`,
|
|
338
|
+
`backspace`, `commit`, and `cancel`. `input.on_edit_requested` is an optional
|
|
339
|
+
callback receiving this session when Accept starts editing. It can later open
|
|
340
|
+
a keyboard modal; the session remains usable while that modal has focus:
|
|
341
|
+
|
|
342
|
+
```python
|
|
343
|
+
def request_keyboard(session):
|
|
344
|
+
# Build/show your keyboard and route its character buttons through:
|
|
345
|
+
session.insert_text("ş") # same filtering and history as TextInput
|
|
346
|
+
# On Done: session.commit(), then close/pop the keyboard modal.
|
|
347
|
+
# On Cancel: session.cancel(), then close/pop the keyboard modal.
|
|
348
|
+
|
|
349
|
+
name_input.on_edit_requested = request_keyboard
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
This release provides the session hook, not an on-screen keyboard widget.
|
|
353
|
+
Legacy `KEYDOWN.unicode` typing remains the default. To use Pygame Unicode
|
|
354
|
+
`TEXTINPUT` events instead, construct the manager with
|
|
355
|
+
`NavigationConfig(text_input_events=True)` and ensure the application enables
|
|
356
|
+
Pygame text input. In that mode printable `KEYDOWN.unicode` is ignored to prevent
|
|
357
|
+
double insertion; editing shortcuts still use key events.
|
|
358
|
+
|
|
359
|
+
Custom controls can set `focusable = True`, override `activate()` and
|
|
360
|
+
`handle_ui_action(action)` (return `True` when consumed), and optionally override
|
|
361
|
+
`get_navigation_rect()`. `ui.draw()` overlays their focus rectangle even when they
|
|
362
|
+
implement their own drawing.
|
|
363
|
+
|
|
364
|
+
Run the mixed-control example after an editable install:
|
|
365
|
+
|
|
366
|
+
```bash
|
|
367
|
+
python examples/navigation_menu.py
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
## CodeEditor (syntax highlight)
|
|
371
|
+
|
|
372
|
+
`CodeEditor`, `TextInput` sinifini inherit eder ve anahtar kelimeleri renk/bold/italic ile cizer.
|
|
373
|
+
|
|
374
|
+
```python
|
|
375
|
+
editor = CodeEditor(
|
|
376
|
+
rect=(24, 520, 620, 170),
|
|
377
|
+
initial_text="for i in range(3):\n print(i)",
|
|
378
|
+
keyword_styles={
|
|
379
|
+
"for": {"color": (0, 120, 255), "bold": True},
|
|
380
|
+
"in": {"color": (0, 120, 255), "bold": True},
|
|
381
|
+
"range": {"color": (200, 120, 30), "italic": True},
|
|
382
|
+
},
|
|
383
|
+
)
|
|
384
|
+
root.add_child(editor)
|
|
385
|
+
|
|
386
|
+
# Autocomplete altyapisi (UI'siz provider hook)
|
|
387
|
+
def my_provider(full_text, cursor_pos, prefix):
|
|
388
|
+
return ["for", "format", "from"] if prefix.startswith("f") else []
|
|
389
|
+
|
|
390
|
+
editor.set_autocomplete_provider(my_provider)
|
|
391
|
+
suggestions = editor.request_completions()
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
## TextInput allowed_char_mode
|
|
395
|
+
|
|
396
|
+
- `ALLOW_ALL_CHARS`
|
|
397
|
+
- `TEXT_ONLY`
|
|
398
|
+
- `NUMBER_ONLY`
|
|
399
|
+
- `HEX_ONLY`
|
|
400
|
+
- `BINARY_ONLY`
|
|
401
|
+
- `OCTAL_ONLY`
|
|
402
|
+
|
|
403
|
+
## Creating custom widgets
|
|
404
|
+
|
|
405
|
+
Subclass `UIComponent` and override any of the following hooks:
|
|
406
|
+
|
|
407
|
+
- `draw(surface)` for custom rendering
|
|
408
|
+
- `handle_event(event)` for keyboard/mouse logic
|
|
409
|
+
- `on_click(event)` for click behavior
|
|
410
|
+
|
|
411
|
+
## Automated tests
|
|
412
|
+
|
|
413
|
+
For development, run `python -m pip install -e . -r requirements-test.txt`, then `python -m pytest`.
|
|
414
|
+
Published packages include only the library; tests and test dependencies are excluded.
|
|
415
|
+
See [tests/README.md](tests/README.md) for headless fixtures, the UI driver,
|
|
416
|
+
coverage, CI, and branch protection setup. See the
|
|
417
|
+
[verification report](tests/REPORT.md) for the current results and fixed defects.
|
|
418
|
+
|
|
419
|
+
## License
|
|
420
|
+
|
|
421
|
+
MIT
|