omnipython-applibs 0.1.2.dev16__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (143) hide show
  1. appkit/__init__.py +52 -0
  2. appkit/__init__.pyi +17 -0
  3. appkit/data.py +149 -0
  4. appkit/data.pyi +25 -0
  5. appkit/foreground.py +357 -0
  6. appkit/foreground.pyi +45 -0
  7. appkit/home.py +19 -0
  8. appkit/home.pyi +8 -0
  9. appkit/hover.py +59 -0
  10. appkit/hover.pyi +13 -0
  11. appkit/index.py +199 -0
  12. appkit/index.pyi +30 -0
  13. appkit/launcher.py +1075 -0
  14. appkit/launcher.pyi +96 -0
  15. appkit/manifest.py +75 -0
  16. appkit/manifest.pyi +8 -0
  17. appkit/net.py +167 -0
  18. appkit/net.pyi +34 -0
  19. appkit/places.py +202 -0
  20. appkit/places.pyi +39 -0
  21. appkit/py.typed +0 -0
  22. appkit/scope.py +636 -0
  23. appkit/scope.pyi +110 -0
  24. appkit/shell.py +121 -0
  25. appkit/shell.pyi +32 -0
  26. appkit/worker.py +409 -0
  27. appkit/worker.pyi +83 -0
  28. controlkit/__init__.py +19 -0
  29. controlkit/__init__.pyi +10 -0
  30. controlkit/_draw.py +88 -0
  31. controlkit/_safe.py +29 -0
  32. controlkit/dotmatrix.py +101 -0
  33. controlkit/dotmatrix.pyi +23 -0
  34. controlkit/encoder.py +297 -0
  35. controlkit/encoder.pyi +55 -0
  36. controlkit/font5x7.py +22 -0
  37. controlkit/font5x7.pyi +11 -0
  38. controlkit/lamp_button.py +92 -0
  39. controlkit/lamp_button.pyi +40 -0
  40. controlkit/meter.py +86 -0
  41. controlkit/meter.pyi +30 -0
  42. controlkit/mock.py +116 -0
  43. controlkit/mock.pyi +35 -0
  44. controlkit/pad_grid.py +113 -0
  45. controlkit/pad_grid.pyi +41 -0
  46. controlkit/py.typed +0 -0
  47. controlkit/slider.py +185 -0
  48. controlkit/slider.pyi +49 -0
  49. controlkit/sprites.py +279 -0
  50. controlkit/sprites.pyi +22 -0
  51. controlkit/theme.py +120 -0
  52. controlkit/theme.pyi +15 -0
  53. deskkit/__init__.py +74 -0
  54. deskkit/__init__.pyi +18 -0
  55. deskkit/forecast.py +261 -0
  56. deskkit/forecast.pyi +40 -0
  57. deskkit/localtime.py +215 -0
  58. deskkit/localtime.pyi +33 -0
  59. deskkit/py.typed +0 -0
  60. deskkit/shell.py +113 -0
  61. deskkit/shell.pyi +33 -0
  62. omnipython_applibs-0.1.2.dev16.dist-info/METADATA +90 -0
  63. omnipython_applibs-0.1.2.dev16.dist-info/RECORD +143 -0
  64. omnipython_applibs-0.1.2.dev16.dist-info/WHEEL +5 -0
  65. omnipython_applibs-0.1.2.dev16.dist-info/licenses/LICENSE +21 -0
  66. omnipython_applibs-0.1.2.dev16.dist-info/top_level.txt +9 -0
  67. programkit/__init__.py +27 -0
  68. programkit/__init__.pyi +8 -0
  69. programkit/board.py +56 -0
  70. programkit/board.pyi +20 -0
  71. programkit/press.py +63 -0
  72. programkit/press.pyi +17 -0
  73. programkit/py.typed +0 -0
  74. programkit/rows.py +149 -0
  75. programkit/rows.pyi +34 -0
  76. sayso/__init__.py +109 -0
  77. sayso/__init__.pyi +124 -0
  78. sayso/auth.py +811 -0
  79. sayso/auth.pyi +102 -0
  80. sayso/client.py +1286 -0
  81. sayso/client.pyi +138 -0
  82. sayso/keepalive.py +371 -0
  83. sayso/keepalive.pyi +53 -0
  84. sayso/local.py +85 -0
  85. sayso/local.pyi +28 -0
  86. sayso/object_specs.py +706 -0
  87. sayso/object_specs.pyi +8 -0
  88. sayso/objects.py +411 -0
  89. sayso/objects.pyi +854 -0
  90. sayso/py.typed +0 -0
  91. sayso/schema_coverage.py +210 -0
  92. sayso/schema_coverage.pyi +13 -0
  93. sayso/transport.py +426 -0
  94. sayso/transport.pyi +47 -0
  95. songmodel/__init__.py +30 -0
  96. songmodel/__init__.pyi +9 -0
  97. songmodel/link.py +189 -0
  98. songmodel/link.pyi +53 -0
  99. songmodel/model.py +238 -0
  100. songmodel/model.pyi +40 -0
  101. songmodel/page.html +225 -0
  102. songmodel/page_data.py +236 -0
  103. songmodel/page_data.pyi +6 -0
  104. songmodel/py.typed +0 -0
  105. soundmodule/__init__.py +7 -0
  106. soundmodule/__init__.pyi +6 -0
  107. soundmodule/engine.py +1001 -0
  108. soundmodule/engine.pyi +196 -0
  109. soundmodule/names.py +298 -0
  110. soundmodule/names.pyi +30 -0
  111. soundmodule/pipes.py +105 -0
  112. soundmodule/pipes.pyi +31 -0
  113. soundmodule/py.typed +0 -0
  114. soundmodule/run.py +249 -0
  115. soundmodule/run.pyi +49 -0
  116. spectrum/__init__.py +72 -0
  117. spectrum/__init__.pyi +30 -0
  118. spectrum/analyzer.py +231 -0
  119. spectrum/analyzer.pyi +67 -0
  120. spectrum/fake_music.py +201 -0
  121. spectrum/fake_music.pyi +36 -0
  122. spectrum/pump_levels.py +126 -0
  123. spectrum/pump_levels.pyi +46 -0
  124. spectrum/py.typed +0 -0
  125. spectrum/spectrum_view.py +403 -0
  126. spectrum/spectrum_view.pyi +80 -0
  127. touchkit/__init__.py +4 -0
  128. touchkit/__init__.pyi +4 -0
  129. touchkit/cam.py +146 -0
  130. touchkit/cam.pyi +35 -0
  131. touchkit/clock.py +18 -0
  132. touchkit/clock.pyi +6 -0
  133. touchkit/ecp.py +134 -0
  134. touchkit/ecp.pyi +28 -0
  135. touchkit/net.py +347 -0
  136. touchkit/net.pyi +27 -0
  137. touchkit/py.typed +0 -0
  138. touchkit/settings.py +85 -0
  139. touchkit/settings.pyi +17 -0
  140. touchkit/shell.py +268 -0
  141. touchkit/shell.pyi +42 -0
  142. touchkit/ui.py +167 -0
  143. touchkit/ui.pyi +53 -0
