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.
- apps/__init__.py +5 -0
- apps/about/__init__.py +257 -0
- apps/about/app.json +1 -0
- apps/about/credits.py +12 -0
- apps/about/facts.py +398 -0
- apps/about/fonts/OFL.txt +93 -0
- apps/about/fonts/latin1_14.bin +0 -0
- apps/about/fonts/latin1_16.bin +0 -0
- apps/about/fonts/latin1_24.bin +0 -0
- apps/about/fonts/latin1_32.bin +0 -0
- apps/about/fonts/latin1_40.bin +0 -0
- apps/backline/__init__.py +58 -0
- apps/backline/app.json +1 -0
- apps/backline/app.py +475 -0
- apps/backline/art.py +717 -0
- apps/backline/ask.py +781 -0
- apps/backline/box.py +502 -0
- apps/backline/cast.py +137 -0
- apps/backline/desk/__init__.py +329 -0
- apps/backline/desk/editor.py +331 -0
- apps/backline/desk/grid.py +154 -0
- apps/backline/desk/look.py +169 -0
- apps/backline/desk/pedals.py +102 -0
- apps/backline/desk/perform.py +157 -0
- apps/backline/desk/prompt.py +210 -0
- apps/backline/desk/strip.py +159 -0
- apps/backline/desk_main.py +226 -0
- apps/backline/engine.py +622 -0
- apps/backline/floor.py +509 -0
- apps/backline/footswitch.py +119 -0
- apps/backline/glyphs.py +82 -0
- apps/backline/kits.py +428 -0
- apps/backline/midipedal.py +362 -0
- apps/backline/page_data.py +413 -0
- apps/backline/parts.py +145 -0
- apps/backline/pedal.py +107 -0
- apps/backline/remote.py +134 -0
- apps/backline/songs/ballad_68.json +1 -0
- apps/backline/songs/bossa.json +1 -0
- apps/backline/songs/country_train.json +1 -0
- apps/backline/songs/funk.json +1 -0
- apps/backline/songs/metal.json +1 -0
- apps/backline/songs/pop.json +1 -0
- apps/backline/songs/rock.json +1 -0
- apps/backline/songs/shuffle.json +1 -0
- apps/battery/__init__.py +101 -0
- apps/battery/app.json +1 -0
- apps/bit_world/act_deck.py +683 -0
- apps/bit_world/act_game.py +762 -0
- apps/bit_world/act_pet.py +1032 -0
- apps/bit_world/app.json +1 -0
- apps/bit_world/bit_output.py +45 -0
- apps/bit_world/bit_palette.py +503 -0
- apps/bit_world/bit_sound.py +431 -0
- apps/bit_world/bit_sprites.py +632 -0
- apps/bit_world/bit_world.py +534 -0
- apps/btreceiver/__init__.py +690 -0
- apps/btreceiver/app.json +1 -0
- apps/btreceiver/chime.py +155 -0
- apps/btreceiver/demo.py +529 -0
- apps/btreceiver/screen.py +633 -0
- apps/camera/__init__.py +316 -0
- apps/camera/app.json +1 -0
- apps/card/__init__.py +113 -0
- apps/card/app.json +1 -0
- apps/cast/__init__.py +631 -0
- apps/cast/app.json +1 -0
- apps/cast/receivers.py +193 -0
- apps/chess/__init__.py +18 -0
- apps/chess/app.json +1 -0
- apps/chess/app.py +922 -0
- apps/chess/art.py +323 -0
- apps/chess/ble.py +411 -0
- apps/chess/engine.py +925 -0
- apps/chess/game.py +327 -0
- apps/chess/net.py +261 -0
- apps/clock/__init__.py +38 -0
- apps/clock/app.json +1 -0
- apps/detect/__init__.py +214 -0
- apps/detect/app.json +1 -0
- apps/fmsynth/__init__.py +41 -0
- apps/fmsynth/algorithms.py +61 -0
- apps/fmsynth/app.json +1 -0
- apps/fmsynth/app.py +355 -0
- apps/fmsynth/editor.py +206 -0
- apps/fmsynth/engine.py +257 -0
- apps/fmsynth/meters.py +262 -0
- apps/fmsynth/midi.py +375 -0
- apps/fmsynth/panel_view.py +1071 -0
- apps/fmsynth/patches/fmsynth-01.syx +0 -0
- apps/fmsynth/settings.py +138 -0
- apps/fmsynth/voice.py +398 -0
- apps/gamepad/__init__.py +685 -0
- apps/gamepad/app.json +1 -0
- apps/gamepad/pad.py +94 -0
- apps/gamepad/watch.py +352 -0
- apps/hidden/__init__.py +72 -0
- apps/hidden/app.json +1 -0
- apps/home/__init__.py +483 -0
- apps/home/app.json +1 -0
- apps/home/main.py +36 -0
- apps/homeassistant/__init__.py +213 -0
- apps/homeassistant/api.py +104 -0
- apps/homeassistant/app.json +1 -0
- apps/huey/__init__.py +287 -0
- apps/huey/acting.py +184 -0
- apps/huey/actor.py +194 -0
- apps/huey/app.json +1 -0
- apps/huey/client.py +125 -0
- apps/huey/servers.py +121 -0
- apps/huey/settings.example.json +8 -0
- apps/huey/settings.py +97 -0
- apps/huey/turn.py +504 -0
- apps/huey/voice.py +217 -0
- apps/info/__init__.py +810 -0
- apps/info/app.json +1 -0
- apps/lora/__init__.py +62 -0
- apps/lora/app.json +1 -0
- apps/manifest.py +71 -0
- apps/medialink_baby_monitor/__init__.py +222 -0
- apps/medialink_baby_monitor/app.json +1 -0
- apps/medialink_doorbell/__init__.py +251 -0
- apps/medialink_doorbell/app.json +1 -0
- apps/medialink_hands_free/__init__.py +217 -0
- apps/medialink_hands_free/app.json +1 -0
- apps/medialink_surveillance_camera/__init__.py +258 -0
- apps/medialink_surveillance_camera/app.json +1 -0
- apps/medialink_video_doorbell/__init__.py +289 -0
- apps/medialink_video_doorbell/app.json +1 -0
- apps/medialink_videophone/__init__.py +273 -0
- apps/medialink_videophone/app.json +1 -0
- apps/medialink_walkie_talkie/__init__.py +228 -0
- apps/medialink_walkie_talkie/app.json +1 -0
- apps/midicontroller/__init__.py +774 -0
- apps/midicontroller/app.json +1 -0
- apps/midicontroller/links.py +421 -0
- apps/midicontroller/surface.py +343 -0
- apps/midiengine/__init__.py +977 -0
- apps/midiengine/app.json +1 -0
- apps/midiengine/banks.py +85 -0
- apps/midiengine/midiin.py +165 -0
- apps/midiengine/player.py +392 -0
- apps/midiengine/umidiparser.py +1413 -0
- apps/mp3/__init__.py +240 -0
- apps/mp3/app.json +1 -0
- apps/perch/__init__.py +119 -0
- apps/perch/app.json +1 -0
- apps/perch/huey.py +481 -0
- apps/perch/huey_props.py +386 -0
- apps/perch/huey_shift.py +42 -0
- apps/perch/huey_views.py +296 -0
- apps/perch/scene_bench.py +680 -0
- apps/perch/scene_coast.py +479 -0
- apps/perch/scene_desk.py +492 -0
- apps/perch/stage.py +1274 -0
- apps/perch/vec.py +366 -0
- apps/repl/__init__.py +325 -0
- apps/repl/app.json +1 -0
- apps/roku/__init__.py +156 -0
- apps/roku/app.json +1 -0
- apps/rokucam/__init__.py +362 -0
- apps/rokucam/app.json +1 -0
- apps/security/__init__.py +261 -0
- apps/security/app.json +1 -0
- apps/settings/__init__.py +221 -0
- apps/settings/app.json +1 -0
- apps/shell/__init__.py +33 -0
- apps/shell/app.json +1 -0
- apps/spotify/__init__.py +669 -0
- apps/spotify/app.json +1 -0
- apps/spotify/screen.py +82 -0
- apps/steps/__init__.py +58 -0
- apps/steps/app.json +1 -0
- apps/stompbox/__init__.py +31 -0
- apps/stompbox/app.json +1 -0
- apps/stompbox/app.py +668 -0
- apps/stompbox/boards.json +20 -0
- apps/stompbox/effects.py +241 -0
- apps/stompbox/engine.py +340 -0
- apps/stompbox/footswitch.py +331 -0
- apps/stompbox/inputs.py +449 -0
- apps/stompbox/meter.py +72 -0
- apps/stompbox/outputs.py +135 -0
- apps/stompbox/pedals.txt +45 -0
- apps/stompbox/presets.py +106 -0
- apps/stompbox/styles.py +135 -0
- apps/stompbox/ui.py +817 -0
- apps/stompbox/wavfile.py +73 -0
- apps/synthstation/__init__.py +20 -0
- apps/synthstation/app.json +1 -0
- apps/synthstation/audio.py +397 -0
- apps/synthstation/catalog.py +50 -0
- apps/synthstation/meters.py +136 -0
- apps/synthstation/midi.py +380 -0
- apps/synthstation/pads.py +177 -0
- apps/synthstation/parts.py +128 -0
- apps/synthstation/station.py +1069 -0
- apps/system/__init__.py +11 -0
- apps/system/app.json +1 -0
- apps/touchcal/__init__.py +324 -0
- apps/touchcal/app.json +1 -0
- apps/touchcal/fit.py +262 -0
- apps/wake/__init__.py +268 -0
- apps/wake/app.json +1 -0
- apps/wake/feed.py +155 -0
- apps/watch/__init__.py +355 -0
- apps/watch/app.json +1 -0
- apps/watch/faces.py +35 -0
- apps/watch/wheel.py +157 -0
- apps/weather/__init__.py +278 -0
- apps/weather/app.json +1 -0
- apps/weather/icons.py +172 -0
- apps/weather/sizing.py +71 -0
- apps/weather/zippad.py +172 -0
- omnipython_apps-0.1.4.dev8.dist-info/METADATA +33 -0
- omnipython_apps-0.1.4.dev8.dist-info/RECORD +218 -0
- omnipython_apps-0.1.4.dev8.dist-info/WHEEL +5 -0
- omnipython_apps-0.1.4.dev8.dist-info/top_level.txt +1 -0
apps/home/__init__.py
ADDED
|
@@ -0,0 +1,483 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Home: the apps on pages, a tab for each category.
|
|
5
|
+
|
|
6
|
+
Each app says what it is in its ``app.json``: ``category`` (its tab), ``icon``
|
|
7
|
+
(a Material Symbols name from the icons package, required), ``color`` (a "#RRGGBB" tile colour) and ``tile`` (false to
|
|
8
|
+
keep it off the tabs). Tabs come in alphabetical order by category. An app
|
|
9
|
+
with no category goes on a tab of its own, "More", last. Home knows no app by
|
|
10
|
+
name: the board's own apps (Info, Settings, Hidden apps, the REPL) are on the
|
|
11
|
+
System tab because their ``app.json`` says so.
|
|
12
|
+
|
|
13
|
+
A tab with more apps than its grid holds gets as many pages as it needs,
|
|
14
|
+
the apps in the same order, with a dot for each page under the grid. A
|
|
15
|
+
swipe across the screen turns the tab's pages, and past its last page
|
|
16
|
+
slides on to the next tab; backwards, past the first page, to the previous
|
|
17
|
+
tab's last page. A tap on a dot turns to that page, and a tap on a tab
|
|
18
|
+
switches to its first page at once. Home comes back to the tab and page it
|
|
19
|
+
was last on. The tabs are as tall as the status bar.
|
|
20
|
+
|
|
21
|
+
An app hidden from an app's can't-run screen (``Launcher.hide``) stays off
|
|
22
|
+
the pages. The Hidden apps app lists them, with the reason each gave, and
|
|
23
|
+
puts them back.
|
|
24
|
+
|
|
25
|
+
A title too long for its tile takes a second line where the tile has room
|
|
26
|
+
for one, broken at a space or a hyphen; a single word too long for the tile
|
|
27
|
+
is cut short with dots. A small tile with room for a 48 px icon over its two
|
|
28
|
+
lines shows one, as large tiles do, so a 480x320 screen gets them; a smaller
|
|
29
|
+
tile keeps the 24 px icon.
|
|
30
|
+
|
|
31
|
+
On a round screen (see ``appkit.shell.is_round``) the pages and their tabs
|
|
32
|
+
fill the square inside the circle, two apps by two, so nothing falls
|
|
33
|
+
outside the circle. They turn in pages the same way.
|
|
34
|
+
"""
|
|
35
|
+
|
|
36
|
+
import lvgl as lv
|
|
37
|
+
|
|
38
|
+
import icons
|
|
39
|
+
from icons import lvgl as lvicons
|
|
40
|
+
from appkit.bar import height_for
|
|
41
|
+
from appkit.shell import ROUND_MARGIN, is_round
|
|
42
|
+
from touchkit import ui
|
|
43
|
+
|
|
44
|
+
DEFAULT_COLOR = "#44505E"
|
|
45
|
+
|
|
46
|
+
LARGE_PAD = 4 # least space between the large layout's icon or title and the tile's edge
|
|
47
|
+
BIG_ICON = 48 # the large layout's icon, and a small tile's when it has the room
|
|
48
|
+
SMALL_ICON = 24
|
|
49
|
+
SMALL_PAD = 2 # a small tile's padding
|
|
50
|
+
COLS, ROWS = 4, 2 # landscape; see grid_shape()
|
|
51
|
+
GAP = 12
|
|
52
|
+
TOP = 56
|
|
53
|
+
MARGIN = 8 # around each page's card
|
|
54
|
+
CARD = 0x121826 # a shade lighter than the screen
|
|
55
|
+
LINE = 0x2A3550 # the card's border and the tab bar's top edge
|
|
56
|
+
TAB_ON = 0x1A2438
|
|
57
|
+
DOT = 6 # a page dot
|
|
58
|
+
DOTS = 14 # the row of page dots under the grid, when a tab has more than one page
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def grid_shape(w, h):
|
|
62
|
+
"""The tiles per page as (columns, rows): 4 by 2 on a landscape screen, 2 by 4
|
|
63
|
+
on a portrait one and 3 by 3 on a square one."""
|
|
64
|
+
if w > h:
|
|
65
|
+
return COLS, ROWS
|
|
66
|
+
if w < h:
|
|
67
|
+
return ROWS, COLS
|
|
68
|
+
return 3, 3
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def _tall_enough(h):
|
|
72
|
+
"""Whether a tile *h* pixels tall fits the large layout: the 48 px icon, centred 22 px
|
|
73
|
+
above the middle, and the title 40 px below it, each with LARGE_PAD to spare."""
|
|
74
|
+
return h >= max(2 * (22 + 24 + LARGE_PAD), 2 * (40 + ui.font.line_height // 2 + LARGE_PAD))
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def _grid(scope, page, cw, ch, apps, cols=COLS, rows=ROWS, small=False):
|
|
78
|
+
"""The app tiles on one page: a card *cw* by *ch*, *cols* by *rows* tiles.
|
|
79
|
+
*small* tiles take the smaller fonts and stack the icon over the title; so do
|
|
80
|
+
tiles too short for the large layout (see `_tall_enough`)."""
|
|
81
|
+
launcher = scope.launcher
|
|
82
|
+
if not small and not _tall_enough((ch - (rows + 1) * GAP) // rows):
|
|
83
|
+
small = True
|
|
84
|
+
gap = GAP // 2 if small else GAP
|
|
85
|
+
card = lv.obj(page)
|
|
86
|
+
card.remove_style_all()
|
|
87
|
+
card.set_pos(MARGIN, MARGIN)
|
|
88
|
+
card.set_size(cw, ch)
|
|
89
|
+
card.set_style_bg_color(lv.color_hex(CARD), 0)
|
|
90
|
+
card.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
91
|
+
card.set_style_radius(12 if small else 20, 0)
|
|
92
|
+
card.set_style_border_width(1, 0)
|
|
93
|
+
card.set_style_border_color(lv.color_hex(LINE), 0)
|
|
94
|
+
card.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
95
|
+
card.add_flag(lv.obj.FLAG.EVENT_BUBBLE) # a swipe on the card still turns the page
|
|
96
|
+
w = (cw - (cols + 1) * gap) // cols
|
|
97
|
+
h = (ch - (rows + 1) * gap) // rows
|
|
98
|
+
if small:
|
|
99
|
+
# Icon and title stacked and centred as one, the title given two lines'
|
|
100
|
+
# room where the tile has it; the larger icon where there's room for
|
|
101
|
+
# that too, so every icon in a row lines up whatever its title.
|
|
102
|
+
lh = ui.tiny.line_height
|
|
103
|
+
inner = h - 2 * SMALL_PAD
|
|
104
|
+
lines = 2 if inner >= SMALL_ICON + LARGE_PAD + 2 * lh else 1
|
|
105
|
+
size = BIG_ICON if lines == 2 and w >= 2 * BIG_ICON and inner >= BIG_ICON + 2 * LARGE_PAD + 2 * lh else SMALL_ICON
|
|
106
|
+
top = (inner - size - LARGE_PAD - lines * lh) // 2
|
|
107
|
+
else:
|
|
108
|
+
lh = ui.font.line_height
|
|
109
|
+
# The title's first line sits 40 px below the middle; a second goes under it.
|
|
110
|
+
lines = 2 if h // 2 >= 40 + lh + LARGE_PAD else 1
|
|
111
|
+
for i, (name, icon_name, color) in enumerate(apps):
|
|
112
|
+
col, row = i % cols, i // cols
|
|
113
|
+
b = lv.button(card)
|
|
114
|
+
b.set_size(w, h)
|
|
115
|
+
b.set_pos(gap + col * (w + gap), gap + row * (h + gap))
|
|
116
|
+
b.set_style_bg_color(lv.color_hex(color), 0)
|
|
117
|
+
title = launcher.info.get(name, {}).get("title", name)
|
|
118
|
+
if small:
|
|
119
|
+
b.set_style_radius(10, 0)
|
|
120
|
+
b.set_style_pad_all(SMALL_PAD, 0)
|
|
121
|
+
icon = lvicons.image(b, icon_name, size, ui.WHITE)
|
|
122
|
+
text = wrap(title, ui.tiny, w - 2 * SMALL_PAD) if lines == 2 else title
|
|
123
|
+
lbl = ui.label(b, text, ui.tiny, ui.WHITE)
|
|
124
|
+
lbl.set_long_mode(lv.label.LONG_MODE.DOTS)
|
|
125
|
+
# A fixed height is what lets DOTS cut a long title.
|
|
126
|
+
lbl.set_size(w - 2 * SMALL_PAD, lh * (2 if "\n" in text else 1))
|
|
127
|
+
lbl.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
128
|
+
if lines == 1:
|
|
129
|
+
icon.align(lv.ALIGN.CENTER, 0, -lh // 2)
|
|
130
|
+
lbl.align(lv.ALIGN.BOTTOM_MID, 0, 0)
|
|
131
|
+
else:
|
|
132
|
+
icon.align(lv.ALIGN.TOP_MID, 0, top)
|
|
133
|
+
lbl.align(lv.ALIGN.TOP_MID, 0, top + size + LARGE_PAD)
|
|
134
|
+
else:
|
|
135
|
+
b.set_style_radius(18, 0)
|
|
136
|
+
icon = lvicons.image(b, icon_name, BIG_ICON, ui.WHITE)
|
|
137
|
+
icon.align(lv.ALIGN.CENTER, 0, -22)
|
|
138
|
+
width = w - 2 * LARGE_PAD
|
|
139
|
+
text = wrap(title, ui.font, width) if lines == 2 else title
|
|
140
|
+
two = "\n" in text
|
|
141
|
+
lbl = ui.label(b, text, ui.font, ui.WHITE)
|
|
142
|
+
lbl.set_long_mode(lv.label.LONG_MODE.DOTS)
|
|
143
|
+
lbl.set_size(width, lh * (2 if two else 1))
|
|
144
|
+
lbl.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
145
|
+
lbl.align(lv.ALIGN.CENTER, 0, 40 + (lh // 2 if two else 0))
|
|
146
|
+
b.add_event_cb((lambda n: lambda e: scope.switch(n))(name), lv.EVENT.CLICKED, None)
|
|
147
|
+
|
|
148
|
+
|
|
149
|
+
def text_width(text, font):
|
|
150
|
+
"""How wide *text* draws in *font*, in pixels."""
|
|
151
|
+
n = len(text.encode()) # LVGL counts bytes
|
|
152
|
+
try:
|
|
153
|
+
attrs = lv.text_attributes_t()
|
|
154
|
+
attrs.init()
|
|
155
|
+
return lv.text_get_width(text, n, font, attrs)
|
|
156
|
+
except AttributeError: # LVGL before 9.4 takes the letter spacing itself
|
|
157
|
+
return lv.text_get_width(text, n, font, 0)
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
def wrap(title, font, width):
|
|
161
|
+
"""*title* as a tile *width* pixels wide shows it in *font*: as it is when
|
|
162
|
+
it fits on one line, else broken into two at the last space or hyphen
|
|
163
|
+
that lets the first line fit. A title with no such break comes back as
|
|
164
|
+
it is, for the label to cut short."""
|
|
165
|
+
if text_width(title, font) <= width:
|
|
166
|
+
return title
|
|
167
|
+
best = None
|
|
168
|
+
for i, ch in enumerate(title):
|
|
169
|
+
if ch == " ":
|
|
170
|
+
head, tail = title[:i], title[i + 1:]
|
|
171
|
+
elif ch == "-":
|
|
172
|
+
head, tail = title[: i + 1], title[i + 1:]
|
|
173
|
+
else:
|
|
174
|
+
continue
|
|
175
|
+
if head.strip() and tail.strip() and text_width(head, font) <= width:
|
|
176
|
+
best = head + "\n" + tail
|
|
177
|
+
return title if best is None else best
|
|
178
|
+
|
|
179
|
+
|
|
180
|
+
def paged(apps, per):
|
|
181
|
+
"""*apps* cut into pages of *per*, in order: one page at least, empty
|
|
182
|
+
when there are no apps."""
|
|
183
|
+
return [apps[i: i + per] for i in range(0, len(apps), per)] or [[]]
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
def _dots(parent, count, w, y, turn):
|
|
187
|
+
"""A row of *count* page dots centred across *w* at *y*; a tap on one
|
|
188
|
+
calls *turn* with its page. Returns the dots."""
|
|
189
|
+
out = []
|
|
190
|
+
step = 3 * DOT
|
|
191
|
+
x = (w - (count - 1) * step - DOT) // 2
|
|
192
|
+
for k in range(count):
|
|
193
|
+
d = lv.obj(parent)
|
|
194
|
+
d.remove_style_all()
|
|
195
|
+
d.set_size(DOT, DOT)
|
|
196
|
+
d.set_pos(x + k * step, y + (DOTS - DOT) // 2)
|
|
197
|
+
d.set_style_radius(DOT // 2, 0)
|
|
198
|
+
d.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
199
|
+
d.set_style_bg_color(ui.MUTED, 0)
|
|
200
|
+
d.set_ext_click_area(DOT) # a fingertip, not just the dot
|
|
201
|
+
d.add_flag(lv.obj.FLAG.CLICKABLE)
|
|
202
|
+
d.add_event_cb((lambda k: lambda e: turn(k))(k), lv.EVENT.CLICKED, None)
|
|
203
|
+
out.append(d)
|
|
204
|
+
return out
|
|
205
|
+
|
|
206
|
+
|
|
207
|
+
class _Tab:
|
|
208
|
+
"""One category's pages: a strip of grids that scrolls a page at a time,
|
|
209
|
+
and its dots. At either end of the strip a swipe passes on to the tab
|
|
210
|
+
view, which turns the tab."""
|
|
211
|
+
|
|
212
|
+
def __init__(self, scope, page, pw, ph, apps, cols, rows, small, dots):
|
|
213
|
+
self.pw = pw
|
|
214
|
+
self.grids = paged(apps, cols * rows)
|
|
215
|
+
gh = ph - dots
|
|
216
|
+
strip = lv.obj(page)
|
|
217
|
+
strip.remove_style_all()
|
|
218
|
+
strip.set_size(pw, gh)
|
|
219
|
+
strip.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
|
220
|
+
strip.set_scrollbar_mode(lv.SCROLLBAR_MODE.OFF)
|
|
221
|
+
if len(self.grids) > 1:
|
|
222
|
+
strip.set_scroll_dir(lv.DIR.HOR)
|
|
223
|
+
strip.set_scroll_snap_x(lv.SCROLL_SNAP.CENTER)
|
|
224
|
+
strip.add_flag(lv.obj.FLAG.SCROLL_ONE)
|
|
225
|
+
strip.add_event_cb(lambda e: self.landed(), lv.EVENT.SCROLL_END, None)
|
|
226
|
+
else:
|
|
227
|
+
strip.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
228
|
+
for k, grid in enumerate(self.grids):
|
|
229
|
+
g = lv.obj(strip)
|
|
230
|
+
g.remove_style_all()
|
|
231
|
+
g.set_pos(k * pw, 0)
|
|
232
|
+
g.set_size(pw, gh)
|
|
233
|
+
g.add_flag(lv.obj.FLAG.EVENT_BUBBLE)
|
|
234
|
+
g.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
235
|
+
_grid(scope, g, pw - 2 * MARGIN, gh - 2 * MARGIN, grid, cols, rows, small)
|
|
236
|
+
self.strip = strip
|
|
237
|
+
self.dots = _dots(page, len(self.grids), pw, gh - MARGIN // 2, self.turn) if len(self.grids) > 1 else []
|
|
238
|
+
self.at = 0
|
|
239
|
+
self.on_turn = None
|
|
240
|
+
|
|
241
|
+
def last(self):
|
|
242
|
+
return len(self.grids) - 1
|
|
243
|
+
|
|
244
|
+
def show(self, k, anim=False):
|
|
245
|
+
"""Turn to page *k* (counted from 0)."""
|
|
246
|
+
k = max(0, min(k, self.last()))
|
|
247
|
+
self.strip.scroll_to_x(k * self.pw, bool(anim))
|
|
248
|
+
if not anim:
|
|
249
|
+
self.mark(k)
|
|
250
|
+
|
|
251
|
+
def turn(self, k):
|
|
252
|
+
self.show(k, True)
|
|
253
|
+
|
|
254
|
+
def landed(self):
|
|
255
|
+
self.mark((self.strip.get_scroll_x() + self.pw // 2) // self.pw)
|
|
256
|
+
|
|
257
|
+
def mark(self, k):
|
|
258
|
+
k = max(0, min(k, self.last()))
|
|
259
|
+
for i, d in enumerate(self.dots):
|
|
260
|
+
d.set_style_bg_color(ui.ACCENT if i == k else ui.MUTED, 0)
|
|
261
|
+
changed = k != self.at
|
|
262
|
+
self.at = k
|
|
263
|
+
if changed and self.on_turn is not None:
|
|
264
|
+
self.on_turn(k)
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
def _tile(name, entry):
|
|
268
|
+
icon = entry.get("icon")
|
|
269
|
+
if icon is None:
|
|
270
|
+
raise ValueError(
|
|
271
|
+
'app %r has no "icon" in its app.json. Every app with a tile needs one: add "icon": '
|
|
272
|
+
'"<Material icon name>", taken from icons.names(), or set "tile": false.' % (name,)
|
|
273
|
+
)
|
|
274
|
+
if not icons.has(icon):
|
|
275
|
+
raise ValueError(
|
|
276
|
+
"app %r names icon %r in its app.json, which the icons package hasn't. "
|
|
277
|
+
"icons.names() lists the ones it has." % (name, icon)
|
|
278
|
+
)
|
|
279
|
+
return (name, icon, int(entry.get("color", DEFAULT_COLOR)[1:], 16))
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
def _pages(info, hidden=()):
|
|
283
|
+
"""``[(category, [(app, icon, colour), ...]), ...]``, from each app's
|
|
284
|
+
``app.json``, leaving out the apps in *hidden*."""
|
|
285
|
+
by_category = {}
|
|
286
|
+
more = []
|
|
287
|
+
for name in sorted(info):
|
|
288
|
+
entry = info[name]
|
|
289
|
+
if not entry.get("tile", True) or name in hidden:
|
|
290
|
+
continue
|
|
291
|
+
category = entry.get("category")
|
|
292
|
+
if category is None:
|
|
293
|
+
more.append(_tile(name, entry))
|
|
294
|
+
else:
|
|
295
|
+
by_category.setdefault(category, []).append(_tile(name, entry))
|
|
296
|
+
out = [(category, by_category[category]) for category in sorted(by_category)]
|
|
297
|
+
if more:
|
|
298
|
+
out.append(("More", more))
|
|
299
|
+
return out
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _below_cap(scope, title, right):
|
|
303
|
+
"""How far Home's own row has to move down to clear the status bar's
|
|
304
|
+
compact cap, which floats at the top middle: 0 when the cap fits between
|
|
305
|
+
*title* and *right*, else the cap's height."""
|
|
306
|
+
cap = getattr(scope, "bar", None)
|
|
307
|
+
if cap is None or not cap.compact or not cap.is_shown():
|
|
308
|
+
return 0
|
|
309
|
+
cap.root.update_layout()
|
|
310
|
+
title.update_layout()
|
|
311
|
+
w = cap.root.get_width()
|
|
312
|
+
left = (scope.size[0] - w) // 2
|
|
313
|
+
if left >= title.get_x() + title.get_width() + 4 and left + w + 4 <= right:
|
|
314
|
+
return 0
|
|
315
|
+
return cap.root.get_y() + cap.root.get_height() + 4
|
|
316
|
+
|
|
317
|
+
|
|
318
|
+
def tab_height(scope):
|
|
319
|
+
"""How tall Home's tabs are: as tall as the status bar, or as the bar
|
|
320
|
+
would be on this screen when there's none or it's the compact cap."""
|
|
321
|
+
cap = getattr(scope, "bar", None)
|
|
322
|
+
if cap is not None and not cap.compact:
|
|
323
|
+
return cap.height
|
|
324
|
+
disp = lv.display_get_default()
|
|
325
|
+
return height_for(disp.get_horizontal_resolution(), disp.get_vertical_resolution())
|
|
326
|
+
|
|
327
|
+
|
|
328
|
+
def _labels_clear(tv, bar):
|
|
329
|
+
"""Whether the tab labels leave a gap of at least 4 px between them."""
|
|
330
|
+
tv.update_layout()
|
|
331
|
+
spans = []
|
|
332
|
+
for i in range(bar.get_child_count()):
|
|
333
|
+
lbl = bar.get_child(i).get_child(0)
|
|
334
|
+
a = lv.area_t()
|
|
335
|
+
lbl.get_coords(a)
|
|
336
|
+
spans.append((a.x1, a.x2))
|
|
337
|
+
spans.sort()
|
|
338
|
+
return all(b[0] - a[1] > 4 for a, b in zip(spans, spans[1:]))
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
def main(scope):
|
|
342
|
+
scr = scope.root
|
|
343
|
+
W, H = scope.size
|
|
344
|
+
kept = scope.store()
|
|
345
|
+
info = scope.launcher.info
|
|
346
|
+
# Dark whether or not the shell put a dark theme on the display.
|
|
347
|
+
scr.set_style_bg_color(ui.BG, 0)
|
|
348
|
+
scr.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
349
|
+
# A round panel gets its own layout when Home has the whole screen.
|
|
350
|
+
round_ = W == H and getattr(scope, "rect", (0, 0, W, H))[:2] == (0, 0) and is_round()
|
|
351
|
+
|
|
352
|
+
if round_:
|
|
353
|
+
# The square inside the circle holds the pages and their tabs.
|
|
354
|
+
inner = W // 2 - ROUND_MARGIN
|
|
355
|
+
side = int(inner * 1.4142) & ~1
|
|
356
|
+
x0 = (W - side) // 2
|
|
357
|
+
tab_bar = ui.small.line_height + 14
|
|
358
|
+
else:
|
|
359
|
+
tab_bar = tab_height(scope)
|
|
360
|
+
# With the status bar's header, its title is the Home icon and the pages
|
|
361
|
+
# take the whole area. Without it, Home draws its own row of TOP pixels.
|
|
362
|
+
header = None if round_ else getattr(scope, "header", None)
|
|
363
|
+
top = 0 if header is not None else TOP
|
|
364
|
+
if not round_ and header is None:
|
|
365
|
+
title = lvicons.image(scr, "home", 32, ui.ACCENT)
|
|
366
|
+
title.set_pos(GAP + 4, (TOP - 32) // 2)
|
|
367
|
+
drop = _below_cap(scope, title, W - GAP)
|
|
368
|
+
if drop:
|
|
369
|
+
title.set_y((TOP - 32) // 2 + drop)
|
|
370
|
+
top += drop
|
|
371
|
+
|
|
372
|
+
tv = lv.tabview(scr)
|
|
373
|
+
if round_:
|
|
374
|
+
tv.set_pos(x0, x0)
|
|
375
|
+
tv.set_size(side, side)
|
|
376
|
+
else:
|
|
377
|
+
tv.set_pos(0, top)
|
|
378
|
+
tv.set_size(W, H - top)
|
|
379
|
+
tv.set_tab_bar_position(lv.DIR.BOTTOM)
|
|
380
|
+
tv.set_tab_bar_size(tab_bar)
|
|
381
|
+
tv.set_style_bg_color(ui.BG, 0)
|
|
382
|
+
tv.get_content().set_style_bg_color(ui.BG, 0)
|
|
383
|
+
|
|
384
|
+
pages = _pages(info, scope.launcher.hidden())
|
|
385
|
+
# The display's shape, not the area under the status bar, picks the grid.
|
|
386
|
+
disp = lv.display_get_default()
|
|
387
|
+
shape = (disp.get_horizontal_resolution(), disp.get_vertical_resolution()) if disp else (W, H)
|
|
388
|
+
cols, rows = (2, 2) if round_ else grid_shape(*shape)
|
|
389
|
+
# Every tab keeps the dots' row when one of them needs it, so the tiles
|
|
390
|
+
# are the same size on every tab.
|
|
391
|
+
dots = DOTS if any(len(apps) > cols * rows for _, apps in pages) else 0
|
|
392
|
+
tabs = []
|
|
393
|
+
for name, apps in pages:
|
|
394
|
+
page = tv.add_tab(name)
|
|
395
|
+
page.set_style_pad_all(0, 0)
|
|
396
|
+
page.set_style_bg_color(ui.BG, 0)
|
|
397
|
+
page.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
398
|
+
if round_:
|
|
399
|
+
tabs.append(_Tab(scope, page, side, side - tab_bar, apps, cols, rows, True, dots))
|
|
400
|
+
else:
|
|
401
|
+
tabs.append(_Tab(scope, page, W, H - top - tab_bar, apps, cols, rows, False, dots))
|
|
402
|
+
|
|
403
|
+
bar = tv.get_tab_bar()
|
|
404
|
+
if round_:
|
|
405
|
+
# Four labels share the square's width: the larger font if its tab is wide enough for "Video", else the smaller.
|
|
406
|
+
tab_font = ui.small if side // max(1, len(pages)) >= 4 * ui.small.line_height else ui.tiny
|
|
407
|
+
else:
|
|
408
|
+
# The status bar's title font, or the largest that leaves the tab room.
|
|
409
|
+
tab_font = getattr(getattr(scope, "bar", None), "title_font", None)
|
|
410
|
+
if tab_font is None:
|
|
411
|
+
tab_font = ui.font if ui.font.line_height + 8 <= tab_bar else ui.small
|
|
412
|
+
bar.set_style_bg_color(ui.PANEL, 0)
|
|
413
|
+
bar.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
414
|
+
bar.set_style_border_side(lv.BORDER_SIDE.TOP, 0)
|
|
415
|
+
bar.set_style_border_width(1, 0)
|
|
416
|
+
bar.set_style_border_color(lv.color_hex(LINE), 0)
|
|
417
|
+
on = lv.STATE.CHECKED
|
|
418
|
+
stripe = 3 if tab_bar < 40 else 4
|
|
419
|
+
for i in range(bar.get_child_count()):
|
|
420
|
+
t = bar.get_child(i)
|
|
421
|
+
t.set_style_radius(0, 0)
|
|
422
|
+
t.set_style_pad_ver(0, 0)
|
|
423
|
+
t.set_style_text_font(tab_font, 0)
|
|
424
|
+
t.set_style_text_color(ui.MUTED, 0)
|
|
425
|
+
t.set_style_bg_opa(lv.OPA.TRANSP, 0)
|
|
426
|
+
t.set_style_border_width(0, 0)
|
|
427
|
+
t.set_style_shadow_width(0, 0)
|
|
428
|
+
# the active tab: a lighter fill and an accent stripe along its top edge
|
|
429
|
+
t.set_style_text_color(ui.WHITE, on)
|
|
430
|
+
t.set_style_bg_color(lv.color_hex(TAB_ON), on)
|
|
431
|
+
t.set_style_bg_opa(lv.OPA.COVER, on)
|
|
432
|
+
t.set_style_border_side(lv.BORDER_SIDE.TOP, on)
|
|
433
|
+
t.set_style_border_width(stripe, on)
|
|
434
|
+
t.set_style_border_color(ui.ACCENT, on)
|
|
435
|
+
if not round_ and not _labels_clear(tv, bar):
|
|
436
|
+
# The labels touch at this width: a smaller font keeps them apart.
|
|
437
|
+
for font in (ui.small, ui.tiny):
|
|
438
|
+
if font.line_height >= tab_font.line_height:
|
|
439
|
+
continue
|
|
440
|
+
tab_font = font
|
|
441
|
+
for i in range(bar.get_child_count()):
|
|
442
|
+
bar.get_child(i).set_style_text_font(font, 0)
|
|
443
|
+
if _labels_clear(tv, bar):
|
|
444
|
+
break
|
|
445
|
+
|
|
446
|
+
def line_up(active):
|
|
447
|
+
# The tabs either side show the pages a swipe reaches next: the
|
|
448
|
+
# last page of the tabs before, the first page of the tabs after.
|
|
449
|
+
for i, t in enumerate(tabs):
|
|
450
|
+
if i != active:
|
|
451
|
+
t.show(t.last() if i < active else 0)
|
|
452
|
+
|
|
453
|
+
def turned(k):
|
|
454
|
+
kept["page"] = k
|
|
455
|
+
|
|
456
|
+
tv.update_layout()
|
|
457
|
+
tab = kept.get("tab", 0)
|
|
458
|
+
if not 0 <= tab < len(pages):
|
|
459
|
+
tab = 0
|
|
460
|
+
if tab:
|
|
461
|
+
tv.set_active(tab, False) # no animation
|
|
462
|
+
if tabs:
|
|
463
|
+
tabs[tab].show(kept.get("page", 0))
|
|
464
|
+
line_up(tab)
|
|
465
|
+
for t in tabs:
|
|
466
|
+
t.on_turn = turned
|
|
467
|
+
|
|
468
|
+
def tapped(i):
|
|
469
|
+
def cb(e):
|
|
470
|
+
tabs[i].show(0)
|
|
471
|
+
kept["page"] = 0
|
|
472
|
+
return cb
|
|
473
|
+
|
|
474
|
+
for i in range(min(bar.get_child_count(), len(tabs))):
|
|
475
|
+
bar.get_child(i).add_event_cb(tapped(i), lv.EVENT.CLICKED, None)
|
|
476
|
+
|
|
477
|
+
def changed(e):
|
|
478
|
+
active = tv.get_tab_active()
|
|
479
|
+
kept["tab"] = active
|
|
480
|
+
kept["page"] = tabs[active].at
|
|
481
|
+
line_up(active)
|
|
482
|
+
|
|
483
|
+
tv.add_event_cb(changed, lv.EVENT.VALUE_CHANGED, None)
|
apps/home/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "home", "title": "Home", "tile": false}
|
apps/home/main.py
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Start Home when the board starts: the board's main.py, for the apps in /apps.
|
|
5
|
+
|
|
6
|
+
Put it on the board with
|
|
7
|
+
``omip.install("github:PyDevices/apps/apps/home/main.py", target="/")``.
|
|
8
|
+
|
|
9
|
+
A round screen, or one under 320 pixels wide or 240 tall (a 240 by 320 portrait
|
|
10
|
+
one too), opens on Watch instead, where Watch is installed: a watch face, then a wheel of the same
|
|
11
|
+
apps. To choose for yourself, set ``HOME`` to ``"home"`` or ``"watch"``.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import appkit
|
|
15
|
+
|
|
16
|
+
HOME = None # None: Watch on a round screen or one under 320 by 240, else Home
|
|
17
|
+
|
|
18
|
+
# A script app Home started runs here, before the display opens. Where timers
|
|
19
|
+
# run it in the background, this returns True and Home comes back when it quits.
|
|
20
|
+
if not appkit.run_pending_script():
|
|
21
|
+
from display_driver import app
|
|
22
|
+
from appkit.shell import fits_home
|
|
23
|
+
from touchkit import net, shell
|
|
24
|
+
|
|
25
|
+
shell.quiet_app_timers(app)
|
|
26
|
+
launcher = shell.TouchLauncher(app, home="home")
|
|
27
|
+
launcher.scan("apps")
|
|
28
|
+
if HOME is not None:
|
|
29
|
+
launcher.home = HOME
|
|
30
|
+
elif "watch" in launcher.names and not fits_home():
|
|
31
|
+
launcher.home = "watch"
|
|
32
|
+
launcher.shell = shell.TouchShell(launcher)
|
|
33
|
+
launcher.boot(launcher.home)
|
|
34
|
+
# Join a known network and start WebREPL, now the display is up.
|
|
35
|
+
net.boot()
|
|
36
|
+
appkit.serve()
|