omnipython-apps 0.1.4.dev8__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 (218) hide show
  1. apps/__init__.py +5 -0
  2. apps/about/__init__.py +257 -0
  3. apps/about/app.json +1 -0
  4. apps/about/credits.py +12 -0
  5. apps/about/facts.py +398 -0
  6. apps/about/fonts/OFL.txt +93 -0
  7. apps/about/fonts/latin1_14.bin +0 -0
  8. apps/about/fonts/latin1_16.bin +0 -0
  9. apps/about/fonts/latin1_24.bin +0 -0
  10. apps/about/fonts/latin1_32.bin +0 -0
  11. apps/about/fonts/latin1_40.bin +0 -0
  12. apps/backline/__init__.py +58 -0
  13. apps/backline/app.json +1 -0
  14. apps/backline/app.py +475 -0
  15. apps/backline/art.py +717 -0
  16. apps/backline/ask.py +781 -0
  17. apps/backline/box.py +502 -0
  18. apps/backline/cast.py +137 -0
  19. apps/backline/desk/__init__.py +329 -0
  20. apps/backline/desk/editor.py +331 -0
  21. apps/backline/desk/grid.py +154 -0
  22. apps/backline/desk/look.py +169 -0
  23. apps/backline/desk/pedals.py +102 -0
  24. apps/backline/desk/perform.py +157 -0
  25. apps/backline/desk/prompt.py +210 -0
  26. apps/backline/desk/strip.py +159 -0
  27. apps/backline/desk_main.py +226 -0
  28. apps/backline/engine.py +622 -0
  29. apps/backline/floor.py +509 -0
  30. apps/backline/footswitch.py +119 -0
  31. apps/backline/glyphs.py +82 -0
  32. apps/backline/kits.py +428 -0
  33. apps/backline/midipedal.py +362 -0
  34. apps/backline/page_data.py +413 -0
  35. apps/backline/parts.py +145 -0
  36. apps/backline/pedal.py +107 -0
  37. apps/backline/remote.py +134 -0
  38. apps/backline/songs/ballad_68.json +1 -0
  39. apps/backline/songs/bossa.json +1 -0
  40. apps/backline/songs/country_train.json +1 -0
  41. apps/backline/songs/funk.json +1 -0
  42. apps/backline/songs/metal.json +1 -0
  43. apps/backline/songs/pop.json +1 -0
  44. apps/backline/songs/rock.json +1 -0
  45. apps/backline/songs/shuffle.json +1 -0
  46. apps/battery/__init__.py +101 -0
  47. apps/battery/app.json +1 -0
  48. apps/bit_world/act_deck.py +683 -0
  49. apps/bit_world/act_game.py +762 -0
  50. apps/bit_world/act_pet.py +1032 -0
  51. apps/bit_world/app.json +1 -0
  52. apps/bit_world/bit_output.py +45 -0
  53. apps/bit_world/bit_palette.py +503 -0
  54. apps/bit_world/bit_sound.py +431 -0
  55. apps/bit_world/bit_sprites.py +632 -0
  56. apps/bit_world/bit_world.py +534 -0
  57. apps/btreceiver/__init__.py +690 -0
  58. apps/btreceiver/app.json +1 -0
  59. apps/btreceiver/chime.py +155 -0
  60. apps/btreceiver/demo.py +529 -0
  61. apps/btreceiver/screen.py +633 -0
  62. apps/camera/__init__.py +316 -0
  63. apps/camera/app.json +1 -0
  64. apps/card/__init__.py +113 -0
  65. apps/card/app.json +1 -0
  66. apps/cast/__init__.py +631 -0
  67. apps/cast/app.json +1 -0
  68. apps/cast/receivers.py +193 -0
  69. apps/chess/__init__.py +18 -0
  70. apps/chess/app.json +1 -0
  71. apps/chess/app.py +922 -0
  72. apps/chess/art.py +323 -0
  73. apps/chess/ble.py +411 -0
  74. apps/chess/engine.py +925 -0
  75. apps/chess/game.py +327 -0
  76. apps/chess/net.py +261 -0
  77. apps/clock/__init__.py +38 -0
  78. apps/clock/app.json +1 -0
  79. apps/detect/__init__.py +214 -0
  80. apps/detect/app.json +1 -0
  81. apps/fmsynth/__init__.py +41 -0
  82. apps/fmsynth/algorithms.py +61 -0
  83. apps/fmsynth/app.json +1 -0
  84. apps/fmsynth/app.py +355 -0
  85. apps/fmsynth/editor.py +206 -0
  86. apps/fmsynth/engine.py +257 -0
  87. apps/fmsynth/meters.py +262 -0
  88. apps/fmsynth/midi.py +375 -0
  89. apps/fmsynth/panel_view.py +1071 -0
  90. apps/fmsynth/patches/fmsynth-01.syx +0 -0
  91. apps/fmsynth/settings.py +138 -0
  92. apps/fmsynth/voice.py +398 -0
  93. apps/gamepad/__init__.py +685 -0
  94. apps/gamepad/app.json +1 -0
  95. apps/gamepad/pad.py +94 -0
  96. apps/gamepad/watch.py +352 -0
  97. apps/hidden/__init__.py +72 -0
  98. apps/hidden/app.json +1 -0
  99. apps/home/__init__.py +483 -0
  100. apps/home/app.json +1 -0
  101. apps/home/main.py +36 -0
  102. apps/homeassistant/__init__.py +213 -0
  103. apps/homeassistant/api.py +104 -0
  104. apps/homeassistant/app.json +1 -0
  105. apps/huey/__init__.py +287 -0
  106. apps/huey/acting.py +184 -0
  107. apps/huey/actor.py +194 -0
  108. apps/huey/app.json +1 -0
  109. apps/huey/client.py +125 -0
  110. apps/huey/servers.py +121 -0
  111. apps/huey/settings.example.json +8 -0
  112. apps/huey/settings.py +97 -0
  113. apps/huey/turn.py +504 -0
  114. apps/huey/voice.py +217 -0
  115. apps/info/__init__.py +810 -0
  116. apps/info/app.json +1 -0
  117. apps/lora/__init__.py +62 -0
  118. apps/lora/app.json +1 -0
  119. apps/manifest.py +71 -0
  120. apps/medialink_baby_monitor/__init__.py +222 -0
  121. apps/medialink_baby_monitor/app.json +1 -0
  122. apps/medialink_doorbell/__init__.py +251 -0
  123. apps/medialink_doorbell/app.json +1 -0
  124. apps/medialink_hands_free/__init__.py +217 -0
  125. apps/medialink_hands_free/app.json +1 -0
  126. apps/medialink_surveillance_camera/__init__.py +258 -0
  127. apps/medialink_surveillance_camera/app.json +1 -0
  128. apps/medialink_video_doorbell/__init__.py +289 -0
  129. apps/medialink_video_doorbell/app.json +1 -0
  130. apps/medialink_videophone/__init__.py +273 -0
  131. apps/medialink_videophone/app.json +1 -0
  132. apps/medialink_walkie_talkie/__init__.py +228 -0
  133. apps/medialink_walkie_talkie/app.json +1 -0
  134. apps/midicontroller/__init__.py +774 -0
  135. apps/midicontroller/app.json +1 -0
  136. apps/midicontroller/links.py +421 -0
  137. apps/midicontroller/surface.py +343 -0
  138. apps/midiengine/__init__.py +977 -0
  139. apps/midiengine/app.json +1 -0
  140. apps/midiengine/banks.py +85 -0
  141. apps/midiengine/midiin.py +165 -0
  142. apps/midiengine/player.py +392 -0
  143. apps/midiengine/umidiparser.py +1413 -0
  144. apps/mp3/__init__.py +240 -0
  145. apps/mp3/app.json +1 -0
  146. apps/perch/__init__.py +119 -0
  147. apps/perch/app.json +1 -0
  148. apps/perch/huey.py +481 -0
  149. apps/perch/huey_props.py +386 -0
  150. apps/perch/huey_shift.py +42 -0
  151. apps/perch/huey_views.py +296 -0
  152. apps/perch/scene_bench.py +680 -0
  153. apps/perch/scene_coast.py +479 -0
  154. apps/perch/scene_desk.py +492 -0
  155. apps/perch/stage.py +1274 -0
  156. apps/perch/vec.py +366 -0
  157. apps/repl/__init__.py +325 -0
  158. apps/repl/app.json +1 -0
  159. apps/roku/__init__.py +156 -0
  160. apps/roku/app.json +1 -0
  161. apps/rokucam/__init__.py +362 -0
  162. apps/rokucam/app.json +1 -0
  163. apps/security/__init__.py +261 -0
  164. apps/security/app.json +1 -0
  165. apps/settings/__init__.py +221 -0
  166. apps/settings/app.json +1 -0
  167. apps/shell/__init__.py +33 -0
  168. apps/shell/app.json +1 -0
  169. apps/spotify/__init__.py +669 -0
  170. apps/spotify/app.json +1 -0
  171. apps/spotify/screen.py +82 -0
  172. apps/steps/__init__.py +58 -0
  173. apps/steps/app.json +1 -0
  174. apps/stompbox/__init__.py +31 -0
  175. apps/stompbox/app.json +1 -0
  176. apps/stompbox/app.py +668 -0
  177. apps/stompbox/boards.json +20 -0
  178. apps/stompbox/effects.py +241 -0
  179. apps/stompbox/engine.py +340 -0
  180. apps/stompbox/footswitch.py +331 -0
  181. apps/stompbox/inputs.py +449 -0
  182. apps/stompbox/meter.py +72 -0
  183. apps/stompbox/outputs.py +135 -0
  184. apps/stompbox/pedals.txt +45 -0
  185. apps/stompbox/presets.py +106 -0
  186. apps/stompbox/styles.py +135 -0
  187. apps/stompbox/ui.py +817 -0
  188. apps/stompbox/wavfile.py +73 -0
  189. apps/synthstation/__init__.py +20 -0
  190. apps/synthstation/app.json +1 -0
  191. apps/synthstation/audio.py +397 -0
  192. apps/synthstation/catalog.py +50 -0
  193. apps/synthstation/meters.py +136 -0
  194. apps/synthstation/midi.py +380 -0
  195. apps/synthstation/pads.py +177 -0
  196. apps/synthstation/parts.py +128 -0
  197. apps/synthstation/station.py +1069 -0
  198. apps/system/__init__.py +11 -0
  199. apps/system/app.json +1 -0
  200. apps/touchcal/__init__.py +324 -0
  201. apps/touchcal/app.json +1 -0
  202. apps/touchcal/fit.py +262 -0
  203. apps/wake/__init__.py +268 -0
  204. apps/wake/app.json +1 -0
  205. apps/wake/feed.py +155 -0
  206. apps/watch/__init__.py +355 -0
  207. apps/watch/app.json +1 -0
  208. apps/watch/faces.py +35 -0
  209. apps/watch/wheel.py +157 -0
  210. apps/weather/__init__.py +278 -0
  211. apps/weather/app.json +1 -0
  212. apps/weather/icons.py +172 -0
  213. apps/weather/sizing.py +71 -0
  214. apps/weather/zippad.py +172 -0
  215. omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
  216. omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
  217. omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
  218. omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