touchkit/shell.py ADDED
@@ -0,0 +1,268 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """touchkit.shell -- the board's chrome and launcher.
5
+
6
+ * `TouchShell` gives every app but Home a header: its title, and a
7
+ status line at the right (``scope.status``, see ``touchkit.ui.status``).
8
+ ``scope.root`` is the area below it. Its Home button sits at the header's
9
+ left, on LVGL's system layer, so it never presses an app's own widgets;
10
+ the board's BOOT button goes home too, through a pin interrupt.
11
+ * `TouchLauncher` keeps a short history of switches for System,
12
+ and takes the USB sound card off when the next app isn't one that plays
13
+ through it, so the PC goes back to its own speakers.
14
+
15
+ Work too heavy for a timer runs through appkit's ``scope.foreground()``,
16
+ and ``main.py`` ends in ``appkit.serve()``.
17
+ """
18
+
19
+ import gc
20
+
21
+ import lvgl as lv
22
+ import multimer
23
+ from multimer import ticks_diff, ticks_ms
24
+
25
+ from appkit import Launcher, Shell, foreground
26
+
27
+ from . import ui
28
+
29
+ #: How often LVGL reads the touch panel, in ms, unless an app asks otherwise.
30
+ TOUCH_MS = 33
31
+
32
+ launcher = None # the running launcher, once a TouchShell has been made for it
33
+ boot_presses = 0
34
+
35
+
36
+ # -- the launcher -------------------------------------------------------------
37
+
38
+
39
+ class TouchLauncher(Launcher):
40
+ """appkit's launcher, keeping the last switches."""
41
+
42
+ def __init__(self, *args, **kw):
43
+ Launcher.__init__(self, *args, **kw)
44
+ #: ``(app, how, ms, free bytes after the old app closed)``, newest last.
45
+ self.history = []
46
+
47
+ def switch(self, name):
48
+ how = Launcher.switch(self, name)
49
+ last = self.last or (how, None, None)
50
+ self.history.append((name, how, last[1], last[2]))
51
+ if len(self.history) > 50:
52
+ del self.history[0]
53
+ return how
54
+
55
+
56
+ # -- the shell ---------------------------------------------------------------------
57
+
58
+
59
+ def _set_launcher(running):
60
+ global launcher
61
+ launcher = running
62
+
63
+
64
+ class TouchShell(Shell):
65
+ """The board's look: a header with the app's title and a status line,
66
+ a Home button on the system layer, and BOOT going home."""
67
+
68
+ def __init__(self, launcher, *, data_root=None):
69
+ _set_launcher(launcher)
70
+ ui.apply_theme() # first: the Home button is made in Shell.__init__
71
+ Shell.__init__(self, launcher, data_root=data_root)
72
+ self.boot_pin = None
73
+ if launcher.home is not None:
74
+ self._boot_button()
75
+
76
+ def make_home_button(self):
77
+ b = lv.button(lv.layer_sys())
78
+ b.set_size(ui.HOME_W, ui.HEADER - 12)
79
+ b.set_pos(6, 6)
80
+ b.set_style_bg_color(lv.color_hex(0x2A3550), 0)
81
+ b.set_style_radius(12, 0)
82
+ lbl = lv.label(b)
83
+ lbl.set_text(lv.SYMBOL.HOME + " Home")
84
+ lbl.set_style_text_font(ui.font, 0)
85
+ lbl.center()
86
+ launcher = self.launcher
87
+ b.add_event_cb(lambda e: go(launcher.home), lv.EVENT.CLICKED, None)
88
+ return b
89
+
90
+ def _boot_button(self):
91
+ try:
92
+ import board_config as board
93
+
94
+ pin = board.boot_button # a lazy role: reading it may hand back a factory
95
+ from machine import Pin
96
+
97
+ if not hasattr(pin, "irq"):
98
+ pin = pin()
99
+ pin.irq(trigger=Pin.IRQ_FALLING, handler=_boot_irq)
100
+ self.boot_pin = pin
101
+ except AttributeError: # no boot_button role: Home is on the screen
102
+ self.boot_pin = None
103
+ except Exception as e: # the role is there but didn't come up
104
+ print("touchkit: no BOOT button: %r" % (e,))
105
+ self.boot_pin = None
106
+
107
+ def make_root(self, scope):
108
+ scr = scope.screen()
109
+ scr.set_style_bg_color(ui.BG, 0)
110
+ scr.set_style_text_font(ui.font, 0)
111
+ scr.set_style_text_color(ui.WHITE, 0)
112
+ scr.remove_flag(lv.obj.FLAG.SCROLLABLE)
113
+ if scope.name == self.launcher.home:
114
+ return scr # Home draws its own top bar
115
+ w, h = scr.get_width(), scr.get_height()
116
+ hdr = ui.plain(lv.obj(scr))
117
+ hdr.set_size(w, ui.HEADER)
118
+ hdr.set_style_bg_color(ui.PANEL, 0)
119
+ hdr.set_style_bg_opa(lv.OPA.COVER, 0)
120
+ title = self.launcher.info.get(scope.name, {}).get("title", scope.name)
121
+ # A narrow screen gets the smaller font, and a title that still
122
+ # doesn't fit ends in dots rather than running off the edge.
123
+ f = ui.big if w >= 480 else ui.font
124
+ t = ui.label(hdr, title, f, ui.ACCENT)
125
+ t.set_long_mode(lv.label.LONG_MODE.DOTS)
126
+ t.set_size(w - ui.HOME_W - 40, f.line_height)
127
+ t.align(lv.ALIGN.LEFT_MID, ui.HOME_W + 24, 0)
128
+ status = ui.label(hdr, "", ui.small, ui.MUTED)
129
+ status.align(lv.ALIGN.RIGHT_MID, -16, 0)
130
+ scope.header = hdr
131
+ scope.status = status
132
+ body = ui.plain(lv.obj(scr))
133
+ body.set_pos(0, ui.HEADER)
134
+ body.set_size(w, h - ui.HEADER)
135
+ return body
136
+
137
+
138
+ def go(name):
139
+ """Switch to app *name* after the current callback."""
140
+ if launcher is not None and launcher.current != name:
141
+ launcher.request(name)
142
+
143
+
144
+ _boot_at = 0
145
+
146
+
147
+ def _boot_go(_):
148
+ if launcher is not None:
149
+ go(launcher.home)
150
+
151
+
152
+ def _boot_irq(pin):
153
+ # A pin IRQ runs between bytecodes; switching from it would close an app
154
+ # in the middle of whatever it was doing, so the switch is scheduled.
155
+ global _boot_at, boot_presses
156
+ now = ticks_ms()
157
+ if ticks_diff(now, _boot_at) < 400:
158
+ return # contact bounce, or a second press mid-switch
159
+ _boot_at = now
160
+ boot_presses += 1
161
+ try:
162
+ multimer.schedule(_boot_go, None)
163
+ except RuntimeError:
164
+ pass # the schedule queue is full: the press is lost, press again
165
+
166
+
167
+ def redraw_home_button():
168
+ """Have LVGL redraw the Home button: for an app that draws straight into
169
+ the framebuffer under it."""
170
+ s = launcher.shell if launcher is not None else None
171
+ b = getattr(s, "home_button", None)
172
+ if b is not None:
173
+ b.invalidate()
174
+
175
+
176
+ def quiet_app_timers(app):
177
+ """Stop the App's own service and refresh timers: display_driver hands
178
+ presentation and input to LVGL, after which they fire and return at
179
+ once, 130 times a second, costing the foreground loop."""
180
+ for t in tuple(app.timers):
181
+ if t.name == "app.service" or str(t.name).startswith("refresh:"):
182
+ t.deinit()
183
+
184
+
185
+ # -- touch -----------------------------------------------------------------------------
186
+
187
+
188
+ def _pointer_indev():
189
+ from display_driver import app
190
+
191
+ for dev in app.devices:
192
+ ind = getattr(dev, "user_data", None)
193
+ if ind is not None and ind.get_type() == lv.INDEV_TYPE.POINTER:
194
+ return ind
195
+ return None
196
+
197
+
198
+ def touch_period(scope, ms):
199
+ """Have LVGL read the touch panel every *ms* while app *scope* is open.
200
+
201
+ A read costs about 0.8 ms and some garbage. An app whose audio stalls on
202
+ every collection that garbage forces can slow it, to 100 ms say.
203
+ """
204
+ ind = _pointer_indev()
205
+ if ind is None:
206
+ return
207
+ ind.get_read_timer().set_period(ms)
208
+ scope.on_close(lambda: ind.get_read_timer().set_period(TOUCH_MS))
209
+
210
+
211
+ # -- what's still running (System, and the switch tests) -------------------------------------
212
+
213
+
214
+ def heap_text():
215
+ n = launcher.switches if launcher is not None else 0
216
+ if not hasattr(gc, "mem_free"): # CPython counts no heap of its own
217
+ return "heap: this interpreter doesn't count it, %d switches" % (n,)
218
+ free = gc.mem_free()
219
+ return "heap free %.1f MB, in use %d KB, %d switches" % (free / 1e6, gc.mem_alloc() // 1024, n)
220
+
221
+
222
+ def audit():
223
+ """What the apps share and must leave as they found it: the audio pumps,
224
+ I2S, the USB host and its streams, the SD card, the foreground loop."""
225
+ out = {}
226
+ try:
227
+ import audiopump
228
+
229
+ out["audiopump"] = bool(audiopump.running())
230
+ except Exception as e:
231
+ out["audiopump"] = repr(e)
232
+ try:
233
+ import _audioif
234
+
235
+ out["i2s"] = _audioif.i2s_state()
236
+ except (ImportError, AttributeError):
237
+ out["i2s"] = None # no I2S port here: a desktop
238
+ except Exception as e:
239
+ out["i2s"] = repr(e)
240
+ try:
241
+ from audiodev import pump
242
+
243
+ h = pump.health() or {}
244
+ out["pump_clients"] = h.get("clients")
245
+ out["pump_running"] = h.get("running")
246
+ except Exception as e:
247
+ out["pump"] = repr(e)
248
+ try:
249
+ import usb.core
250
+
251
+ # find() would start the host, which an audit must not do: count only
252
+ # when something already has. usb.core has no public "is it running".
253
+ running = getattr(usb.core, "_started", None) is not None
254
+ out["host_devices"] = len(list(usb.core.find(find_all=True))) if running else None
255
+ except Exception as e:
256
+ out["usb"] = repr(e)
257
+ try:
258
+ import os
259
+
260
+ os.stat("/sd")
261
+ out["sd"] = "mounted"
262
+ except OSError:
263
+ out["sd"] = None
264
+ out["foreground"] = foreground.current() is not None
265
+ scope = launcher.scope if launcher is not None else None
266
+ out["timers"] = len(scope.timers) if scope is not None else None
267
+ out["free"] = gc.mem_free() if hasattr(gc, "mem_free") else None
268
+ return out
touchkit/shell.pyi ADDED
@@ -0,0 +1,42 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The board's chrome and launcher."""
5
+
6
+ from typing import Any, Literal
7
+
8
+ from appkit import Launcher, Shell
9
+ from appkit.scope import AppScope
10
+
11
+ from . import ui as ui
12
+
13
+ TOUCH_MS: int
14
+ launcher: Launcher | None
15
+ boot_presses: int
16
+
17
+ class TouchLauncher(Launcher):
18
+ """appkit's launcher, keeping the last switches."""
19
+
20
+ history: list[tuple[str, str, int | None, int | None]]
21
+ def __init__(self, *args: Any, **kw: Any) -> None: ...
22
+ def switch(self, name: str) -> Literal["start", "switch", "restart"]: ...
23
+
24
+ class TouchShell(Shell):
25
+ """The board's look: a header with the app's title and a status line, a Home button, and BOOT going home."""
26
+
27
+ boot_pin: Any
28
+ def __init__(self, launcher: Launcher, *, data_root: str | None = None) -> None: ...
29
+ def make_home_button(self) -> Any: ...
30
+ def make_root(self, scope: AppScope) -> Any: ...
31
+
32
+ def go(name: str) -> None:
33
+ """Switch to app `name` after the current callback."""
34
+ def redraw_home_button() -> None:
35
+ """Have LVGL redraw the Home button."""
36
+ def quiet_app_timers(app: Any) -> None:
37
+ """Stop the App's own service and refresh timers."""
38
+ def touch_period(scope: AppScope, ms: int) -> None:
39
+ """Have LVGL read the touch panel every `ms` while app `scope` is open."""
40
+ def heap_text() -> str: ...
41
+ def audit() -> dict[str, Any]:
42
+ """What the apps share and must leave as they found it."""
touchkit/ui.py ADDED
@@ -0,0 +1,167 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """touchkit.ui -- the board's look, and the few widgets its apps build from.
5
+
6
+ The colours and fonts are here so an app can use them without the shell;
7
+ `apply_theme` puts them on the display, once, at boot.
8
+ """
9
+
10
+ import lvgl as lv
11
+
12
+ HEADER = 64 # the top bar every app but Home has
13
+ HOME_W = 128 # the Home button, at the header's left
14
+
15
+
16
+ def _font(*sizes):
17
+ for s in sizes:
18
+ f = getattr(lv, "font_montserrat_%d" % s, None)
19
+ if f is not None:
20
+ return f
21
+ return lv.font_default()
22
+
23
+
24
+ font = _font(20, 18, 16)
25
+ small = _font(16, 14)
26
+ tiny = _font(14, 12) # captions and eyebrows over a block of controls
27
+ big = _font(28, 26, 24, 22)
28
+ huge = _font(48, 40, 36, 32, 28)
29
+
30
+ BG = lv.color_hex(0x0B0E14)
31
+ PANEL = lv.color_hex(0x1A2030)
32
+ KEY = lv.color_hex(0x2A3550) # a secondary button: the Home button's grey
33
+ ACCENT = lv.palette_main(lv.PALETTE.TEAL)
34
+ WARN = lv.palette_main(lv.PALETTE.AMBER)
35
+ BAD = lv.palette_main(lv.PALETTE.RED)
36
+ GOOD = lv.palette_main(lv.PALETTE.GREEN)
37
+ MUTED = lv.palette_main(lv.PALETTE.GREY)
38
+ WHITE = lv.color_hex(0xFFFFFF)
39
+
40
+
41
+ def apply_theme():
42
+ """The dark theme in the board's colours, on the default display."""
43
+ disp = lv.display_get_default()
44
+ try:
45
+ disp.set_theme(lv.theme_default_init(disp, ACCENT, WARN, True, font))
46
+ except AttributeError:
47
+ pass
48
+ lv.screen_active().set_style_bg_color(BG, 0)
49
+
50
+
51
+ def plain(obj):
52
+ """*obj* with no style of its own and no scrolling: a bare area."""
53
+ obj.remove_style_all()
54
+ obj.remove_flag(lv.obj.FLAG.SCROLLABLE)
55
+ return obj
56
+
57
+
58
+ def status(scope):
59
+ """The app's status line: the right end of the shell's header, or a
60
+ label at the top right of ``scope.root`` without one."""
61
+ lbl = getattr(scope, "status", None)
62
+ if lbl is None:
63
+ lbl = label(scope.root, "", small, MUTED)
64
+ lbl.align(lv.ALIGN.TOP_RIGHT, -16, 8)
65
+ return lbl
66
+
67
+
68
+ def missing(scope, short, text):
69
+ """An app that can't run here: *short* on the status line and *text* in
70
+ the middle of the screen, saying which module or hardware is lacking.
71
+ Home and BOOT go back as usual."""
72
+ status(scope).set_text(short)
73
+ msg = label(scope.root, text, font, WHITE)
74
+ msg.set_width(scope.size[0] - 48)
75
+ msg.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
76
+ msg.align(lv.ALIGN.CENTER, 0, 0)
77
+ return msg
78
+
79
+
80
+ def label(parent, text="", font=None, color=None):
81
+ lbl = lv.label(parent)
82
+ lbl.set_text(text)
83
+ if font is not None:
84
+ lbl.set_style_text_font(font, 0)
85
+ if color is not None:
86
+ lbl.set_style_text_color(color, 0)
87
+ return lbl
88
+
89
+
90
+ def button(parent, text, cb, w=None, h=None, font=None, color=None):
91
+ """A button that calls ``cb()`` when tapped. Returns ``(button, label)``."""
92
+ b = lv.button(parent)
93
+ if w:
94
+ b.set_width(w)
95
+ if h:
96
+ b.set_height(h)
97
+ if color is not None:
98
+ b.set_style_bg_color(color, 0)
99
+ b.set_style_radius(14, 0)
100
+ lbl = lv.label(b)
101
+ lbl.set_text(text)
102
+ lbl.set_style_text_font(font or globals()["font"], 0)
103
+ lbl.center()
104
+
105
+ def clicked(e):
106
+ cb()
107
+
108
+ b.add_event_cb(clicked, lv.EVENT.CLICKED, None)
109
+ return b, lbl
110
+
111
+
112
+ def box(parent, x, y, w, h, color=None):
113
+ """A plain rectangle (a card or a panel) at a fixed place."""
114
+ o = lv.obj(parent)
115
+ o.set_pos(x, y)
116
+ o.set_size(w, h)
117
+ o.set_style_bg_color(color or PANEL, 0)
118
+ o.set_style_border_width(0, 0)
119
+ o.set_style_radius(14, 0)
120
+ o.set_style_pad_all(10, 0)
121
+ o.remove_flag(lv.obj.FLAG.SCROLLABLE)
122
+ return o
123
+
124
+
125
+ def frame(parent, x, y, w, h):
126
+ """A thin border round a picture drawn straight into the framebuffer."""
127
+ f = lv.obj(parent)
128
+ f.remove_style_all()
129
+ f.set_pos(x - 2, y - 2)
130
+ f.set_size(w + 4, h + 4)
131
+ f.set_style_border_width(2, 0)
132
+ f.set_style_border_color(PANEL, 0)
133
+ return f
134
+
135
+
136
+ def rgb565_image(img, pixels, w, h, keep):
137
+ """Show *pixels* (RGB565, *w* x *h*) in LVGL image *img*. LVGL keeps a
138
+ pointer, not a reference: *keep* is a dict that holds the buffer for
139
+ as long as it shows."""
140
+ dsc = lv.image_dsc_t()
141
+ dsc.header.magic = lv.IMAGE_HEADER_MAGIC
142
+ dsc.header.cf = lv.COLOR_FORMAT.RGB565
143
+ dsc.header.w = w
144
+ dsc.header.h = h
145
+ dsc.header.stride = w * 2
146
+ dsc.data_size = len(pixels)
147
+ dsc.data = pixels
148
+ keep[id(img)] = (dsc, pixels)
149
+ img.set_src(dsc)
150
+
151
+
152
+ def decode_jpeg(data, max_w, max_h=None):
153
+ """``(pixels, w, h)``: JPEG *data* decoded to RGB565 on the P4's
154
+ decoder, scaled down by halves until it fits *max_w* x *max_h*."""
155
+ import jpegio
156
+
157
+ if max_h is None:
158
+ max_h = max_w
159
+ dec = jpegio.JpegDecoder()
160
+ w, h = dec.open(data)
161
+ scale = 0
162
+ while ((w >> scale) > max_w or (h >> scale) > max_h) and scale < 3:
163
+ scale += 1
164
+ w, h = w >> scale, h >> scale
165
+ px = bytearray(w * h * 2)
166
+ dec.decode(px, scale)
167
+ return px, w, h
touchkit/ui.pyi ADDED
@@ -0,0 +1,53 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """The board's look, and the few widgets its apps build from."""
5
+
6
+ from typing import Any, Callable
7
+
8
+ from appkit.scope import AppScope
9
+
10
+ HEADER: int
11
+ HOME_W: int
12
+ font: Any
13
+ small: Any
14
+ tiny: Any
15
+ big: Any
16
+ huge: Any
17
+ BG: Any
18
+ PANEL: Any
19
+ KEY: Any
20
+ ACCENT: Any
21
+ WARN: Any
22
+ BAD: Any
23
+ GOOD: Any
24
+ MUTED: Any
25
+ WHITE: Any
26
+
27
+ def apply_theme() -> None:
28
+ """The dark theme in the board's colours, on the default display."""
29
+ def plain(obj: Any) -> Any:
30
+ """`obj` with no style of its own and no scrolling: a bare area."""
31
+ def status(scope: AppScope) -> Any:
32
+ """The app's status line label."""
33
+ def missing(scope: AppScope, short: str, text: str) -> Any:
34
+ """Say an app can't run here: `short` on the status line and `text` in the middle."""
35
+ def label(parent: Any, text: str = "", font: Any = None, color: Any = None) -> Any: ...
36
+ def button(
37
+ parent: Any,
38
+ text: str,
39
+ cb: Callable[[], Any],
40
+ w: int | None = None,
41
+ h: int | None = None,
42
+ font: Any = None,
43
+ color: Any = None,
44
+ ) -> tuple[Any, Any]:
45
+ """A button that calls `cb()` when tapped. Returns `(button, label)`."""
46
+ def box(parent: Any, x: int, y: int, w: int, h: int, color: Any = None) -> Any:
47
+ """A plain rectangle (a card or a panel) at a fixed place."""
48
+ def frame(parent: Any, x: int, y: int, w: int, h: int) -> Any:
49
+ """A thin border round a picture drawn straight into the framebuffer."""
50
+ def rgb565_image(img: Any, pixels: bytearray | bytes, w: int, h: int, keep: dict[int, Any]) -> None:
51
+ """Show `pixels` (RGB565, `w` x `h`) in LVGL image `img`; `keep` holds the buffer for as long as it shows."""
52
+ def decode_jpeg(data: bytes | bytearray | memoryview, max_w: int, max_h: int | None = None) -> tuple[bytearray, int, int]:
53
+ """`(pixels, w, h)`: JPEG `data` decoded to RGB565, scaled down by halves to fit."""