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/weather/__init__.py
ADDED
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Weather: conditions and five days ahead, laid out to fit a round screen.
|
|
5
|
+
|
|
6
|
+
It was drawn for a 480-pixel round screen, and on a smaller one everything
|
|
7
|
+
shrinks with it (`sizing`), so the same layout fits a 240-pixel watch face.
|
|
8
|
+
|
|
9
|
+
Until you choose a place it shows the city the board's IP address is in,
|
|
10
|
+
marked with a location pin. Swipe up for the five days and down to come back.
|
|
11
|
+
Hold your finger on the screen to choose a ZIP code or change the units.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import lvgl as lv
|
|
15
|
+
from appkit.shell import is_round
|
|
16
|
+
from deskkit import forecast, localtime
|
|
17
|
+
|
|
18
|
+
from . import icons, sizing
|
|
19
|
+
from .zippad import ZipPad
|
|
20
|
+
|
|
21
|
+
_BG_DAY = 0x123A5E
|
|
22
|
+
_BG_NIGHT = 0x0A1020
|
|
23
|
+
_WHITE = 0xFFFFFF
|
|
24
|
+
_SOFT = 0xB9C6D4
|
|
25
|
+
_RAIN = 0x57B6FF
|
|
26
|
+
_ICON = 130
|
|
27
|
+
_SMALL_ICON = 44
|
|
28
|
+
_BIG_TEMP_SCALE = 512 # the largest compiled font, doubled, at full size
|
|
29
|
+
# The temperature's font: 40 px, or the largest a firmware without it has.
|
|
30
|
+
_TEMP = getattr(lv, "font_montserrat_40", None) or getattr(lv, "font_montserrat_32", lv.font_montserrat_24)
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _clean(obj):
|
|
34
|
+
obj.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
35
|
+
obj.set_style_pad_all(0, 0)
|
|
36
|
+
obj.set_style_border_width(0, 0)
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def _label(parent, font, color=_WHITE):
|
|
40
|
+
label = lv.label(parent)
|
|
41
|
+
label.set_style_text_font(font, 0)
|
|
42
|
+
label.set_style_text_color(lv.color_hex(color), 0)
|
|
43
|
+
label.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
44
|
+
return label
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
class _Screen:
|
|
48
|
+
def __init__(self, scope):
|
|
49
|
+
self.scope = scope
|
|
50
|
+
self.root = scope.root
|
|
51
|
+
self.w, self.h = scope.size
|
|
52
|
+
self.pad = None
|
|
53
|
+
self.showing_days = False
|
|
54
|
+
_clean(self.root)
|
|
55
|
+
self.root.add_event_cb(self._gesture, lv.EVENT.GESTURE, None)
|
|
56
|
+
self.root.add_event_cb(self._held, lv.EVENT.LONG_PRESSED, None)
|
|
57
|
+
self.now = None
|
|
58
|
+
self.days = None
|
|
59
|
+
self.k = sizing.scale(self.w, self.h)
|
|
60
|
+
self.round = is_round()
|
|
61
|
+
self.top = 0 # where the words may start: below the Home button, if it's over the screen
|
|
62
|
+
self.notice = _label(self.root, sizing.font(24 * self.k, 16), _SOFT)
|
|
63
|
+
self.notice.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
64
|
+
self.notice.set_width(self.w * 7 // 10)
|
|
65
|
+
self.notice.set_long_mode(lv.label.LONG_MODE.WRAP)
|
|
66
|
+
self.notice.center()
|
|
67
|
+
|
|
68
|
+
def _panel(self, background):
|
|
69
|
+
panel = lv.obj(self.root)
|
|
70
|
+
_clean(panel)
|
|
71
|
+
panel.set_size(self.w, self.h)
|
|
72
|
+
panel.set_style_radius(0, 0)
|
|
73
|
+
panel.set_style_bg_color(lv.color_hex(background), 0)
|
|
74
|
+
panel.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
75
|
+
return panel
|
|
76
|
+
|
|
77
|
+
def _drop(self, attr):
|
|
78
|
+
panel = getattr(self, attr)
|
|
79
|
+
if panel is not None:
|
|
80
|
+
panel.delete()
|
|
81
|
+
setattr(self, attr, None)
|
|
82
|
+
|
|
83
|
+
def show(self):
|
|
84
|
+
"""Draw what's known. Rebuilt whole: it changes twice an hour at most."""
|
|
85
|
+
self.top = sizing.below_home(self.scope)
|
|
86
|
+
self._drop("now")
|
|
87
|
+
self._drop("days")
|
|
88
|
+
place = forecast.current()
|
|
89
|
+
data = forecast.latest
|
|
90
|
+
if self.pad is not None:
|
|
91
|
+
return
|
|
92
|
+
if place is None:
|
|
93
|
+
if localtime.finding():
|
|
94
|
+
self.notice.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
95
|
+
self.notice.set_text("Finding where you are")
|
|
96
|
+
return
|
|
97
|
+
self.ask_for_zip()
|
|
98
|
+
return
|
|
99
|
+
if data is None:
|
|
100
|
+
self.notice.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
101
|
+
if forecast.last_error is None:
|
|
102
|
+
self.notice.set_text("Getting the weather")
|
|
103
|
+
else:
|
|
104
|
+
self.notice.set_text("Can't reach the weather service. Trying again soon.")
|
|
105
|
+
return
|
|
106
|
+
self.notice.add_flag(lv.obj.FLAG.HIDDEN)
|
|
107
|
+
background = _BG_DAY if data["is_day"] else _BG_NIGHT
|
|
108
|
+
self.root.set_style_bg_color(lv.color_hex(background), 0)
|
|
109
|
+
self._build_now(place, data, background)
|
|
110
|
+
self._build_days(data, background)
|
|
111
|
+
self._apply_page()
|
|
112
|
+
|
|
113
|
+
def _build_now(self, place, data, background):
|
|
114
|
+
# A column centred on the screen, where a round one is widest: the
|
|
115
|
+
# place, the icon, the temperature, its words, the day's range.
|
|
116
|
+
k = self.k
|
|
117
|
+
panel = self.now = self._panel(background)
|
|
118
|
+
name = _label(panel, sizing.font(16 * k))
|
|
119
|
+
name.set_style_text_color(lv.color_hex(_SOFT), 0)
|
|
120
|
+
if place.get("from_ip"):
|
|
121
|
+
name.set_text(lv.SYMBOL.GPS + " " + place["name"])
|
|
122
|
+
else:
|
|
123
|
+
name.set_text(place["name"])
|
|
124
|
+
|
|
125
|
+
icon_size = int(_ICON * k)
|
|
126
|
+
icon = icons.make(panel, data["code"], data["is_day"], icon_size, background)
|
|
127
|
+
|
|
128
|
+
temp = _label(panel, _TEMP)
|
|
129
|
+
temp.set_text("%d°" % forecast.degrees(data["temp"]))
|
|
130
|
+
temp_scale = int(_BIG_TEMP_SCALE * k)
|
|
131
|
+
temp.set_style_transform_scale(temp_scale, 0)
|
|
132
|
+
temp.update_layout()
|
|
133
|
+
temp.set_style_transform_pivot_x(temp.get_width() // 2, 0)
|
|
134
|
+
temp.set_style_transform_pivot_y(temp.get_height() // 2, 0)
|
|
135
|
+
|
|
136
|
+
words = _label(panel, sizing.font(24 * k, 16))
|
|
137
|
+
words.set_text(icons.name(data["code"], data["is_day"]))
|
|
138
|
+
|
|
139
|
+
range_ = _label(panel, sizing.font(16 * k), _SOFT)
|
|
140
|
+
range_.set_text(
|
|
141
|
+
"H %d° L %d° Feels %d°"
|
|
142
|
+
% (
|
|
143
|
+
forecast.degrees(data["hi"]),
|
|
144
|
+
forecast.degrees(data["lo"]),
|
|
145
|
+
forecast.degrees(data["feels"]),
|
|
146
|
+
)
|
|
147
|
+
)
|
|
148
|
+
column = [(name, 0), (icon, 0), (temp, temp_scale), (words, 0), (range_, 0)]
|
|
149
|
+
if forecast.last_error is not None:
|
|
150
|
+
old = _label(panel, sizing.font(14 * k), _SOFT)
|
|
151
|
+
old.set_text("as of %s" % data["as_of"])
|
|
152
|
+
column.append((old, 0))
|
|
153
|
+
# Where the column is too tall for the screen (below the Home button
|
|
154
|
+
# on a small round one), the icon gives up the height.
|
|
155
|
+
while not self._stack(column, int(24 * k), max(4, int(6 * k))) and icon_size > 24:
|
|
156
|
+
icon_size -= 6
|
|
157
|
+
icon.delete()
|
|
158
|
+
icon = icons.make(panel, data["code"], data["is_day"], icon_size, background)
|
|
159
|
+
column[1] = (icon, 0)
|
|
160
|
+
|
|
161
|
+
def _stack(self, column, gap, least=2):
|
|
162
|
+
"""Put each ``(obj, transform_scale)`` under the last, *gap* apart,
|
|
163
|
+
the whole column centred on the screen and below the Home button.
|
|
164
|
+
The gap shrinks, down to *least*, until every line is on the screen,
|
|
165
|
+
and inside the circle on a round one. Returns whether it fits."""
|
|
166
|
+
sizes = []
|
|
167
|
+
for obj, scale in column:
|
|
168
|
+
obj.update_layout()
|
|
169
|
+
w, h = obj.get_width(), obj.get_height()
|
|
170
|
+
if scale:
|
|
171
|
+
# Drawn scaled about its middle; only the glyphs' cap height
|
|
172
|
+
# shows, so the line's empty top and bottom aren't counted.
|
|
173
|
+
w, h = w * scale // 256 + 1, h * scale * 3 // 1024 + 2
|
|
174
|
+
sizes.append((w, h))
|
|
175
|
+
while True:
|
|
176
|
+
y = max(self.top, (self.h - sum(h for _, h in sizes) - gap * (len(column) - 1)) // 2)
|
|
177
|
+
tops = []
|
|
178
|
+
fits = True
|
|
179
|
+
for w, h in sizes:
|
|
180
|
+
tops.append(y)
|
|
181
|
+
if w > 2 * sizing.half_width(self.w, self.h, self.round, y, y + h, 2) or y + h > self.h:
|
|
182
|
+
fits = False
|
|
183
|
+
y += h + gap
|
|
184
|
+
if fits or gap <= least:
|
|
185
|
+
break
|
|
186
|
+
gap = max(least, gap - 2)
|
|
187
|
+
for (obj, _scale), (_w, h), top in zip(column, sizes, tops):
|
|
188
|
+
obj.align(lv.ALIGN.TOP_MID, 0, top + (h - obj.get_height()) // 2)
|
|
189
|
+
return fits
|
|
190
|
+
|
|
191
|
+
def _build_days(self, data, background):
|
|
192
|
+
k = self.k
|
|
193
|
+
panel = self.days = self._panel(background)
|
|
194
|
+
big = sizing.font(24 * k, 16)
|
|
195
|
+
small = sizing.font(14 * k)
|
|
196
|
+
rows = len(data["days"])
|
|
197
|
+
clear = sizing.below_home(self.scope, centred=False) # the rows run edge to edge
|
|
198
|
+
pair = big.get_line_height() + small.get_line_height()
|
|
199
|
+
row_h = self.h * 15 // 100
|
|
200
|
+
if self.round:
|
|
201
|
+
row_h = min(row_h, self.h * 72 // 100 // rows)
|
|
202
|
+
# Clear of the Home button: the rows start below it and end as far
|
|
203
|
+
# from the bottom as they would without it.
|
|
204
|
+
bottom = self.h - max(clear, (self.h - row_h * rows) // 2)
|
|
205
|
+
top = max(clear, (self.h - row_h * rows) // 2)
|
|
206
|
+
row_h = (bottom - top) // rows
|
|
207
|
+
# Too tight for the rain under the temperatures: it goes beside them.
|
|
208
|
+
stacked = row_h >= pair
|
|
209
|
+
if not stacked:
|
|
210
|
+
row_h = max(row_h, big.get_line_height())
|
|
211
|
+
# Every row's ends line up, inside the circle at the first and last rows.
|
|
212
|
+
half = sizing.half_width(self.w, self.h, self.round, top, top + row_h * rows)
|
|
213
|
+
half = min(half, self.h * 6 // 10)
|
|
214
|
+
icon_size = max(20, min(int(_SMALL_ICON * k), row_h - 4))
|
|
215
|
+
right = -(self.w // 2 - half)
|
|
216
|
+
for i, (day, code, hi, lo, rain) in enumerate(data["days"]):
|
|
217
|
+
y = top + i * row_h
|
|
218
|
+
cy = y + row_h // 2 - self.h // 2
|
|
219
|
+
name = _label(panel, big)
|
|
220
|
+
name.set_text("Today" if i == 0 else day)
|
|
221
|
+
name.align(lv.ALIGN.LEFT_MID, self.w // 2 - half, cy)
|
|
222
|
+
|
|
223
|
+
icon = icons.make(panel, code, True, icon_size, background)
|
|
224
|
+
|
|
225
|
+
temps = _label(panel, big)
|
|
226
|
+
temps.set_text("%d° / %d°" % (forecast.degrees(hi), forecast.degrees(lo)))
|
|
227
|
+
chance = _label(panel, small, _RAIN)
|
|
228
|
+
chance.set_text("%d%%" % rain if not stacked else "%d%% rain" % rain)
|
|
229
|
+
if stacked:
|
|
230
|
+
icon.align(lv.ALIGN.CENTER, -half // 6, cy)
|
|
231
|
+
temps.align(lv.ALIGN.RIGHT_MID, right, cy - pair // 2 + big.get_line_height() // 2)
|
|
232
|
+
chance.align(lv.ALIGN.RIGHT_MID, right, cy + pair // 2 - small.get_line_height() // 2)
|
|
233
|
+
else:
|
|
234
|
+
chance.align(lv.ALIGN.RIGHT_MID, right, cy)
|
|
235
|
+
chance.update_layout()
|
|
236
|
+
temps.align(lv.ALIGN.RIGHT_MID, right - chance.get_width() - 6, cy)
|
|
237
|
+
temps.update_layout()
|
|
238
|
+
icon.align(lv.ALIGN.RIGHT_MID, right - chance.get_width() - temps.get_width() - 12, cy)
|
|
239
|
+
|
|
240
|
+
def _apply_page(self):
|
|
241
|
+
shown, hidden = (self.days, self.now) if self.showing_days else (self.now, self.days)
|
|
242
|
+
if shown is not None:
|
|
243
|
+
shown.remove_flag(lv.obj.FLAG.HIDDEN)
|
|
244
|
+
if hidden is not None:
|
|
245
|
+
hidden.add_flag(lv.obj.FLAG.HIDDEN)
|
|
246
|
+
|
|
247
|
+
def _gesture(self, _event):
|
|
248
|
+
direction = lv.indev_active().get_gesture_dir()
|
|
249
|
+
if direction == lv.DIR.TOP:
|
|
250
|
+
self.showing_days = True
|
|
251
|
+
elif direction == lv.DIR.BOTTOM:
|
|
252
|
+
self.showing_days = False
|
|
253
|
+
else:
|
|
254
|
+
return
|
|
255
|
+
lv.indev_active().wait_release() # or a slow swipe would also count as a hold
|
|
256
|
+
self._apply_page()
|
|
257
|
+
|
|
258
|
+
def _held(self, _event):
|
|
259
|
+
if self.pad is None:
|
|
260
|
+
self.ask_for_zip()
|
|
261
|
+
|
|
262
|
+
def ask_for_zip(self):
|
|
263
|
+
self.notice.add_flag(lv.obj.FLAG.HIDDEN)
|
|
264
|
+
self._drop("now")
|
|
265
|
+
self._drop("days")
|
|
266
|
+
self.pad = ZipPad(self.scope, self.w, self.h, self._zip_done)
|
|
267
|
+
|
|
268
|
+
def _zip_done(self):
|
|
269
|
+
self.pad.delete()
|
|
270
|
+
self.pad = None
|
|
271
|
+
self.show()
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
def main(scope):
|
|
275
|
+
screen = _Screen(scope)
|
|
276
|
+
forecast.place() # loads it, and with it the timezone
|
|
277
|
+
screen.show()
|
|
278
|
+
forecast.keep_fresh(scope, screen.show)
|
apps/weather/app.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"name": "weather", "title": "Weather", "category": "Desk", "icon": "wb_sunny", "color": "#2F6EA5", "bar": "none"}
|
apps/weather/icons.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Weather icons built from LVGL objects, so they scale to any size with no image files."""
|
|
5
|
+
|
|
6
|
+
import struct
|
|
7
|
+
|
|
8
|
+
import lvgl as lv
|
|
9
|
+
|
|
10
|
+
# A line's points are whole numbers or floats, as LVGL was built.
|
|
11
|
+
_probe = lv.point_precise_t()
|
|
12
|
+
_probe.x = 1.5
|
|
13
|
+
_POINT = "<ff" if _probe.x == 1.5 else "<ii"
|
|
14
|
+
_bolts = []
|
|
15
|
+
|
|
16
|
+
_SUN = 0xFFC533
|
|
17
|
+
_MOON = 0xDCE6F2
|
|
18
|
+
_CLOUD = 0xD5DEE8
|
|
19
|
+
_DARK_CLOUD = 0x8896A6
|
|
20
|
+
_RAIN = 0x57B6FF
|
|
21
|
+
_SNOW = 0xFFFFFF
|
|
22
|
+
_BOLT = 0xFFE14D
|
|
23
|
+
|
|
24
|
+
CLEAR, PARTLY, CLOUDY, FOG, DRIZZLE, RAIN, SNOW, STORM = range(8)
|
|
25
|
+
|
|
26
|
+
NAMES = {
|
|
27
|
+
CLEAR: "Clear",
|
|
28
|
+
PARTLY: "Partly cloudy",
|
|
29
|
+
CLOUDY: "Cloudy",
|
|
30
|
+
FOG: "Fog",
|
|
31
|
+
DRIZZLE: "Drizzle",
|
|
32
|
+
RAIN: "Rain",
|
|
33
|
+
SNOW: "Snow",
|
|
34
|
+
STORM: "Thunderstorm",
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def kind(code):
|
|
39
|
+
"""Return the icon kind for a WMO weather code, the codes Open-Meteo sends."""
|
|
40
|
+
if code <= 1:
|
|
41
|
+
return CLEAR
|
|
42
|
+
if code == 2:
|
|
43
|
+
return PARTLY
|
|
44
|
+
if code == 3:
|
|
45
|
+
return CLOUDY
|
|
46
|
+
if code in (45, 48):
|
|
47
|
+
return FOG
|
|
48
|
+
if 51 <= code <= 57:
|
|
49
|
+
return DRIZZLE
|
|
50
|
+
if 61 <= code <= 67 or 80 <= code <= 82:
|
|
51
|
+
return RAIN
|
|
52
|
+
if 71 <= code <= 77 or code in (85, 86):
|
|
53
|
+
return SNOW
|
|
54
|
+
if code >= 95:
|
|
55
|
+
return STORM
|
|
56
|
+
return CLOUDY
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
def name(code, is_day):
|
|
60
|
+
"""Return the words for a WMO weather code."""
|
|
61
|
+
which = kind(code)
|
|
62
|
+
if which == CLEAR and is_day:
|
|
63
|
+
return "Sunny"
|
|
64
|
+
return NAMES[which]
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def _disc(parent, x, y, d, color):
|
|
68
|
+
o = lv.obj(parent)
|
|
69
|
+
o.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
70
|
+
o.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
71
|
+
o.set_style_pad_all(0, 0)
|
|
72
|
+
o.set_style_border_width(0, 0)
|
|
73
|
+
o.set_style_bg_color(lv.color_hex(color), 0)
|
|
74
|
+
o.set_style_radius(lv.RADIUS_CIRCLE, 0)
|
|
75
|
+
o.set_pos(x, y)
|
|
76
|
+
o.set_size(d, d)
|
|
77
|
+
return o
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def _bar(parent, x, y, w, h, color):
|
|
81
|
+
o = _disc(parent, x, y, w, color)
|
|
82
|
+
o.set_size(w, h)
|
|
83
|
+
return o
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def _sun(parent, x, y, d):
|
|
87
|
+
_disc(parent, x, y, d, _SUN)
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def _moon(parent, x, y, d, background):
|
|
91
|
+
_disc(parent, x, y, d, _MOON)
|
|
92
|
+
_disc(parent, x + d * 3 // 10, y - d // 10, d * 8 // 10, background)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
def _cloud(parent, x, y, w, color=_CLOUD):
|
|
96
|
+
u = w // 10
|
|
97
|
+
_bar(parent, x, y + 3 * u, w, 3 * u, color)
|
|
98
|
+
_disc(parent, x + u, y + u, 4 * u, color)
|
|
99
|
+
_disc(parent, x + 4 * u, y, 5 * u, color)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def _streaks(parent, x, y, w, n, color, long):
|
|
103
|
+
step = w // n
|
|
104
|
+
for i in range(n):
|
|
105
|
+
_bar(parent, x + step // 4 + i * step, y, max(2, w // 16), long, color)
|
|
106
|
+
|
|
107
|
+
|
|
108
|
+
def _bolt(parent, x, y, u):
|
|
109
|
+
bolt = lv.line(parent)
|
|
110
|
+
points = bytearray()
|
|
111
|
+
for px, py in ((x + u, y), (x - u // 2, y + u * 2), (x + u // 2, y + u * 2), (x - u, y + u * 4)):
|
|
112
|
+
points += struct.pack(_POINT, px, py)
|
|
113
|
+
# LVGL keeps a pointer to the points rather than a copy, so they're kept
|
|
114
|
+
# here for as long as a bolt can be on screen: one now, five days ahead.
|
|
115
|
+
_bolts.append(points)
|
|
116
|
+
del _bolts[:-12]
|
|
117
|
+
bolt.set_points(points, 4)
|
|
118
|
+
bolt.set_style_line_width(max(2, u // 2), 0)
|
|
119
|
+
bolt.set_style_line_color(lv.color_hex(_BOLT), 0)
|
|
120
|
+
bolt.set_style_line_rounded(True, 0)
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
def make(parent, code, is_day, size, background):
|
|
124
|
+
"""Draw the icon for *code* in a new transparent box; return the box.
|
|
125
|
+
|
|
126
|
+
Args:
|
|
127
|
+
parent (lv.obj): What to draw it on.
|
|
128
|
+
code (int): The WMO weather code.
|
|
129
|
+
is_day (bool): False swaps the sun for the moon.
|
|
130
|
+
size (int): The box's width and height in pixels.
|
|
131
|
+
background (int): The colour behind it, which cuts the moon's crescent.
|
|
132
|
+
"""
|
|
133
|
+
box = lv.obj(parent)
|
|
134
|
+
box.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
135
|
+
box.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
136
|
+
box.set_style_pad_all(0, 0)
|
|
137
|
+
box.set_style_border_width(0, 0)
|
|
138
|
+
box.set_style_bg_opa(lv.OPA.TRANSP, 0)
|
|
139
|
+
box.set_size(size, size)
|
|
140
|
+
|
|
141
|
+
which = kind(code)
|
|
142
|
+
u = size // 10
|
|
143
|
+
if which == CLEAR:
|
|
144
|
+
if is_day:
|
|
145
|
+
_sun(box, u * 2, u * 2, u * 6)
|
|
146
|
+
else:
|
|
147
|
+
_moon(box, u * 2, u * 2, u * 6, background)
|
|
148
|
+
elif which == PARTLY:
|
|
149
|
+
if is_day:
|
|
150
|
+
_sun(box, u * 4, u, u * 5)
|
|
151
|
+
else:
|
|
152
|
+
_moon(box, u * 4, u, u * 5, background)
|
|
153
|
+
_cloud(box, 0, u * 3, u * 8)
|
|
154
|
+
elif which == CLOUDY:
|
|
155
|
+
_cloud(box, u, u * 2, u * 8)
|
|
156
|
+
elif which == FOG:
|
|
157
|
+
for i in range(4):
|
|
158
|
+
_bar(box, u * (1 + i % 2), u * (2 + i * 2), u * 7, u, _CLOUD)
|
|
159
|
+
elif which == DRIZZLE:
|
|
160
|
+
_cloud(box, u, u, u * 8)
|
|
161
|
+
_streaks(box, u * 2, u * 7, u * 6, 3, _RAIN, u)
|
|
162
|
+
elif which == RAIN:
|
|
163
|
+
_cloud(box, u, u, u * 8, _DARK_CLOUD)
|
|
164
|
+
_streaks(box, u * 2, u * 6, u * 6, 3, _RAIN, u * 3)
|
|
165
|
+
elif which == SNOW:
|
|
166
|
+
_cloud(box, u, u, u * 8)
|
|
167
|
+
for x, y in ((2, 7), (4, 8), (6, 7)):
|
|
168
|
+
_disc(box, u * x, u * y, u, _SNOW)
|
|
169
|
+
else:
|
|
170
|
+
_cloud(box, u, u, u * 8, _DARK_CLOUD)
|
|
171
|
+
_bolt(box, u * 5, u * 6, u)
|
|
172
|
+
return box
|
apps/weather/sizing.py
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""Sizes for Weather's screens, from the 480-pixel round screen it was drawn for.
|
|
5
|
+
|
|
6
|
+
Every size is the one it has there, times `scale`; a font is the largest
|
|
7
|
+
the firmware has that is no taller, and never smaller than the least one
|
|
8
|
+
that still reads. On a round screen `half_width` says how much of a row
|
|
9
|
+
lies inside the circle.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
import lvgl as lv
|
|
13
|
+
|
|
14
|
+
DRAWN_FOR = 480 # the screen the sizes below are given for
|
|
15
|
+
_SIZES = (48, 40, 36, 32, 28, 24, 22, 20, 18, 16, 14, 12)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
def scale(width, height):
|
|
19
|
+
"""How much smaller this screen is than the one Weather was drawn for:
|
|
20
|
+
1.0 on a 480-pixel screen and larger ones, 0.5 on a 240-pixel one."""
|
|
21
|
+
return min(1.0, min(width, height) / DRAWN_FOR)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def font(px, least=14):
|
|
25
|
+
"""The largest Montserrat font no taller than *px*, and no smaller than
|
|
26
|
+
*least* when the firmware has one that size or larger."""
|
|
27
|
+
px = max(px, least)
|
|
28
|
+
for size in _SIZES:
|
|
29
|
+
if size <= px:
|
|
30
|
+
f = getattr(lv, "font_montserrat_%d" % size, None)
|
|
31
|
+
if f is not None:
|
|
32
|
+
return f
|
|
33
|
+
for size in reversed(_SIZES):
|
|
34
|
+
f = getattr(lv, "font_montserrat_%d" % size, None)
|
|
35
|
+
if f is not None:
|
|
36
|
+
return f
|
|
37
|
+
return lv.font_get_default()
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def half_width(width, height, round_, top, bottom, margin=6):
|
|
41
|
+
"""Half the width a row from *top* to *bottom* (pixels from the top) can
|
|
42
|
+
use: inside the circle on a round screen, less *margin* on each side."""
|
|
43
|
+
if not round_:
|
|
44
|
+
return width // 2 - margin
|
|
45
|
+
r = width / 2
|
|
46
|
+
dy = max(abs(top - height / 2), abs(bottom - height / 2))
|
|
47
|
+
if dy >= r:
|
|
48
|
+
return 0
|
|
49
|
+
return int((r * r - dy * dy) ** 0.5) - margin
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def below_home(scope, gap=4, centred=True):
|
|
53
|
+
"""How far down the Shell's Home button reaches, plus *gap*, when it
|
|
54
|
+
floats over the top of the app's screen; 0 when it doesn't. Weather's
|
|
55
|
+
words start below it, so the button never sits on them. For *centred*
|
|
56
|
+
words, a button in a corner is no matter."""
|
|
57
|
+
shell = getattr(getattr(scope, "launcher", None), "shell", None)
|
|
58
|
+
button = getattr(shell, "home_button", None)
|
|
59
|
+
if button is None or button.has_flag(lv.obj.FLAG.HIDDEN):
|
|
60
|
+
return 0
|
|
61
|
+
button.update_layout()
|
|
62
|
+
area = lv.area_t()
|
|
63
|
+
button.get_coords(area)
|
|
64
|
+
width, height = scope.size
|
|
65
|
+
# A button in a corner clears the words, which are centred; one that
|
|
66
|
+
# reaches towards the middle, as on a round screen, doesn't.
|
|
67
|
+
if area.y1 > height // 4:
|
|
68
|
+
return 0
|
|
69
|
+
if centred and (area.x2 < width // 4 or area.x1 > width * 3 // 4):
|
|
70
|
+
return 0
|
|
71
|
+
return area.y2 + 1 + gap
|
apps/weather/zippad.py
ADDED
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""A keypad for a ZIP code, sized so every key sits inside a round screen."""
|
|
5
|
+
|
|
6
|
+
import lvgl as lv
|
|
7
|
+
from appkit.shell import is_round
|
|
8
|
+
from deskkit import forecast
|
|
9
|
+
|
|
10
|
+
from . import sizing
|
|
11
|
+
|
|
12
|
+
_LENGTH = 5
|
|
13
|
+
_BG = 0x0A1020
|
|
14
|
+
_KEY = 0x24344A
|
|
15
|
+
_GO = 0x2F7D4F
|
|
16
|
+
_WHITE = 0xFFFFFF
|
|
17
|
+
_SOFT = 0xB9C6D4
|
|
18
|
+
_BAD = 0xFF8A7A
|
|
19
|
+
_GRID = (("1", "2", "3"), ("4", "5", "6"), ("7", "8", "9"), ("del", "0", "ok"))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class ZipPad:
|
|
23
|
+
"""Ask for a ZIP code, look it up, and call *done* with the place saved.
|
|
24
|
+
|
|
25
|
+
Args:
|
|
26
|
+
scope (AppScope): The app it belongs to.
|
|
27
|
+
width (int): The screen's width.
|
|
28
|
+
height (int): The screen's height.
|
|
29
|
+
done (callable): Called with no arguments once there's a place, or when
|
|
30
|
+
you back out of changing one you already have.
|
|
31
|
+
"""
|
|
32
|
+
|
|
33
|
+
def __init__(self, scope, width, height, done):
|
|
34
|
+
self.scope = scope
|
|
35
|
+
self.done = done
|
|
36
|
+
self.digits = ""
|
|
37
|
+
self.busy = False
|
|
38
|
+
|
|
39
|
+
self.panel = panel = lv.obj(scope.root)
|
|
40
|
+
panel.remove_flag(lv.obj.FLAG.SCROLLABLE)
|
|
41
|
+
panel.set_size(width, height)
|
|
42
|
+
panel.set_style_pad_all(0, 0)
|
|
43
|
+
panel.set_style_border_width(0, 0)
|
|
44
|
+
panel.set_style_radius(0, 0)
|
|
45
|
+
panel.set_style_bg_color(lv.color_hex(_BG), 0)
|
|
46
|
+
|
|
47
|
+
k = sizing.scale(width, height)
|
|
48
|
+
side = min(width, height)
|
|
49
|
+
key_w = side * 20 // 100
|
|
50
|
+
key_h = side * 11 // 100
|
|
51
|
+
gap = max(4, side * 2 // 100)
|
|
52
|
+
key_font = sizing.font(24 * k, 16)
|
|
53
|
+
title_font = sizing.font(16 * k)
|
|
54
|
+
digits_font = sizing.font(40 * k, 24)
|
|
55
|
+
|
|
56
|
+
# Title, digits, then the keys: a column centred on the screen, so a
|
|
57
|
+
# round one's edge clears the top and bottom rows.
|
|
58
|
+
title_h = title_font.get_line_height()
|
|
59
|
+
digits_h = digits_font.get_line_height()
|
|
60
|
+
column = title_h + gap + digits_h + gap + 4 * key_h + 3 * gap
|
|
61
|
+
top = (height - column) // 2
|
|
62
|
+
clear = sizing.below_home(scope)
|
|
63
|
+
if clear > top:
|
|
64
|
+
# Below the Home button, ending where it would have: the keys
|
|
65
|
+
# give up the height, down to what their labels need.
|
|
66
|
+
bottom = top + column
|
|
67
|
+
top = clear
|
|
68
|
+
key_h = max(key_font.get_line_height() + 4, (bottom - top - title_h - digits_h - 5 * gap) // 4)
|
|
69
|
+
digits_top = top + title_h + gap
|
|
70
|
+
grid_top = digits_top + digits_h + gap
|
|
71
|
+
|
|
72
|
+
self.title = lv.label(panel)
|
|
73
|
+
self.title.set_style_text_font(title_font, 0)
|
|
74
|
+
self.title.set_style_text_color(lv.color_hex(_SOFT), 0)
|
|
75
|
+
self.title.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
76
|
+
self.title.set_long_mode(lv.label.LONG_MODE.WRAP)
|
|
77
|
+
# A message too long for the row wraps upwards, inside the circle.
|
|
78
|
+
self.title.set_width(min(width * 7 // 10, 2 * sizing.half_width(width, height, is_round(), top, top + title_h, 4)))
|
|
79
|
+
self.title_bottom = top + title_h
|
|
80
|
+
self.width = width
|
|
81
|
+
|
|
82
|
+
self.shown = lv.label(panel)
|
|
83
|
+
self.shown.set_style_text_font(digits_font, 0)
|
|
84
|
+
self.shown.set_style_text_color(lv.color_hex(_WHITE), 0)
|
|
85
|
+
self.shown.align(lv.ALIGN.TOP_MID, 0, digits_top)
|
|
86
|
+
|
|
87
|
+
place = forecast.current()
|
|
88
|
+
if place is not None:
|
|
89
|
+
self.units = lv.button(panel)
|
|
90
|
+
units_w = key_w * 8 // 10
|
|
91
|
+
self.units.set_size(units_w, min(key_h, digits_h))
|
|
92
|
+
# Right of the digits, clear of five of them.
|
|
93
|
+
self.units.set_pos(width // 2 + side * 21 // 100, digits_top + (digits_h - min(key_h, digits_h)) // 2)
|
|
94
|
+
self.units.set_style_bg_color(lv.color_hex(_KEY), 0)
|
|
95
|
+
self.units.set_style_pad_all(0, 0)
|
|
96
|
+
self.units.add_event_cb(self._toggle_units, lv.EVENT.CLICKED, None)
|
|
97
|
+
self.units_label = lv.label(self.units)
|
|
98
|
+
self.units_label.set_style_text_font(key_font, 0)
|
|
99
|
+
self.units_label.set_text("°" + place.get("units", "F"))
|
|
100
|
+
self.units_label.center()
|
|
101
|
+
|
|
102
|
+
for row, keys in enumerate(_GRID):
|
|
103
|
+
for col, key in enumerate(keys):
|
|
104
|
+
b = lv.button(panel)
|
|
105
|
+
b.set_size(key_w, key_h)
|
|
106
|
+
b.set_pos(
|
|
107
|
+
(width - 3 * key_w - 2 * gap) // 2 + col * (key_w + gap),
|
|
108
|
+
grid_top + row * (key_h + gap),
|
|
109
|
+
)
|
|
110
|
+
color = _GO if key == "ok" else _KEY
|
|
111
|
+
b.set_style_bg_color(lv.color_hex(color), 0)
|
|
112
|
+
b.set_style_pad_all(0, 0)
|
|
113
|
+
label = lv.label(b)
|
|
114
|
+
label.set_style_text_font(key_font, 0)
|
|
115
|
+
if key == "del":
|
|
116
|
+
label.set_text(lv.SYMBOL.BACKSPACE)
|
|
117
|
+
elif key == "ok":
|
|
118
|
+
label.set_text(lv.SYMBOL.OK)
|
|
119
|
+
else:
|
|
120
|
+
label.set_text(key)
|
|
121
|
+
label.center()
|
|
122
|
+
b.add_event_cb(self._maker(key), lv.EVENT.CLICKED, None)
|
|
123
|
+
self._refresh("Enter your ZIP code")
|
|
124
|
+
|
|
125
|
+
def delete(self):
|
|
126
|
+
self.panel.delete()
|
|
127
|
+
|
|
128
|
+
def _maker(self, key):
|
|
129
|
+
return lambda _event: self._press(key)
|
|
130
|
+
|
|
131
|
+
def _refresh(self, title=None, color=_SOFT):
|
|
132
|
+
if title is not None:
|
|
133
|
+
self.title.set_text(title)
|
|
134
|
+
self.title.set_style_text_color(lv.color_hex(color), 0)
|
|
135
|
+
self.title.update_layout()
|
|
136
|
+
self.title.set_pos((self.width - self.title.get_width()) // 2, self.title_bottom - self.title.get_height())
|
|
137
|
+
self.shown.set_text(self.digits + "-" * (_LENGTH - len(self.digits)))
|
|
138
|
+
|
|
139
|
+
def _press(self, key):
|
|
140
|
+
if self.busy:
|
|
141
|
+
return
|
|
142
|
+
if key == "del":
|
|
143
|
+
if self.digits:
|
|
144
|
+
self.digits = self.digits[:-1]
|
|
145
|
+
self._refresh("Enter your ZIP code")
|
|
146
|
+
elif forecast.current() is not None:
|
|
147
|
+
self.done() # nothing typed and a place to go back to
|
|
148
|
+
elif key == "ok":
|
|
149
|
+
if len(self.digits) == _LENGTH:
|
|
150
|
+
self.busy = True
|
|
151
|
+
self._refresh("Looking it up")
|
|
152
|
+
self.scope.worker.submit(lambda: forecast.choose(self.digits), self._found, key="zip")
|
|
153
|
+
elif len(self.digits) < _LENGTH:
|
|
154
|
+
self.digits += key
|
|
155
|
+
self._refresh()
|
|
156
|
+
|
|
157
|
+
def _found(self, _place, error):
|
|
158
|
+
self.busy = False
|
|
159
|
+
if error is None:
|
|
160
|
+
self.done()
|
|
161
|
+
return
|
|
162
|
+
if isinstance(error, ValueError):
|
|
163
|
+
self._refresh("No place has that ZIP code", _BAD)
|
|
164
|
+
else:
|
|
165
|
+
self._refresh("Can't reach the service. Try again.", _BAD)
|
|
166
|
+
self.digits = ""
|
|
167
|
+
self._refresh()
|
|
168
|
+
|
|
169
|
+
def _toggle_units(self, _event):
|
|
170
|
+
units = "C" if forecast.current().get("units", "F") == "F" else "F"
|
|
171
|
+
forecast.set_units(units)
|
|
172
|
+
self.units_label.set_text("°" + units)
|