apps/watch/__init__.py ADDED
@@ -0,0 +1,355 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Watch: a home screen for round and small screens, a watch face first.
5
+
6
+ It opens on a watch face, with the date, the battery where the board has
7
+ one, today's steps where it counts them, and whether it's on the network, on
8
+ a line under the hands. In a browser page that line is left out: a page has
9
+ no battery, steps or network of its own to show. Swipe left or right for another face; the one you
10
+ pick is kept across restarts. A tap, or a swipe up, opens the wheel of
11
+ apps (`wheel`); a tap on the time at the top of the wheel, a swipe
12
+ sideways, or a few idle seconds go back to the face. The apps are those
13
+ Home shows, in the order of its tabs: each app's ``app.json`` says what
14
+ it is, as for Home, and an app Home hides stays off the wheel too.
15
+
16
+ Every app comes back here through the Shell's Home button. The faces are
17
+ a hybrid face with the time in digits too, first, and Clock's analog clock
18
+ in each of its skins (`faces`).
19
+
20
+ A board's ``main.py`` makes it the home screen with
21
+ ``TouchLauncher(app, home="watch")``; Home's own ``main.py`` does that by
22
+ itself on a round screen or a small one (see ``appkit.shell.is_small``).
23
+ """
24
+
25
+ import json
26
+ import sys
27
+
28
+ import lvgl as lv
29
+ from deskkit import localtime
30
+
31
+ from appkit.bar import battery_percent, board_battery
32
+ from appkit import launcher as running
33
+ from appkit.shell import is_round
34
+ from touchkit import ui
35
+
36
+ from . import faces
37
+ from .wheel import Wheel
38
+
39
+ DEFAULT_COLOR = "#44505E"
40
+ WHEEL_IDLE_MS = 8000 # the wheel goes back to the face after this long untouched
41
+ GLANCE_MS = 5000 # how often the line under the face is read again
42
+ TICK_MS = 250
43
+ _WEEKDAYS = ("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun")
44
+ _MONTHS = ("Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec")
45
+
46
+
47
+ def in_order(info, hidden=()):
48
+ """``[(name, title, category, icon, colour), ...]``: the apps Home puts
49
+ on its tabs, in the same order, from each app's ``app.json``. An app
50
+ with no icon gets the "apps" icon rather than stopping the wheel."""
51
+ by_category = {}
52
+ for name in sorted(info):
53
+ entry = info[name]
54
+ if not entry.get("tile", True) or name in hidden:
55
+ continue
56
+ category = entry.get("category") or "More"
57
+ color = int(entry.get("color", DEFAULT_COLOR)[1:], 16)
58
+ tile = (name, entry.get("title", name), category, entry.get("icon") or "apps", color)
59
+ by_category.setdefault(category, []).append(tile)
60
+ order = sorted(c for c in by_category if c != "More")
61
+ if "More" in by_category:
62
+ order.append("More")
63
+ return [tile for c in order for tile in by_category[c]]
64
+
65
+
66
+ def _role(name):
67
+ """The board's role *name*, or None where it hasn't one or it fails."""
68
+ board = sys.modules.get("board_config")
69
+ if board is None or name not in getattr(board, "PERIPHERALS", ()):
70
+ return None
71
+ try:
72
+ return getattr(board, name)
73
+ except Exception:
74
+ return None
75
+
76
+
77
+ def _battery():
78
+ try:
79
+ return board_battery()
80
+ except Exception:
81
+ return None
82
+
83
+
84
+ def battery_text(battery):
85
+ """``"82%"``, with ``" charging"`` while it charges, as the status bar
86
+ reads it, or None with no reading."""
87
+ if battery is None:
88
+ return None
89
+ try:
90
+ pct = battery_percent(battery)
91
+ charging = getattr(battery, "charging", False)
92
+ except Exception:
93
+ return None
94
+ if pct is None:
95
+ return None
96
+ return "%d%%%s" % (pct, " charging" if charging else "")
97
+
98
+
99
+ def steps_text(accel):
100
+ """``"1234 steps"`` where the accelerometer counts steps, else None."""
101
+ if accel is None or not hasattr(accel, "steps"):
102
+ return None
103
+ try:
104
+ if not getattr(accel, "features_running", True):
105
+ return None
106
+ return "%d steps" % accel.steps
107
+ except Exception:
108
+ return None
109
+
110
+
111
+ def network_text():
112
+ """``"online"`` or ``"offline"``, from the board's network."""
113
+ from touchkit import net
114
+
115
+ return "online" if net.ip() else "offline"
116
+
117
+
118
+ def shows_glances():
119
+ """False in a browser page, where the line under the face has nothing of
120
+ the board's to say."""
121
+ return running.host() != "browser"
122
+
123
+
124
+ def glances(date=True):
125
+ """The line under the face: the date unless the face shows it, then
126
+ whatever the board can tell."""
127
+ t = localtime.now()
128
+ parts = ["%s %d %s" % (_WEEKDAYS[t[6] % 7], t[2], _MONTHS[(t[1] - 1) % 12])] if date else []
129
+ for text in (battery_text(_battery()), steps_text(_role("accelerometer")), network_text()):
130
+ if text:
131
+ parts.append(text)
132
+ return " ".join(parts)
133
+
134
+
135
+ def _face_path(scope):
136
+ return scope.data_dir + "/face.json"
137
+
138
+
139
+ def _load_face(scope):
140
+ try:
141
+ with open(_face_path(scope)) as f:
142
+ return json.load(f).get("face", faces.DEFAULT)
143
+ except (OSError, ValueError):
144
+ return faces.DEFAULT
145
+
146
+
147
+ def _save_face(scope, name):
148
+ try:
149
+ with open(_face_path(scope), "w") as f:
150
+ json.dump({"face": name}, f)
151
+ except OSError as e:
152
+ print("watch: the face wasn't saved: %r" % (e,))
153
+
154
+
155
+ def _catcher(parent, w, h):
156
+ """A clear, clickable layer over the whole screen."""
157
+ o = lv.obj(parent)
158
+ o.remove_style_all()
159
+ o.set_size(w, h)
160
+ o.remove_flag(lv.obj.FLAG.SCROLLABLE)
161
+ o.add_flag(lv.obj.FLAG.CLICKABLE)
162
+ o.remove_flag(lv.obj.FLAG.GESTURE_BUBBLE) # its swipes are its own
163
+ return o
164
+
165
+
166
+ def main(scope):
167
+ root = scope.root
168
+ W, H = scope.size
169
+ root.remove_flag(lv.obj.FLAG.SCROLLABLE)
170
+ root.set_style_bg_color(lv.color_hex(0x000000), 0)
171
+ root.set_style_bg_opa(lv.OPA.COVER, 0)
172
+ kept = scope.store()
173
+ side = min(W, H)
174
+ state = {"face": None, "name": _load_face(scope), "swiped": False, "glance_at": 0, "opened": 0}
175
+
176
+ # -- the face --
177
+ face_view = lv.obj(root)
178
+ face_view.remove_style_all()
179
+ face_view.set_size(W, H)
180
+ face_view.remove_flag(lv.obj.FLAG.SCROLLABLE)
181
+ dial = lv.obj(face_view)
182
+ dial.remove_style_all()
183
+ dial.set_size(side, side)
184
+ dial.center()
185
+ dial.remove_flag(lv.obj.FLAG.SCROLLABLE)
186
+ line = ui.label(face_view, "", ui.tiny, ui.WHITE)
187
+ line.set_style_bg_color(lv.color_hex(0x000000), 0)
188
+ line.set_style_bg_opa(lv.OPA._60, 0)
189
+ line.set_style_pad_hor(8, 0)
190
+ line.set_style_pad_ver(2, 0)
191
+ line.set_style_radius(8, 0)
192
+ line.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
193
+ line.set_long_mode(lv.label.LONG_MODE.DOTS)
194
+ catch = _catcher(face_view, W, H)
195
+
196
+ def place():
197
+ """Put the line where the current face leaves room for it, inside
198
+ the circle on a round screen: the lower fifth, or on the hybrid
199
+ face, which has the date in a window and VI near the bottom, one
200
+ line under its name."""
201
+ hybrid = state["name"] == faces.HYBRID
202
+ row = ui.tiny.line_height + (2 if hybrid else 4)
203
+ if hybrid:
204
+ top, bottom = faces.clear_band(side)
205
+ y = (H - side) // 2 + (top + bottom - row) // 2
206
+ line.set_style_pad_ver(1, 0)
207
+ line.set_height(row) # one line: dots, never a second
208
+ else:
209
+ y = H * 4 // 5 - ui.tiny.line_height // 2
210
+ line.set_style_pad_ver(2, 0)
211
+ line.set_height(lv.SIZE_CONTENT)
212
+ if is_round():
213
+ far = max(abs(side / 2 - y), abs(side / 2 - y - row))
214
+ half = int(max(0, (side / 2 - 8) ** 2 - far ** 2) ** 0.5)
215
+ line.set_style_max_width(max(60, 2 * half), 0)
216
+ else:
217
+ line.set_style_max_width(W - 16, 0)
218
+ line.set_width(lv.SIZE_CONTENT)
219
+ line.update_layout()
220
+ line.align(lv.ALIGN.TOP_MID, 0, y)
221
+
222
+ def show_line(text):
223
+ line.set_text(text)
224
+ if text:
225
+ line.remove_flag(lv.obj.FLAG.HIDDEN)
226
+ else:
227
+ line.add_flag(lv.obj.FLAG.HIDDEN)
228
+ place()
229
+
230
+ def show_face(name):
231
+ dial.clean()
232
+ state["name"] = name
233
+ state["face"] = faces.make(name, dial, side)
234
+ line.move_foreground()
235
+ catch.move_foreground()
236
+
237
+ def glance(force=False):
238
+ state["glance_at"] += TICK_MS
239
+ if force or state["glance_at"] >= GLANCE_MS:
240
+ state["glance_at"] = 0
241
+ if not shows_glances():
242
+ line.add_flag(lv.obj.FLAG.HIDDEN)
243
+ return
244
+ show_line(glances(state["name"] != faces.HYBRID))
245
+
246
+ def turn_face(step):
247
+ names = faces.names()
248
+ i = names.index(state["name"]) if state["name"] in names else 0
249
+ name = names[(i + step) % len(names)]
250
+ show_face(name)
251
+ _save_face(scope, name)
252
+ show_line(name) # says which face it is until the next glance
253
+ state["glance_at"] = -GLANCE_MS // 2
254
+
255
+ # -- the wheel --
256
+ wheel_view = lv.obj(root)
257
+ wheel_view.remove_style_all()
258
+ wheel_view.set_size(W, H)
259
+ wheel_view.remove_flag(lv.obj.FLAG.SCROLLABLE)
260
+ wheel_view.add_flag(lv.obj.FLAG.HIDDEN)
261
+ wheel_view.remove_flag(lv.obj.FLAG.GESTURE_BUBBLE)
262
+ launcher = scope.launcher
263
+ apps = in_order(launcher.info, launcher.hidden())
264
+ names = [a[0] for a in apps]
265
+ at = names.index(kept["app"]) if kept.get("app") in names else 0
266
+ wheel = Wheel(wheel_view, W, H, apps, scope.switch, at)
267
+ clock = ui.label(wheel_view, "", ui.small, ui.MUTED)
268
+ clock.add_flag(lv.obj.FLAG.CLICKABLE)
269
+ clock.set_ext_click_area(12)
270
+ clock.align(lv.ALIGN.TOP_MID, 0, 6 if not is_round() else max(6, H // 16))
271
+
272
+ def selected(i):
273
+ if 0 <= i < len(apps):
274
+ kept["app"] = apps[i][0]
275
+
276
+ wheel.on_select = selected
277
+ selected(wheel.selected)
278
+
279
+ def open_wheel():
280
+ t = localtime.now()
281
+ clock.set_text("%d:%02d" % (t[3], t[4]))
282
+ face_view.add_flag(lv.obj.FLAG.HIDDEN)
283
+ wheel_view.remove_flag(lv.obj.FLAG.HIDDEN)
284
+ state["opened"] = lv.tick_get()
285
+ if lv.group_get_default() is not None:
286
+ lv.group_focus_obj(wheel.cont)
287
+
288
+ def close_wheel():
289
+ wheel_view.add_flag(lv.obj.FLAG.HIDDEN)
290
+ face_view.remove_flag(lv.obj.FLAG.HIDDEN)
291
+ glance(True)
292
+
293
+ # A swipe also ends in a release, which LVGL may report as a click:
294
+ # one press is a swipe or a tap, never both.
295
+ def pressed(e):
296
+ state["swiped"] = False
297
+
298
+ def face_gesture(e):
299
+ d = lv.indev_active().get_gesture_dir()
300
+ state["swiped"] = True
301
+ if d == lv.DIR.LEFT:
302
+ turn_face(1)
303
+ elif d == lv.DIR.RIGHT:
304
+ turn_face(-1)
305
+ elif d == lv.DIR.TOP:
306
+ open_wheel()
307
+
308
+ def face_tap(e):
309
+ if not state["swiped"]:
310
+ open_wheel()
311
+
312
+ catch.add_event_cb(pressed, lv.EVENT.PRESSED, None)
313
+ catch.add_event_cb(face_gesture, lv.EVENT.GESTURE, None)
314
+ catch.add_event_cb(face_tap, lv.EVENT.CLICKED, None)
315
+
316
+ def wheel_gesture(e):
317
+ d = lv.indev_active().get_gesture_dir()
318
+ if d in (lv.DIR.LEFT, lv.DIR.RIGHT):
319
+ close_wheel()
320
+
321
+ wheel_view.add_event_cb(wheel_gesture, lv.EVENT.GESTURE, None)
322
+ wheel.cont.add_event_cb(wheel_gesture, lv.EVENT.GESTURE, None)
323
+ clock.add_event_cb(lambda e: close_wheel(), lv.EVENT.CLICKED, None)
324
+
325
+ # Keys: Enter on the face opens the wheel; the wheel takes them from there.
326
+ group = lv.group_get_default()
327
+ if group is not None:
328
+ group.add_obj(catch)
329
+ group.add_obj(wheel.cont)
330
+ lv.group_focus_obj(catch)
331
+
332
+ def face_key(e):
333
+ if e.get_key() == lv.KEY.ENTER:
334
+ open_wheel()
335
+
336
+ catch.add_event_cb(face_key, lv.EVENT.KEY, None)
337
+
338
+ def tick(_t=None):
339
+ if not face_view.has_flag(lv.obj.FLAG.HIDDEN):
340
+ state["face"].update_time()
341
+ glance()
342
+ return
343
+ t = localtime.now()
344
+ clock.set_text("%d:%02d" % (t[3], t[4]))
345
+ disp = lv.display_get_default()
346
+ # Untouched since it opened, however it was opened (a tap, a key,
347
+ # or a script), for WHEEL_IDLE_MS.
348
+ if (disp is not None and disp.get_inactive_time() > WHEEL_IDLE_MS
349
+ and lv.tick_elaps(state["opened"]) > WHEEL_IDLE_MS):
350
+ close_wheel()
351
+
352
+ show_face(state["name"])
353
+ glance(True)
354
+ scope.every(TICK_MS, tick)
355
+ tick()
apps/watch/app.json ADDED
@@ -0,0 +1 @@
1
+ {"name": "watch", "title": "Watch", "tile": false, "bar": "none"}
apps/watch/faces.py ADDED
@@ -0,0 +1,35 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Watch's faces: the hybrid face, then every skin of Clock's analog clock.
5
+
6
+ A face is made with `make` on a square parent and has ``update_time()``,
7
+ which Watch calls a few times a second; it redraws when the second changes.
8
+ """
9
+
10
+ from deskkit import localtime
11
+ from deskkit.clockface import AnalogClock
12
+ from deskkit.hybridface import HybridWatch
13
+
14
+ HYBRID = "OmniPython Hybrid"
15
+ DEFAULT = HYBRID
16
+
17
+
18
+ def names():
19
+ """Every face, the default first."""
20
+ return (HYBRID,) + AnalogClock.skin_names()
21
+
22
+
23
+ def make(name, parent, size):
24
+ """Face *name* on *parent*, *size* pixels square. An unknown name
25
+ gets the default face."""
26
+ if name not in AnalogClock.skin_names():
27
+ return HybridWatch(parent, size, localtime.now)
28
+ return AnalogClock(parent, (size, size), localtime.clock_time, name)
29
+
30
+
31
+ def clear_band(size):
32
+ """``(top, bottom)``, in pixels down a face *size* pixels square: the
33
+ band of the default face with no numeral, name or window in it, where a
34
+ line of text can sit."""
35
+ return HybridWatch.clear_band(size)
apps/watch/wheel.py ADDED
@@ -0,0 +1,157 @@
1
+ # SPDX-FileCopyrightText: 2026 Brad Barnett
2
+ #
3
+ # SPDX-License-Identifier: MIT
4
+ """Watch's wheel: every app on an arc, the one in the middle large.
5
+
6
+ A column of discs, one an app in its colour with its icon, scrolls up and
7
+ down and snaps an app to the middle. As it scrolls, each disc slides along
8
+ an arc that follows a round screen's edge and fades the further it is from
9
+ the middle; the middle one grows, with its name and tab beside it. A tap on
10
+ the middle app opens it, a tap on another brings it to the middle. Keys do
11
+ the same: up and down (or left and right) turn the wheel, Enter opens.
12
+ """
13
+
14
+ import math
15
+
16
+ import lvgl as lv
17
+ from icons import lvgl as lvicons
18
+
19
+ from touchkit import ui
20
+
21
+ ICON = 32 # the middle disc's icon; the others draw it smaller
22
+
23
+
24
+ def arc(r, dy):
25
+ """How far in from the edge a disc *dy* pixels from the middle sits, on
26
+ a circle of radius *r*."""
27
+ dy = min(r, dy)
28
+ return r - int(math.sqrt(r * r - dy * dy))
29
+
30
+
31
+ class Wheel:
32
+ """The wheel on *parent*, *w* by *h*. *apps* is ``[(name, title,
33
+ category, icon, colour), ...]`` in order; *on_open* is called with the
34
+ name of the app to open. *at* is the app that starts in the middle."""
35
+
36
+ def __init__(self, parent, w, h, apps, on_open, at=0):
37
+ self.apps = apps
38
+ self.on_open = on_open
39
+ self.selected = -1
40
+ self.on_select = None # called with the index of the app that comes to the middle
41
+ slot = max(40, h // 4)
42
+ self.slot = slot
43
+ self.big = slot - 4
44
+ self.small = slot * 3 // 5
45
+ self.r = h // 2 # the arc's radius: the screen's own on a round one
46
+ self.col = w * 3 // 10 # the discs' centre line, left of the middle
47
+ cont = lv.obj(parent)
48
+ cont.remove_style_all()
49
+ cont.set_size(w, h)
50
+ cont.set_flex_flow(lv.FLEX_FLOW.COLUMN)
51
+ cont.set_style_pad_top((h - slot) // 2, 0)
52
+ cont.set_style_pad_bottom((h - slot) // 2, 0)
53
+ cont.set_scroll_dir(lv.DIR.VER)
54
+ cont.set_scroll_snap_y(lv.SCROLL_SNAP.CENTER)
55
+ cont.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
56
+ cont.add_event_cb(lambda e: self._arrange(), lv.EVENT.SCROLL, None)
57
+ cont.add_event_cb(lambda e: self._arrange(), lv.EVENT.SCROLL_END, None)
58
+ cont.add_event_cb(self._key, lv.EVENT.KEY, None)
59
+ self.cont = cont
60
+ self.items = []
61
+ self.discs = []
62
+ self.icons = []
63
+ for i, (name, title, category, icon, color) in enumerate(apps):
64
+ item = lv.obj(cont)
65
+ item.remove_style_all()
66
+ item.set_size(w, slot)
67
+ item.remove_flag(lv.obj.FLAG.SCROLLABLE)
68
+ item.add_flag(lv.obj.FLAG.CLICKABLE)
69
+ item.add_flag(lv.obj.FLAG.GESTURE_BUBBLE)
70
+ disc = lv.obj(item)
71
+ disc.remove_style_all()
72
+ disc.remove_flag(lv.obj.FLAG.CLICKABLE)
73
+ disc.set_style_radius(lv.RADIUS_CIRCLE, 0)
74
+ disc.set_style_bg_color(lv.color_hex(color), 0)
75
+ disc.set_style_bg_opa(lv.OPA.COVER, 0)
76
+ img = lvicons.image(disc, icon, ICON, ui.WHITE)
77
+ img.center()
78
+ item.add_event_cb((lambda i: lambda e: self._tapped(i))(i), lv.EVENT.CLICKED, None)
79
+ self.items.append(item)
80
+ self.discs.append(disc)
81
+ self.icons.append(img)
82
+ # The middle app's tab and name, right of its disc.
83
+ x = self.col + self.big // 2 + 10
84
+ self.tab = ui.label(parent, "", ui.tiny, ui.MUTED)
85
+ self.name = ui.label(parent, "", ui.font, ui.WHITE)
86
+ for lbl in (self.tab, self.name):
87
+ lbl.set_width(max(40, w - x - 12))
88
+ lbl.set_long_mode(lv.label.LONG_MODE.DOTS)
89
+ lbl.remove_flag(lv.obj.FLAG.CLICKABLE)
90
+ self.name.set_height(2 * ui.font.line_height)
91
+ self.tab.set_pos(x, h // 2 - ui.font.line_height // 2 - ui.tiny.line_height - 2)
92
+ self.name.set_pos(x, h // 2 - ui.font.line_height // 2)
93
+ cont.update_layout()
94
+ if apps:
95
+ self.show(at, False)
96
+ self._arrange()
97
+
98
+ def middle(self):
99
+ """The index of the app nearest the middle, or -1 with none."""
100
+ a = lv.area_t()
101
+ self.cont.get_coords(a)
102
+ cy = (a.y1 + a.y2) // 2
103
+ best, best_d = -1, 1 << 30
104
+ for i, item in enumerate(self.items):
105
+ item.get_coords(a)
106
+ d = abs((a.y1 + a.y2) // 2 - cy)
107
+ if d < best_d:
108
+ best, best_d = i, d
109
+ return best
110
+
111
+ def _arrange(self):
112
+ a = lv.area_t()
113
+ self.cont.get_coords(a)
114
+ cy = (a.y1 + a.y2) // 2
115
+ r = self.r
116
+ best = self.middle()
117
+ for i, item in enumerate(self.items):
118
+ item.get_coords(a)
119
+ dy = min(r, abs((a.y1 + a.y2) // 2 - cy))
120
+ x = arc(r, dy)
121
+ d = self.big if i == best else self.small
122
+ disc = self.discs[i]
123
+ disc.set_size(d, d)
124
+ disc.set_pos(self.col - d // 2 + x, (self.slot - d) // 2)
125
+ self.icons[i].set_scale(256 if i == best else 256 * (self.small * 3 // 5) // ICON)
126
+ disc.set_style_opa(255 - 200 * dy // r, 0)
127
+ if best != self.selected:
128
+ self.selected = best
129
+ if best >= 0:
130
+ name, title, category, icon, color = self.apps[best]
131
+ self.name.set_text(title)
132
+ self.tab.set_text(category)
133
+ if self.on_select is not None:
134
+ self.on_select(best)
135
+
136
+ def show(self, i, anim=True):
137
+ """Bring app *i* (from 0) to the middle."""
138
+ if not self.items:
139
+ return
140
+ i = max(0, min(i, len(self.items) - 1))
141
+ self.items[i].scroll_to_view(bool(anim))
142
+ self._arrange()
143
+
144
+ def _tapped(self, i):
145
+ if i == self.selected:
146
+ self.on_open(self.apps[i][0])
147
+ else:
148
+ self.show(i)
149
+
150
+ def _key(self, e):
151
+ key = e.get_key()
152
+ if key in (lv.KEY.UP, lv.KEY.LEFT, lv.KEY.PREV):
153
+ self.show(self.selected - 1)
154
+ elif key in (lv.KEY.DOWN, lv.KEY.RIGHT, lv.KEY.NEXT):
155
+ self.show(self.selected + 1)
156
+ elif key == lv.KEY.ENTER and self.selected >= 0:
157
+ self.on_open(self.apps[self.selected][0])