pydevices-pdwidgets 0.0.22__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.
- pydevices_pdwidgets-0.0.22/LICENSE +21 -0
- pydevices_pdwidgets-0.0.22/PKG-INFO +132 -0
- pydevices_pdwidgets-0.0.22/README.md +116 -0
- pydevices_pdwidgets-0.0.22/VERSION +1 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/__init__.py +160 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/_compat.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/_constants.py +90 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/_focus.py +122 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/_icon_load.py +52 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/_themes.py +149 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/_util.py +64 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/_write_font.py +120 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/console.py +258 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/display.py +469 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/LICENSE +202 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/README.md +15 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/__init__.py +4 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/add_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/add_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/add_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/add_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/battery_full_color_24dp.py +78 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/bluetooth_color_24dp.py +78 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/check_box_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/check_box_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/check_box_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/check_box_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/check_box_outline_blank_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/check_box_outline_blank_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/check_box_outline_blank_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/check_box_outline_blank_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/close_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/close_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/close_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/close_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/error_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/error_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/error_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/error_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/expand_more_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/expand_more_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/expand_more_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/expand_more_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/home_filled_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/home_filled_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/home_filled_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/home_filled_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/info_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/info_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/info_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/info_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_down_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_down_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_down_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_down_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_left_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_left_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_left_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_left_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_right_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_right_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_right_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_right_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_up_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_up_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_up_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/keyboard_arrow_up_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/menu_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/menu_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/menu_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/menu_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/notifications_color_24dp.py +78 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/radio_button_checked_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/radio_button_checked_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/radio_button_checked_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/radio_button_checked_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/radio_button_unchecked_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/radio_button_unchecked_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/radio_button_unchecked_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/radio_button_unchecked_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/remove_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/remove_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/remove_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/remove_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/toggle_off_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/toggle_off_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/toggle_off_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/toggle_off_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/toggle_on_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/toggle_on_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/toggle_on_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/toggle_on_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/warning_18dp.py +10 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/warning_24dp.py +11 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/warning_36dp.py +18 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/icons/warning_48dp.py +24 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/pct.py +143 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/screen.py +77 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/task.py +49 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widget-dependencies.md +78 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widget.py +553 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/__init__.py +130 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/_layout.py +64 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/_raised.py +126 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/accordion.py +81 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/app_bar.py +88 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/badge.py +79 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/bottom_sheet.py +77 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/button.py +264 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/card.py +164 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/chart.py +87 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/check_box.py +55 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/chip.py +106 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/color_picker.py +128 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/column.py +34 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/date_picker.py +176 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/dialog.py +133 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/digital_clock.py +81 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/divider.py +47 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/drawer.py +78 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/dropdown.py +197 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/form.py +74 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/form_row.py +66 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/gauge.py +79 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/grid.py +67 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/icon.py +135 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/icon_button.py +98 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/image.py +117 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/keyboard.py +171 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/label.py +157 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/list_view.py +141 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/menu.py +98 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/navigator.py +90 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/number_stepper.py +121 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/page.py +53 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/password_field.py +77 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/pin_pad.py +82 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/progress_bar.py +138 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/radio_button.py +68 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/radio_group.py +55 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/row.py +34 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/scroll_bar.py +148 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/scroll_view.py +128 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/segmented_control.py +128 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/slider.py +151 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/spinner.py +84 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/switch.py +84 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/tab_view.py +175 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/text_box.py +96 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/text_input.py +119 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/toast.py +108 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/toggle.py +80 -0
- pydevices_pdwidgets-0.0.22/lib/pdwidgets/widgets/toggle_button.py +55 -0
- pydevices_pdwidgets-0.0.22/lib/pydevices_pdwidgets.egg-info/PKG-INFO +132 -0
- pydevices_pdwidgets-0.0.22/lib/pydevices_pdwidgets.egg-info/SOURCES.txt +164 -0
- pydevices_pdwidgets-0.0.22/lib/pydevices_pdwidgets.egg-info/dependency_links.txt +1 -0
- pydevices_pdwidgets-0.0.22/lib/pydevices_pdwidgets.egg-info/requires.txt +3 -0
- pydevices_pdwidgets-0.0.22/lib/pydevices_pdwidgets.egg-info/top_level.txt +1 -0
- pydevices_pdwidgets-0.0.22/pyproject.toml +48 -0
- pydevices_pdwidgets-0.0.22/setup.cfg +4 -0
- pydevices_pdwidgets-0.0.22/tests/test_button_backdrop.py +65 -0
- pydevices_pdwidgets-0.0.22/tests/test_compat.py +25 -0
- pydevices_pdwidgets-0.0.22/tests/test_dirty_z_order.py +67 -0
- pydevices_pdwidgets-0.0.22/tests/test_import.py +24 -0
- pydevices_pdwidgets-0.0.22/tests/test_raised.py +102 -0
- pydevices_pdwidgets-0.0.22/tests/test_widget_api.py +78 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2023 Brad Barnett
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: pydevices-pdwidgets
|
|
3
|
+
Version: 0.0.22
|
|
4
|
+
Summary: Cross-platform widget toolkit for PyDevices
|
|
5
|
+
Author: Brad Barnett
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/PyDevices/pdwidgets
|
|
8
|
+
Project-URL: Issues, https://github.com/PyDevices/pdwidgets/issues
|
|
9
|
+
Requires-Python: >=3.8
|
|
10
|
+
Description-Content-Type: text/markdown
|
|
11
|
+
License-File: LICENSE
|
|
12
|
+
Requires-Dist: pydevices
|
|
13
|
+
Requires-Dist: pydevices-pygraphics
|
|
14
|
+
Requires-Dist: pydevices-palettes
|
|
15
|
+
Dynamic: license-file
|
|
16
|
+
|
|
17
|
+
# pdwidgets
|
|
18
|
+
|
|
19
|
+
**Pure-Python, portable widget toolkit for [PyDevices](https://github.com/PyDevices/pydevices)**
|
|
20
|
+
|
|
21
|
+
`pdwidgets` provides a complete, 100% pure-Python GUI toolkit for building touchscreen and desktop interfaces without requiring native C bindings or complex build toolchains. It runs seamlessly on **MicroPython**, **CircuitPython**, **CPython desktop**, and **PyScript (Web)**.
|
|
22
|
+
|
|
23
|
+
### Where pdwidgets fits
|
|
24
|
+
|
|
25
|
+
PyDevices offers several GUI approaches; `pdwidgets` is the pure-Python one. See
|
|
26
|
+
[pydevices — choosing a GUI layer](https://github.com/PyDevices/pydevices/blob/main/docs/architecture.md#choosing-a-gui-layer).
|
|
27
|
+
|
|
28
|
+
---
|
|
29
|
+
|
|
30
|
+
## Quick Start: Interactive Button & Screen
|
|
31
|
+
|
|
32
|
+
```python
|
|
33
|
+
import board_config
|
|
34
|
+
import appdev
|
|
35
|
+
import pdwidgets as pd
|
|
36
|
+
from pdwidgets.icons import touch_app # Pure-Python icon bytecode
|
|
37
|
+
|
|
38
|
+
# 1. Initialize display and the event app
|
|
39
|
+
app = appdev.App(board_config)
|
|
40
|
+
display = pd.Display(board_config.display_drv, app)
|
|
41
|
+
screen = pd.Screen(display)
|
|
42
|
+
|
|
43
|
+
_taps = 0
|
|
44
|
+
|
|
45
|
+
# 2. Add an interactive button with a click handler
|
|
46
|
+
btn = pd.Button(
|
|
47
|
+
screen,
|
|
48
|
+
x=40,
|
|
49
|
+
y=60,
|
|
50
|
+
w=160,
|
|
51
|
+
h=50,
|
|
52
|
+
label="Tap me (0)",
|
|
53
|
+
icon=touch_app,
|
|
54
|
+
)
|
|
55
|
+
|
|
56
|
+
def on_button_click(event):
|
|
57
|
+
global _taps
|
|
58
|
+
_taps += 1
|
|
59
|
+
btn.set_label(f"Tap me ({_taps})")
|
|
60
|
+
display.refresh()
|
|
61
|
+
|
|
62
|
+
btn.on_click(on_button_click)
|
|
63
|
+
|
|
64
|
+
# 3. Draw the initial screen. The app runs itself from here -- no app.run()
|
|
65
|
+
# is needed; call it only to block at this point or to get an exit code.
|
|
66
|
+
display.show(screen)
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
---
|
|
70
|
+
|
|
71
|
+
## Key Features
|
|
72
|
+
|
|
73
|
+
- **100% Pure Python & Portable**: Zero native C extensions or compilation steps required.
|
|
74
|
+
- **Zero-File Icon System (`pdwidgets.icons`)**: Material Design icons packaged directly as importable Python bytecode modules (`bytearray` bitmaps)—no SD card assets, binary file I/O, or asset path management needed.
|
|
75
|
+
- **MCU Memory-Friendly (Lean Imports)**: Import individual widgets to minimize RAM footprint on microcontrollers:
|
|
76
|
+
```python
|
|
77
|
+
from pdwidgets.widgets.button import Button
|
|
78
|
+
from pdwidgets.widgets.screen import Screen
|
|
79
|
+
```
|
|
80
|
+
- **Integrated Theming**: Customizable color schemes, border radii, and visual states using [`palettes`](https://github.com/PyDevices/palettes).
|
|
81
|
+
|
|
82
|
+
---
|
|
83
|
+
|
|
84
|
+
## Installation
|
|
85
|
+
|
|
86
|
+
```python
|
|
87
|
+
import mip
|
|
88
|
+
# pdwidgets does not pull its dependencies on MIP -- install them too.
|
|
89
|
+
mip.install("pydevices", index="https://PyDevices.github.io/mip")
|
|
90
|
+
mip.install("pygraphics", index="https://PyDevices.github.io/mip")
|
|
91
|
+
mip.install("palettes", index="https://PyDevices.github.io/mip")
|
|
92
|
+
mip.install("pdwidgets", index="https://PyDevices.github.io/mip")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
```bash
|
|
96
|
+
pip install -i https://test.pypi.org/simple/ \
|
|
97
|
+
--extra-index-url https://pypi.org/simple/ pydevices-pdwidgets
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
Full dependency chain and `board_config` requirements:
|
|
101
|
+
[docs/index.md](docs/index.md).
|
|
102
|
+
|
|
103
|
+
## Links & Demos
|
|
104
|
+
|
|
105
|
+
- [Documentation](https://pdwidgets.readthedocs.io)
|
|
106
|
+
- [Source Code](https://github.com/PyDevices/pdwidgets)
|
|
107
|
+
- [PyScript Live Demos](https://pydevices.github.io/pydevices-examples/pyscript/)
|
|
108
|
+
- Related: [pydevices](https://github.com/PyDevices/pydevices), [palettes](https://github.com/PyDevices/palettes), [pydevices-examples](https://github.com/PyDevices/pydevices-examples)
|
|
109
|
+
|
|
110
|
+
## License
|
|
111
|
+
|
|
112
|
+
MIT — see [LICENSE](LICENSE).
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Icon assets (maintainers)
|
|
118
|
+
|
|
119
|
+
Runtime icons are **importable Python modules** under [`lib/pdwidgets/icons/`](lib/pdwidgets/icons/)
|
|
120
|
+
(no binary mip). Authoring:
|
|
121
|
+
|
|
122
|
+
```bash
|
|
123
|
+
# 1) Optional: regenerate mono .pbm / color .bmp from Material Design
|
|
124
|
+
.venv/bin/python scripts/assets_generate_pdwidgets_icons.py
|
|
125
|
+
.venv/bin/python scripts/assets_make_color_icons.py
|
|
126
|
+
# 2) Convert binaries → .py modules (BITMAP = bytearray; uses sibling or TestPyPI pygraphics)
|
|
127
|
+
.venv/bin/python scripts/assets_icons_to_py.py --delete-binaries
|
|
128
|
+
# Optional bulk dump into assets/icons/
|
|
129
|
+
.venv/bin/python scripts/assets_convert_md_png_to_pbm.py
|
|
130
|
+
# PNG smoke probe (PyDevices display stack + material-design-icons png/)
|
|
131
|
+
SDL_VIDEODRIVER=dummy ../pydevices-examples/.venv/bin/python tools/png_test.py
|
|
132
|
+
```
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# pdwidgets
|
|
2
|
+
|
|
3
|
+
**Pure-Python, portable widget toolkit for [PyDevices](https://github.com/PyDevices/pydevices)**
|
|
4
|
+
|
|
5
|
+
`pdwidgets` provides a complete, 100% pure-Python GUI toolkit for building touchscreen and desktop interfaces without requiring native C bindings or complex build toolchains. It runs seamlessly on **MicroPython**, **CircuitPython**, **CPython desktop**, and **PyScript (Web)**.
|
|
6
|
+
|
|
7
|
+
### Where pdwidgets fits
|
|
8
|
+
|
|
9
|
+
PyDevices offers several GUI approaches; `pdwidgets` is the pure-Python one. See
|
|
10
|
+
[pydevices — choosing a GUI layer](https://github.com/PyDevices/pydevices/blob/main/docs/architecture.md#choosing-a-gui-layer).
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## Quick Start: Interactive Button & Screen
|
|
15
|
+
|
|
16
|
+
```python
|
|
17
|
+
import board_config
|
|
18
|
+
import appdev
|
|
19
|
+
import pdwidgets as pd
|
|
20
|
+
from pdwidgets.icons import touch_app # Pure-Python icon bytecode
|
|
21
|
+
|
|
22
|
+
# 1. Initialize display and the event app
|
|
23
|
+
app = appdev.App(board_config)
|
|
24
|
+
display = pd.Display(board_config.display_drv, app)
|
|
25
|
+
screen = pd.Screen(display)
|
|
26
|
+
|
|
27
|
+
_taps = 0
|
|
28
|
+
|
|
29
|
+
# 2. Add an interactive button with a click handler
|
|
30
|
+
btn = pd.Button(
|
|
31
|
+
screen,
|
|
32
|
+
x=40,
|
|
33
|
+
y=60,
|
|
34
|
+
w=160,
|
|
35
|
+
h=50,
|
|
36
|
+
label="Tap me (0)",
|
|
37
|
+
icon=touch_app,
|
|
38
|
+
)
|
|
39
|
+
|
|
40
|
+
def on_button_click(event):
|
|
41
|
+
global _taps
|
|
42
|
+
_taps += 1
|
|
43
|
+
btn.set_label(f"Tap me ({_taps})")
|
|
44
|
+
display.refresh()
|
|
45
|
+
|
|
46
|
+
btn.on_click(on_button_click)
|
|
47
|
+
|
|
48
|
+
# 3. Draw the initial screen. The app runs itself from here -- no app.run()
|
|
49
|
+
# is needed; call it only to block at this point or to get an exit code.
|
|
50
|
+
display.show(screen)
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
---
|
|
54
|
+
|
|
55
|
+
## Key Features
|
|
56
|
+
|
|
57
|
+
- **100% Pure Python & Portable**: Zero native C extensions or compilation steps required.
|
|
58
|
+
- **Zero-File Icon System (`pdwidgets.icons`)**: Material Design icons packaged directly as importable Python bytecode modules (`bytearray` bitmaps)—no SD card assets, binary file I/O, or asset path management needed.
|
|
59
|
+
- **MCU Memory-Friendly (Lean Imports)**: Import individual widgets to minimize RAM footprint on microcontrollers:
|
|
60
|
+
```python
|
|
61
|
+
from pdwidgets.widgets.button import Button
|
|
62
|
+
from pdwidgets.widgets.screen import Screen
|
|
63
|
+
```
|
|
64
|
+
- **Integrated Theming**: Customizable color schemes, border radii, and visual states using [`palettes`](https://github.com/PyDevices/palettes).
|
|
65
|
+
|
|
66
|
+
---
|
|
67
|
+
|
|
68
|
+
## Installation
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
import mip
|
|
72
|
+
# pdwidgets does not pull its dependencies on MIP -- install them too.
|
|
73
|
+
mip.install("pydevices", index="https://PyDevices.github.io/mip")
|
|
74
|
+
mip.install("pygraphics", index="https://PyDevices.github.io/mip")
|
|
75
|
+
mip.install("palettes", index="https://PyDevices.github.io/mip")
|
|
76
|
+
mip.install("pdwidgets", index="https://PyDevices.github.io/mip")
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
pip install -i https://test.pypi.org/simple/ \
|
|
81
|
+
--extra-index-url https://pypi.org/simple/ pydevices-pdwidgets
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Full dependency chain and `board_config` requirements:
|
|
85
|
+
[docs/index.md](docs/index.md).
|
|
86
|
+
|
|
87
|
+
## Links & Demos
|
|
88
|
+
|
|
89
|
+
- [Documentation](https://pdwidgets.readthedocs.io)
|
|
90
|
+
- [Source Code](https://github.com/PyDevices/pdwidgets)
|
|
91
|
+
- [PyScript Live Demos](https://pydevices.github.io/pydevices-examples/pyscript/)
|
|
92
|
+
- Related: [pydevices](https://github.com/PyDevices/pydevices), [palettes](https://github.com/PyDevices/palettes), [pydevices-examples](https://github.com/PyDevices/pydevices-examples)
|
|
93
|
+
|
|
94
|
+
## License
|
|
95
|
+
|
|
96
|
+
MIT — see [LICENSE](LICENSE).
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
---
|
|
100
|
+
|
|
101
|
+
## Icon assets (maintainers)
|
|
102
|
+
|
|
103
|
+
Runtime icons are **importable Python modules** under [`lib/pdwidgets/icons/`](lib/pdwidgets/icons/)
|
|
104
|
+
(no binary mip). Authoring:
|
|
105
|
+
|
|
106
|
+
```bash
|
|
107
|
+
# 1) Optional: regenerate mono .pbm / color .bmp from Material Design
|
|
108
|
+
.venv/bin/python scripts/assets_generate_pdwidgets_icons.py
|
|
109
|
+
.venv/bin/python scripts/assets_make_color_icons.py
|
|
110
|
+
# 2) Convert binaries → .py modules (BITMAP = bytearray; uses sibling or TestPyPI pygraphics)
|
|
111
|
+
.venv/bin/python scripts/assets_icons_to_py.py --delete-binaries
|
|
112
|
+
# Optional bulk dump into assets/icons/
|
|
113
|
+
.venv/bin/python scripts/assets_convert_md_png_to_pbm.py
|
|
114
|
+
# PNG smoke probe (PyDevices display stack + material-design-icons png/)
|
|
115
|
+
SDL_VIDEODRIVER=dummy ../pydevices-examples/.venv/bin/python tools/png_test.py
|
|
116
|
+
```
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
0.0.22
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""
|
|
5
|
+
`pdwidgets`
|
|
6
|
+
====================================================
|
|
7
|
+
Provides a collection of widgets for creating graphical user interfaces on embedded systems.
|
|
8
|
+
It includes base classes for widgets, as well as specific widgets such as buttons, labels, sliders, and more.
|
|
9
|
+
|
|
10
|
+
Core (always imported): Display, Screen, Task, Widget, themes, constants.
|
|
11
|
+
|
|
12
|
+
Widgets load lazily via ``__getattr__`` so MCU images only pay for modules you
|
|
13
|
+
touch. Lean path::
|
|
14
|
+
|
|
15
|
+
from pdwidgets.widgets.button import Button
|
|
16
|
+
|
|
17
|
+
Convenience::
|
|
18
|
+
|
|
19
|
+
import pdwidgets as pd
|
|
20
|
+
pd.Button(...) # imports widgets.button on first access
|
|
21
|
+
|
|
22
|
+
See ``widget-dependencies.md`` for the peer import graph.
|
|
23
|
+
|
|
24
|
+
Proportional fonts:
|
|
25
|
+
``Label`` (and widgets built on it) gains proportional-font rendering when a
|
|
26
|
+
``font`` module is supplied. That path uses the private
|
|
27
|
+
:mod:`pdwidgets._write_font` helper (fonts from ``write_font_converter``).
|
|
28
|
+
|
|
29
|
+
Timer architecture:
|
|
30
|
+
pdwidgets owns **no** timer of its own. Each :class:`Display` wires itself
|
|
31
|
+
into the shared ``appdev.App`` at construction. Apps just build the UI;
|
|
32
|
+
the app keeps itself alive past the end of the script.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
import events
|
|
36
|
+
from pygraphics import Area
|
|
37
|
+
|
|
38
|
+
from . import pct
|
|
39
|
+
from ._constants import (
|
|
40
|
+
ALIGN, #: Widget alignment flags (``ALIGN.TOP_LEFT``, ``ALIGN.CENTER``, …).
|
|
41
|
+
DEFAULT_PADDING, #: Default ``(PAD, PAD, PAD, PAD)`` inset for widgets.
|
|
42
|
+
ICON_SIZE, #: Valid icon sizes: ``SMALL`` (18), ``MEDIUM`` (24), ``LARGE`` (36), ``XLARGE`` (48).
|
|
43
|
+
PAD, #: Default padding unit in pixels (2).
|
|
44
|
+
POSITION, #: Bit flags combined into :data:`ALIGN` (``LEFT``, ``TOP``, ``OUTER``, …).
|
|
45
|
+
TEXT_SIZE, #: Romfont heights: ``SMALL`` (8), ``MEDIUM`` (14), ``LARGE`` (16).
|
|
46
|
+
TEXT_WIDTH, #: Fixed romfont character width in pixels (8).
|
|
47
|
+
)
|
|
48
|
+
from ._themes import ColorTheme, IconTheme, get_palette, icon_theme
|
|
49
|
+
from .display import Display, tick
|
|
50
|
+
from .screen import Screen
|
|
51
|
+
from .task import Task
|
|
52
|
+
from .widget import Widget
|
|
53
|
+
|
|
54
|
+
DEBUG = False #: When ``True``, enable extra debug logging in pdwidgets.
|
|
55
|
+
MARK_UPDATES = False #: When ``True``, draw a colored border around flushed areas.
|
|
56
|
+
|
|
57
|
+
# Widget name -> (import path, attribute). Core names live above.
|
|
58
|
+
_LAZY = {
|
|
59
|
+
"Accordion": ("pdwidgets.widgets.accordion", "Accordion"),
|
|
60
|
+
"AppBar": ("pdwidgets.widgets.app_bar", "AppBar"),
|
|
61
|
+
"Badge": ("pdwidgets.widgets.badge", "Badge"),
|
|
62
|
+
"BottomSheet": ("pdwidgets.widgets.bottom_sheet", "BottomSheet"),
|
|
63
|
+
"Button": ("pdwidgets.widgets.button", "Button"),
|
|
64
|
+
"Card": ("pdwidgets.widgets.card", "Card"),
|
|
65
|
+
"Chart": ("pdwidgets.widgets.chart", "Chart"),
|
|
66
|
+
"CheckBox": ("pdwidgets.widgets.check_box", "CheckBox"),
|
|
67
|
+
"Chip": ("pdwidgets.widgets.chip", "Chip"),
|
|
68
|
+
"ColorPicker": ("pdwidgets.widgets.color_picker", "ColorPicker"),
|
|
69
|
+
"Column": ("pdwidgets.widgets.column", "Column"),
|
|
70
|
+
"DatePicker": ("pdwidgets.widgets.date_picker", "DatePicker"),
|
|
71
|
+
"Dialog": ("pdwidgets.widgets.dialog", "Dialog"),
|
|
72
|
+
"DigitalClock": ("pdwidgets.widgets.digital_clock", "DigitalClock"),
|
|
73
|
+
"Divider": ("pdwidgets.widgets.divider", "Divider"),
|
|
74
|
+
"Drawer": ("pdwidgets.widgets.drawer", "Drawer"),
|
|
75
|
+
"Dropdown": ("pdwidgets.widgets.dropdown", "Dropdown"),
|
|
76
|
+
"Form": ("pdwidgets.widgets.form", "Form"),
|
|
77
|
+
"FormRow": ("pdwidgets.widgets.form_row", "FormRow"),
|
|
78
|
+
"Gauge": ("pdwidgets.widgets.gauge", "Gauge"),
|
|
79
|
+
"Grid": ("pdwidgets.widgets.grid", "Grid"),
|
|
80
|
+
"Icon": ("pdwidgets.widgets.icon", "Icon"),
|
|
81
|
+
"IconButton": ("pdwidgets.widgets.icon_button", "IconButton"),
|
|
82
|
+
"Image": ("pdwidgets.widgets.image", "Image"),
|
|
83
|
+
"Keyboard": ("pdwidgets.widgets.keyboard", "Keyboard"),
|
|
84
|
+
"Label": ("pdwidgets.widgets.label", "Label"),
|
|
85
|
+
"ListView": ("pdwidgets.widgets.list_view", "ListView"),
|
|
86
|
+
"Menu": ("pdwidgets.widgets.menu", "Menu"),
|
|
87
|
+
"Navigator": ("pdwidgets.widgets.navigator", "Navigator"),
|
|
88
|
+
"NumberStepper": ("pdwidgets.widgets.number_stepper", "NumberStepper"),
|
|
89
|
+
"Page": ("pdwidgets.widgets.page", "Page"),
|
|
90
|
+
"PasswordField": ("pdwidgets.widgets.password_field", "PasswordField"),
|
|
91
|
+
"PinPad": ("pdwidgets.widgets.pin_pad", "PinPad"),
|
|
92
|
+
"ProgressBar": ("pdwidgets.widgets.progress_bar", "ProgressBar"),
|
|
93
|
+
"RadioButton": ("pdwidgets.widgets.radio_button", "RadioButton"),
|
|
94
|
+
"RadioGroup": ("pdwidgets.widgets.radio_group", "RadioGroup"),
|
|
95
|
+
"Row": ("pdwidgets.widgets.row", "Row"),
|
|
96
|
+
"ScrollBar": ("pdwidgets.widgets.scroll_bar", "ScrollBar"),
|
|
97
|
+
"ScrollView": ("pdwidgets.widgets.scroll_view", "ScrollView"),
|
|
98
|
+
"SegmentedControl": ("pdwidgets.widgets.segmented_control", "SegmentedControl"),
|
|
99
|
+
"Slider": ("pdwidgets.widgets.slider", "Slider"),
|
|
100
|
+
"Spinner": ("pdwidgets.widgets.spinner", "Spinner"),
|
|
101
|
+
"Switch": ("pdwidgets.widgets.switch", "Switch"),
|
|
102
|
+
"TabView": ("pdwidgets.widgets.tab_view", "TabView"),
|
|
103
|
+
"TextBox": ("pdwidgets.widgets.text_box", "TextBox"),
|
|
104
|
+
"TextInput": ("pdwidgets.widgets.text_input", "TextInput"),
|
|
105
|
+
"Toast": ("pdwidgets.widgets.toast", "Toast"),
|
|
106
|
+
"Toggle": ("pdwidgets.widgets.toggle", "Toggle"),
|
|
107
|
+
"ToggleButton": ("pdwidgets.widgets.toggle_button", "ToggleButton"),
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
__all__ = [
|
|
111
|
+
"ALIGN",
|
|
112
|
+
"DEBUG",
|
|
113
|
+
"DEFAULT_PADDING",
|
|
114
|
+
"ICON_SIZE",
|
|
115
|
+
"MARK_UPDATES",
|
|
116
|
+
"pct",
|
|
117
|
+
"PAD",
|
|
118
|
+
"POSITION",
|
|
119
|
+
"TEXT_SIZE",
|
|
120
|
+
"TEXT_WIDTH",
|
|
121
|
+
"Area",
|
|
122
|
+
"ColorTheme",
|
|
123
|
+
"Display",
|
|
124
|
+
"IconTheme",
|
|
125
|
+
"Screen",
|
|
126
|
+
"Task",
|
|
127
|
+
"Widget",
|
|
128
|
+
"events",
|
|
129
|
+
"get_palette",
|
|
130
|
+
"icon_theme",
|
|
131
|
+
"tick",
|
|
132
|
+
]
|
|
133
|
+
__all__ += list(_LAZY.keys())
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def __getattr__(name):
|
|
137
|
+
"""Lazily import a widget class listed in ``_LAZY``.
|
|
138
|
+
|
|
139
|
+
Args:
|
|
140
|
+
name: Public widget name (for example ``"Button"``).
|
|
141
|
+
|
|
142
|
+
Returns:
|
|
143
|
+
The resolved class or object.
|
|
144
|
+
|
|
145
|
+
Raises:
|
|
146
|
+
AttributeError: If ``name`` is not a known lazy export.
|
|
147
|
+
"""
|
|
148
|
+
spec = _LAZY.get(name)
|
|
149
|
+
if spec is None:
|
|
150
|
+
raise AttributeError(f"module 'pdwidgets' has no attribute {name!r}")
|
|
151
|
+
mod_path, attr = spec
|
|
152
|
+
mod = __import__(mod_path, None, None, [attr])
|
|
153
|
+
val = getattr(mod, attr)
|
|
154
|
+
globals()[name] = val
|
|
155
|
+
return val
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
def __dir__():
|
|
159
|
+
"""Return sorted public names including lazy widget exports."""
|
|
160
|
+
return sorted(set(__all__) | set(globals().keys()))
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Small compatibility helpers for Python hosts without ``micropython``."""
|
|
5
|
+
|
|
6
|
+
try:
|
|
7
|
+
from micropython import const
|
|
8
|
+
except ImportError:
|
|
9
|
+
|
|
10
|
+
def const(value):
|
|
11
|
+
return value
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""
|
|
5
|
+
Constants used by the pdwidgets library.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
from ._compat import const
|
|
9
|
+
|
|
10
|
+
PAD = const(2)
|
|
11
|
+
DEFAULT_PADDING = (PAD, PAD, PAD, PAD)
|
|
12
|
+
TEXT_WIDTH = const(8)
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
class _Constants:
|
|
16
|
+
"""
|
|
17
|
+
A base class for creating a struct-like class. The class may be used to check if a value is one of the built-in values, for instance:
|
|
18
|
+
```
|
|
19
|
+
CONSTANTS = _Constants()
|
|
20
|
+
if value in CONSTANTS:
|
|
21
|
+
print("Value is valid")
|
|
22
|
+
```
|
|
23
|
+
May also be used to iterate over the values:
|
|
24
|
+
```
|
|
25
|
+
CONSTANTS = _Constants()
|
|
26
|
+
for value in CONSTANTS:
|
|
27
|
+
print(value)
|
|
28
|
+
```
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
@classmethod
|
|
32
|
+
def __contains__(cls, item):
|
|
33
|
+
return item in cls.__dict__.values()
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def __iter__(cls):
|
|
37
|
+
return iter(cls.__dict__.values())
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
class _IconSize(_Constants):
|
|
41
|
+
SMALL = 18
|
|
42
|
+
MEDIUM = 24
|
|
43
|
+
LARGE = 36
|
|
44
|
+
XLARGE = 48
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
ICON_SIZE = _IconSize()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class _TextSize(_Constants):
|
|
51
|
+
SMALL = 8
|
|
52
|
+
MEDIUM = 14
|
|
53
|
+
LARGE = 16
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
TEXT_SIZE = _TextSize()
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
class _Position(_Constants):
|
|
60
|
+
LEFT = 1 << 0
|
|
61
|
+
RIGHT = 1 << 1
|
|
62
|
+
TOP = 1 << 2
|
|
63
|
+
BOTTOM = 1 << 3
|
|
64
|
+
OUTER = 1 << 4
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
POSITION = _Position()
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
class _Align(_Constants):
|
|
71
|
+
CENTER = 0 # 0
|
|
72
|
+
TOP_LEFT = POSITION.TOP | POSITION.LEFT # 5
|
|
73
|
+
TOP = POSITION.TOP # 4
|
|
74
|
+
TOP_RIGHT = POSITION.TOP | POSITION.RIGHT # 6
|
|
75
|
+
LEFT = POSITION.LEFT # 1
|
|
76
|
+
RIGHT = POSITION.RIGHT # 2
|
|
77
|
+
BOTTOM_LEFT = POSITION.BOTTOM | POSITION.LEFT # 9
|
|
78
|
+
BOTTOM = POSITION.BOTTOM # 8
|
|
79
|
+
BOTTOM_RIGHT = POSITION.BOTTOM | POSITION.RIGHT # 10
|
|
80
|
+
OUTER_TOP_LEFT = POSITION.TOP | POSITION.LEFT | POSITION.OUTER # 21
|
|
81
|
+
OUTER_TOP = POSITION.TOP | POSITION.OUTER # 20
|
|
82
|
+
OUTER_TOP_RIGHT = POSITION.TOP | POSITION.RIGHT | POSITION.OUTER # 22
|
|
83
|
+
OUTER_LEFT = POSITION.LEFT | POSITION.OUTER # 17
|
|
84
|
+
OUTER_RIGHT = POSITION.RIGHT | POSITION.OUTER # 18
|
|
85
|
+
OUTER_BOTTOM_LEFT = POSITION.BOTTOM | POSITION.LEFT | POSITION.OUTER # 25
|
|
86
|
+
OUTER_BOTTOM = POSITION.BOTTOM | POSITION.OUTER # 24
|
|
87
|
+
OUTER_BOTTOM_RIGHT = POSITION.BOTTOM | POSITION.RIGHT | POSITION.OUTER # 26
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
ALIGN = _Align()
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2024 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Keyboard focus ring for pdwidgets (Tab / Shift-Tab / arrows)."""
|
|
5
|
+
|
|
6
|
+
import events
|
|
7
|
+
import keys
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class FocusManager:
|
|
11
|
+
"""Tracks focusable widgets and moves focus without a pointer.
|
|
12
|
+
|
|
13
|
+
Pointer modality (:meth:`Widget.set_modal`) remains separate: it captures
|
|
14
|
+
mouse/touch only. FocusManager owns which field receives keystrokes.
|
|
15
|
+
"""
|
|
16
|
+
|
|
17
|
+
def __init__(self):
|
|
18
|
+
self._widgets = []
|
|
19
|
+
self._index = -1
|
|
20
|
+
|
|
21
|
+
@property
|
|
22
|
+
def focused(self):
|
|
23
|
+
if 0 <= self._index < len(self._widgets):
|
|
24
|
+
return self._widgets[self._index]
|
|
25
|
+
return None
|
|
26
|
+
|
|
27
|
+
def register(self, widget):
|
|
28
|
+
"""Add ``widget`` to the focus ring (idempotent)."""
|
|
29
|
+
if widget not in self._widgets:
|
|
30
|
+
self._widgets.append(widget)
|
|
31
|
+
|
|
32
|
+
def unregister(self, widget):
|
|
33
|
+
"""Remove ``widget`` from the focus ring."""
|
|
34
|
+
if widget in self._widgets:
|
|
35
|
+
i = self._widgets.index(widget)
|
|
36
|
+
self._widgets.remove(widget)
|
|
37
|
+
if self._index == i:
|
|
38
|
+
self._index = -1
|
|
39
|
+
if hasattr(widget, "focused"):
|
|
40
|
+
widget.focused = False
|
|
41
|
+
elif self._index > i:
|
|
42
|
+
self._index -= 1
|
|
43
|
+
|
|
44
|
+
def focus(self, widget):
|
|
45
|
+
"""Give keyboard focus to ``widget`` (must be registered)."""
|
|
46
|
+
if widget is None:
|
|
47
|
+
self.blur()
|
|
48
|
+
return
|
|
49
|
+
if widget not in self._widgets:
|
|
50
|
+
self.register(widget)
|
|
51
|
+
prev = self.focused
|
|
52
|
+
if prev is widget:
|
|
53
|
+
return
|
|
54
|
+
if prev is not None:
|
|
55
|
+
if hasattr(prev, "focused"):
|
|
56
|
+
prev.focused = False
|
|
57
|
+
if hasattr(prev, "invalidate"):
|
|
58
|
+
prev.invalidate()
|
|
59
|
+
self._index = self._widgets.index(widget)
|
|
60
|
+
if hasattr(widget, "focused"):
|
|
61
|
+
widget.focused = True
|
|
62
|
+
if hasattr(widget, "invalidate"):
|
|
63
|
+
widget.invalidate()
|
|
64
|
+
# Keep TextInput._focused in sync for soft-keyboard fallbacks.
|
|
65
|
+
try:
|
|
66
|
+
from .widgets.text_input import TextInput
|
|
67
|
+
|
|
68
|
+
TextInput._focused = widget if isinstance(widget, TextInput) else None
|
|
69
|
+
except ImportError:
|
|
70
|
+
pass
|
|
71
|
+
|
|
72
|
+
def blur(self):
|
|
73
|
+
"""Clear keyboard focus."""
|
|
74
|
+
prev = self.focused
|
|
75
|
+
self._index = -1
|
|
76
|
+
if prev is not None:
|
|
77
|
+
if hasattr(prev, "focused"):
|
|
78
|
+
prev.focused = False
|
|
79
|
+
if hasattr(prev, "invalidate"):
|
|
80
|
+
prev.invalidate()
|
|
81
|
+
try:
|
|
82
|
+
from .widgets.text_input import TextInput
|
|
83
|
+
|
|
84
|
+
TextInput._focused = None
|
|
85
|
+
except ImportError:
|
|
86
|
+
pass
|
|
87
|
+
|
|
88
|
+
def focus_next(self, reverse=False):
|
|
89
|
+
"""Move focus to the next (or previous) visible focusable widget."""
|
|
90
|
+
if not self._widgets:
|
|
91
|
+
return
|
|
92
|
+
n = len(self._widgets)
|
|
93
|
+
step = -1 if reverse else 1
|
|
94
|
+
start = self._index if self._index >= 0 else (0 if not reverse else n - 1)
|
|
95
|
+
for i in range(1, n + 1):
|
|
96
|
+
idx = (start + step * i) % n
|
|
97
|
+
w = self._widgets[idx]
|
|
98
|
+
if getattr(w, "visible", True):
|
|
99
|
+
self.focus(w)
|
|
100
|
+
return
|
|
101
|
+
|
|
102
|
+
def handle_key(self, event):
|
|
103
|
+
"""Handle Tab / arrows for focus movement.
|
|
104
|
+
|
|
105
|
+
Returns:
|
|
106
|
+
bool: ``True`` if the event was consumed as a focus-change key.
|
|
107
|
+
"""
|
|
108
|
+
if not self._widgets or event.type != events.KEYDOWN:
|
|
109
|
+
return False
|
|
110
|
+
key = event.key
|
|
111
|
+
mod = getattr(event, "mod", 0) or 0
|
|
112
|
+
shift = bool(mod & keys.KMOD_SHIFT)
|
|
113
|
+
if key == keys.K_TAB:
|
|
114
|
+
self.focus_next(reverse=shift)
|
|
115
|
+
return True
|
|
116
|
+
if key in (keys.K_DOWN, keys.K_RIGHT):
|
|
117
|
+
self.focus_next(reverse=False)
|
|
118
|
+
return True
|
|
119
|
+
if key in (keys.K_UP, keys.K_LEFT):
|
|
120
|
+
self.focus_next(reverse=True)
|
|
121
|
+
return True
|
|
122
|
+
return False
|