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/mp3/__init__.py
ADDED
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""MP3 player: the songs in a folder, with the spectrum of what plays.
|
|
5
|
+
|
|
6
|
+
On a computer the songs are in ``$MP3_DIR``, else ``~/music``. On a board
|
|
7
|
+
they're in a ``music`` folder: ``/sd/music`` on the SD card, ``/music`` on
|
|
8
|
+
flash and ``/data/music``, all three in one list (`appkit.places`).
|
|
9
|
+
|
|
10
|
+
the archived pydevices-examples' mp3_from_sd, with buttons: play and stop, previous and
|
|
11
|
+
next, volume. A song that ends goes on to the next one. On a board the card is mounted
|
|
12
|
+
read-only (its writes are unreliable on this board) and only while the app
|
|
13
|
+
is open.
|
|
14
|
+
|
|
15
|
+
It plays to the sound output chosen for the whole device (``audio.out`` in
|
|
16
|
+
the connections picker), and choosing another while a song plays moves the
|
|
17
|
+
song there: it starts again from the top on the new output.
|
|
18
|
+
"""
|
|
19
|
+
|
|
20
|
+
import os
|
|
21
|
+
|
|
22
|
+
import lvgl as lv
|
|
23
|
+
from multimer import ticks_diff, ticks_ms
|
|
24
|
+
|
|
25
|
+
import spectrum
|
|
26
|
+
from appkit import connections
|
|
27
|
+
from appkit import data as appdata
|
|
28
|
+
from appkit import places
|
|
29
|
+
from touchkit import ui
|
|
30
|
+
|
|
31
|
+
MUSIC = "music" # the folder name, on the card, flash and the data root
|
|
32
|
+
VOLUME = 80 # ES8311 steps of 0.5 dB: 80 is -10 dB
|
|
33
|
+
TOP = 132 # the spectrum's first row, in the app's area
|
|
34
|
+
MIN_H = 48 # the shortest spectrum worth drawing
|
|
35
|
+
|
|
36
|
+
state = None # the open player's state, for the console
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _env(name):
|
|
40
|
+
fn = getattr(os, "getenv", None)
|
|
41
|
+
return fn(name) if fn is not None else None
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def _home():
|
|
45
|
+
return (_env("USERPROFILE") or _env("HOME") or "").replace("\\", "/")
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def music_folder():
|
|
49
|
+
"""A computer's songs' folder: ``$MP3_DIR`` or ``~/music``."""
|
|
50
|
+
return _env("MP3_DIR") or _home() + "/music"
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def main(scope):
|
|
54
|
+
try:
|
|
55
|
+
import audiomp3
|
|
56
|
+
except ImportError as e:
|
|
57
|
+
ui.missing(scope, "missing: audiomp3", "The MP3 player needs audiomp3, the board's MP3 decoder, and an SD card: %s." % (e,))
|
|
58
|
+
return
|
|
59
|
+
try:
|
|
60
|
+
import board_peripherals as bp
|
|
61
|
+
except ImportError:
|
|
62
|
+
bp = None
|
|
63
|
+
if getattr(bp, "audio_out", None) is None:
|
|
64
|
+
ui.missing(scope, "missing: audio out", "The MP3 player needs a board_peripherals module with an audio_out role, which this board's config doesn't have.")
|
|
65
|
+
return
|
|
66
|
+
from audiodev import AudioFormat
|
|
67
|
+
|
|
68
|
+
scr = scope.root
|
|
69
|
+
status = ui.status(scope)
|
|
70
|
+
W, H = scope.size
|
|
71
|
+
hdr = getattr(scope, "header", None) or scr
|
|
72
|
+
if appdata.desktop():
|
|
73
|
+
folder = music_folder()
|
|
74
|
+
try:
|
|
75
|
+
names = sorted(os.listdir(folder))
|
|
76
|
+
except OSError:
|
|
77
|
+
names = []
|
|
78
|
+
songs = [folder + "/" + n for n in names if n.lower().endswith(".mp3")]
|
|
79
|
+
else:
|
|
80
|
+
places.hold_card(scope) # read-only, while the app is open
|
|
81
|
+
folder = places.where_text(MUSIC)
|
|
82
|
+
songs = places.files(MUSIC, (".mp3",))
|
|
83
|
+
global state
|
|
84
|
+
st = state = {"i": 0, "out": None, "file": None, "song": None, "meter": None, "fmt": None, "vol": VOLUME,
|
|
85
|
+
"playing": False, "device": None}
|
|
86
|
+
|
|
87
|
+
title = ui.label(scr, "", ui.font, ui.WHITE)
|
|
88
|
+
title.set_pos(16, 84)
|
|
89
|
+
title.set_width(W - 32)
|
|
90
|
+
title.set_long_mode(lv.label.LONG_MODE.DOTS)
|
|
91
|
+
|
|
92
|
+
def release_song():
|
|
93
|
+
if st["meter"] is not None:
|
|
94
|
+
spectrum.stop(st["meter"])
|
|
95
|
+
st["meter"] = None
|
|
96
|
+
if st["out"] is not None:
|
|
97
|
+
st["out"].stop()
|
|
98
|
+
if st["file"] is not None:
|
|
99
|
+
st["file"].close()
|
|
100
|
+
st["file"] = None
|
|
101
|
+
st["song"] = None
|
|
102
|
+
|
|
103
|
+
def close_out():
|
|
104
|
+
if st["out"] is not None:
|
|
105
|
+
st["out"].detach()
|
|
106
|
+
st["out"].close()
|
|
107
|
+
st["out"] = None
|
|
108
|
+
|
|
109
|
+
def close():
|
|
110
|
+
st["playing"] = False
|
|
111
|
+
release_song()
|
|
112
|
+
close_out()
|
|
113
|
+
|
|
114
|
+
scope.on_close(close)
|
|
115
|
+
|
|
116
|
+
def open_out(fmt_out):
|
|
117
|
+
# A computer names the device chosen in the picker; a board's
|
|
118
|
+
# audio_out plays wherever its own choice routes it.
|
|
119
|
+
kwargs = {} if st["device"] is None else {"device": st["device"]}
|
|
120
|
+
try:
|
|
121
|
+
# A player can trade latency for fewer dropouts: a board
|
|
122
|
+
# with a choice buffers more.
|
|
123
|
+
return bp.audio_out(fmt_out, latency="buffered", **kwargs)
|
|
124
|
+
except TypeError: # an audio_out that takes no latency
|
|
125
|
+
return bp.audio_out(fmt_out, **kwargs)
|
|
126
|
+
|
|
127
|
+
def moved(endpoints):
|
|
128
|
+
# Another output was chosen: what plays starts again there.
|
|
129
|
+
st["device"] = connections.device(endpoints)
|
|
130
|
+
if st["out"] is None:
|
|
131
|
+
return
|
|
132
|
+
playing = st["playing"]
|
|
133
|
+
release_song()
|
|
134
|
+
close_out()
|
|
135
|
+
if playing:
|
|
136
|
+
play()
|
|
137
|
+
|
|
138
|
+
st["device"] = connections.device(scope.follow("audio.out", moved))
|
|
139
|
+
|
|
140
|
+
def play(i=None):
|
|
141
|
+
if not songs:
|
|
142
|
+
return
|
|
143
|
+
if i is not None:
|
|
144
|
+
st["i"] = i % len(songs)
|
|
145
|
+
release_song()
|
|
146
|
+
path = songs[st["i"]]
|
|
147
|
+
name = path.rsplit("/", 1)[-1]
|
|
148
|
+
f = open(path, "rb")
|
|
149
|
+
st["file"] = f
|
|
150
|
+
song = audiomp3.MP3Decoder(f)
|
|
151
|
+
st["song"] = song
|
|
152
|
+
fmt = (song.sample_rate, song.channel_count)
|
|
153
|
+
if st["out"] is not None and st["fmt"] != fmt:
|
|
154
|
+
close_out()
|
|
155
|
+
if st["out"] is None:
|
|
156
|
+
st["out"] = open_out(AudioFormat(song.sample_rate, song.channel_count, 16))
|
|
157
|
+
# service() refills the decoder's file buffer from this thread
|
|
158
|
+
# (the pump on the other core can't read the card): on the app's
|
|
159
|
+
# timer, so it stops when the app closes.
|
|
160
|
+
st["out"].attach(scope)
|
|
161
|
+
st["fmt"] = fmt
|
|
162
|
+
out = st["out"]
|
|
163
|
+
out.set_volume(st["vol"])
|
|
164
|
+
out.play(song)
|
|
165
|
+
st["playing"] = True
|
|
166
|
+
st["started"] = ticks_ms()
|
|
167
|
+
title.set_text("%d/%d %s (%d Hz, %s)" % (st["i"] + 1, len(songs), name[:-4], song.sample_rate, "stereo" if song.channel_count == 2 else "mono"))
|
|
168
|
+
play_lbl.set_text(lv.SYMBOL.STOP + " Stop")
|
|
169
|
+
if not getattr(out, "pumped", False):
|
|
170
|
+
status.set_text("no spectrum: not on the audio pump")
|
|
171
|
+
return
|
|
172
|
+
try:
|
|
173
|
+
from spectrum.analyzer import levels_for
|
|
174
|
+
except ImportError as e: # the spectrum draws with pygraphics
|
|
175
|
+
status.set_text("no spectrum: %s" % (e,))
|
|
176
|
+
return
|
|
177
|
+
from board_config import display_drv
|
|
178
|
+
|
|
179
|
+
if not display_drv.framebuffers():
|
|
180
|
+
status.set_text("no spectrum: the display has no framebuffer")
|
|
181
|
+
return
|
|
182
|
+
if scope.rect[3] - TOP < MIN_H:
|
|
183
|
+
status.set_text("no spectrum: the screen is too short")
|
|
184
|
+
return
|
|
185
|
+
m = spectrum.meter(scope, levels_for(out), TOP)
|
|
186
|
+
st["meter"] = m
|
|
187
|
+
spectrum.start(m, scope, (hdr,))
|
|
188
|
+
|
|
189
|
+
def stop():
|
|
190
|
+
st["playing"] = False
|
|
191
|
+
release_song()
|
|
192
|
+
play_lbl.set_text(lv.SYMBOL.PLAY + " Play")
|
|
193
|
+
|
|
194
|
+
def toggle():
|
|
195
|
+
if st["playing"]:
|
|
196
|
+
stop()
|
|
197
|
+
else:
|
|
198
|
+
play()
|
|
199
|
+
|
|
200
|
+
def volume(step):
|
|
201
|
+
st["vol"] = max(0, min(100, st["vol"] + step))
|
|
202
|
+
if st["out"] is not None:
|
|
203
|
+
st["out"].set_volume(st["vol"])
|
|
204
|
+
vol_lbl.set_text("%d%%" % st["vol"])
|
|
205
|
+
|
|
206
|
+
y = 12
|
|
207
|
+
b, _ = ui.button(scr, lv.SYMBOL.PREV, lambda: play(st["i"] - 1), w=90, h=60, font=ui.big)
|
|
208
|
+
b.set_pos(16, y)
|
|
209
|
+
b, play_lbl = ui.button(scr, lv.SYMBOL.PLAY + " Play", toggle, w=180, h=60, font=ui.big)
|
|
210
|
+
b.set_pos(118, y)
|
|
211
|
+
b, _ = ui.button(scr, lv.SYMBOL.NEXT, lambda: play(st["i"] + 1), w=90, h=60, font=ui.big)
|
|
212
|
+
b.set_pos(310, y)
|
|
213
|
+
b, _ = ui.button(scr, lv.SYMBOL.VOLUME_MID, lambda: volume(-5), w=90, h=60, font=ui.big)
|
|
214
|
+
b.set_pos(W - 16 - 90 - 100 - 90, y)
|
|
215
|
+
vol_lbl = ui.label(scr, "%d%%" % st["vol"], ui.big, ui.WHITE)
|
|
216
|
+
vol_lbl.set_pos(W - 16 - 90 - 92, y + 14)
|
|
217
|
+
b, _ = ui.button(scr, lv.SYMBOL.VOLUME_MAX, lambda: volume(5), w=90, h=60, font=ui.big)
|
|
218
|
+
b.set_pos(W - 16 - 90, y)
|
|
219
|
+
|
|
220
|
+
if not songs:
|
|
221
|
+
status.set_text("no songs")
|
|
222
|
+
title.set_text("No songs. Put .mp3 files in %s." % folder)
|
|
223
|
+
return
|
|
224
|
+
|
|
225
|
+
def tick(t):
|
|
226
|
+
out = st["out"]
|
|
227
|
+
if (st["playing"] and out is not None and st["song"] is not None
|
|
228
|
+
and ticks_diff(ticks_ms(), st["started"]) > 3000):
|
|
229
|
+
# A song that has run out: the pump stops pulling it.
|
|
230
|
+
from audiodev import pump
|
|
231
|
+
|
|
232
|
+
h = pump.health() or {}
|
|
233
|
+
if not h.get("running") and not out.paused:
|
|
234
|
+
play(st["i"] + 1)
|
|
235
|
+
return
|
|
236
|
+
status.set_text("playing" if st["playing"] else "stopped")
|
|
237
|
+
|
|
238
|
+
title.set_text("%d song%s in %s" % (len(songs), "" if len(songs) == 1 else "s", folder))
|
|
239
|
+
scope.after(300, lambda t: play(0))
|
|
240
|
+
scope.every(1000, tick)
|
apps/mp3/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "mp3", "title": "MP3 player", "category": "Audio", "icon": "audio_file", "color": "#3B6E2A"}
|
apps/perch/__init__.py
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Huey's Perch: Huey the chameleon at the coast, a workbench and a desk, drawn as vectors.
|
|
5
|
+
|
|
6
|
+
Every picture is shapes built in Python and drawn by svgio at this screen's
|
|
7
|
+
size. Touch the chameleon and he answers. Touch anywhere else for four
|
|
8
|
+
buttons: the next place, the next season or time of day (at the workbench,
|
|
9
|
+
the next set of colours), a closer view of the same drawing, and something
|
|
10
|
+
for him to do.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
import lvgl as lv
|
|
14
|
+
from appkit import glass
|
|
15
|
+
|
|
16
|
+
from .stage import TICK_MS, Stage
|
|
17
|
+
|
|
18
|
+
_DOCK_TICKS = 4000 // TICK_MS # the buttons stay this long after the last touch
|
|
19
|
+
_FADE_TICKS = 8
|
|
20
|
+
_GLASS = glass.GLASS
|
|
21
|
+
_TURNS = ("tongue", "stroll", "hold", "turn", "look") # what the star asks for, by turns
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
class _Dock:
|
|
25
|
+
"""Four round buttons down the right side, there when touched and gone soon after.
|
|
26
|
+
|
|
27
|
+
The chameleon keeps to the left and the middle of every place, so this
|
|
28
|
+
side is the one he is never behind.
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self, root, size, actions):
|
|
32
|
+
w, h = size
|
|
33
|
+
side = glass.side(w, h)
|
|
34
|
+
gap = side // 4
|
|
35
|
+
self.bar = glass.pane(lv.obj(root))
|
|
36
|
+
self.bar.set_size(side + 2 * gap, len(actions) * side + (len(actions) + 1) * gap)
|
|
37
|
+
self.bar.set_style_radius(lv.RADIUS_CIRCLE, 0)
|
|
38
|
+
# clear of a round screen's edge
|
|
39
|
+
self.bar.align(lv.ALIGN.RIGHT_MID, -max(8, w // 28), 0)
|
|
40
|
+
self.buttons = []
|
|
41
|
+
for i, (icon, action) in enumerate(actions):
|
|
42
|
+
button = lv.obj(self.bar)
|
|
43
|
+
glass.key(button, icon)
|
|
44
|
+
button.set_size(side, side)
|
|
45
|
+
button.set_pos(gap, gap + i * (side + gap))
|
|
46
|
+
button.set_style_radius(lv.RADIUS_CIRCLE, 0)
|
|
47
|
+
button.add_event_cb(self._pressed(action), lv.EVENT.CLICKED, None)
|
|
48
|
+
self.buttons.append(button)
|
|
49
|
+
self.left = 0
|
|
50
|
+
self.bar.add_flag(lv.obj.FLAG.HIDDEN)
|
|
51
|
+
|
|
52
|
+
def _pressed(self, action):
|
|
53
|
+
def on_click(_event):
|
|
54
|
+
self.show()
|
|
55
|
+
action()
|
|
56
|
+
|
|
57
|
+
return on_click
|
|
58
|
+
|
|
59
|
+
def show(self):
|
|
60
|
+
self.left = _DOCK_TICKS
|
|
61
|
+
self.bar.set_style_opa(255, 0)
|
|
62
|
+
self.bar.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
63
|
+
|
|
64
|
+
def tick(self):
|
|
65
|
+
if self.left <= 0:
|
|
66
|
+
return
|
|
67
|
+
self.left -= 1
|
|
68
|
+
if self.left == 0:
|
|
69
|
+
self.bar.add_flag(lv.obj.FLAG.HIDDEN)
|
|
70
|
+
elif self.left < _FADE_TICKS:
|
|
71
|
+
self.bar.set_style_opa(255 * self.left // _FADE_TICKS, 0)
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
def main(scope):
|
|
75
|
+
root = scope.root
|
|
76
|
+
root.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
77
|
+
root.set_style_pad_all(0, 0)
|
|
78
|
+
root.set_style_border_width(0, 0)
|
|
79
|
+
root.set_style_bg_color(lv.color_hex(_GLASS), 0)
|
|
80
|
+
root.set_style_bg_opa(255, 0)
|
|
81
|
+
stage = Stage(root, scope.size)
|
|
82
|
+
turn = [-1]
|
|
83
|
+
|
|
84
|
+
def something():
|
|
85
|
+
turn[0] = (turn[0] + 1) % len(_TURNS)
|
|
86
|
+
stage.cues.append(_TURNS[turn[0]])
|
|
87
|
+
|
|
88
|
+
dock = _Dock(
|
|
89
|
+
root,
|
|
90
|
+
scope.size,
|
|
91
|
+
(
|
|
92
|
+
("photo_library", stage.next_place),
|
|
93
|
+
("wb_sunny", stage.next_variant),
|
|
94
|
+
("search", stage.next_view),
|
|
95
|
+
("star", something),
|
|
96
|
+
),
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
point = lv.point_t()
|
|
100
|
+
|
|
101
|
+
def touched(_event):
|
|
102
|
+
indev = lv.indev_active()
|
|
103
|
+
if indev is None:
|
|
104
|
+
return
|
|
105
|
+
indev.get_point(point)
|
|
106
|
+
if not stage.tap(point.x, point.y):
|
|
107
|
+
dock.show()
|
|
108
|
+
|
|
109
|
+
root.add_flag(lv.obj.FLAG.CLICKABLE)
|
|
110
|
+
root.add_event_cb(touched, lv.EVENT.CLICKED, None)
|
|
111
|
+
|
|
112
|
+
def tick(_timer=None):
|
|
113
|
+
stage.tick()
|
|
114
|
+
dock.tick()
|
|
115
|
+
|
|
116
|
+
scope.every(TICK_MS, tick)
|
|
117
|
+
scope.on_close(stage.close)
|
|
118
|
+
# for whoever drives the app from outside: a test, a screenshot script
|
|
119
|
+
scope.perch = (stage, dock)
|
apps/perch/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "perch", "title": "Huey's Perch", "category": "Desk", "icon": "photo_library", "color": "#2F8F5B", "needs": ["svgio.expand", "svgio.Buffer"], "bar": "none"}
|