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
|
@@ -0,0 +1,633 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The receiver's screen: the cover, what's playing, the transport, and calls.
|
|
5
|
+
|
|
6
|
+
`Screen` is controlkit's now-playing screen with the receiver's own parts
|
|
7
|
+
added: the pairing steps, the sender's battery and signal, shuffle and
|
|
8
|
+
repeat, and a call's card. While a stream plays, twelve spectrum bars sit
|
|
9
|
+
under a smaller cover; before one starts, the cover takes their room. It builds every widget once and then only
|
|
10
|
+
changes them: a new track sets some labels, a new cover sets one image, and
|
|
11
|
+
the spectrum moves a few bars. A call shows a card over the player until it
|
|
12
|
+
ends. Nothing here talks to Bluetooth; the app hands it what the sink and
|
|
13
|
+
the hands-free unit say.
|
|
14
|
+
"""
|
|
15
|
+
|
|
16
|
+
import lvgl as lv
|
|
17
|
+
from controlkit import RingButton, glyphs
|
|
18
|
+
from controlkit import nowplaying
|
|
19
|
+
from controlkit.nowplaying import (
|
|
20
|
+
BG, COLUMN, F_BIG, F_BODY, F_HUGE, F_MID, F_SMALL, F_TINY, F_TITLE, LINE, MODE_HIT, MODE_ICON, MUTED, SUB,
|
|
21
|
+
SWITCH_ROOM, TEAL, TEXT, clock,
|
|
22
|
+
)
|
|
23
|
+
from controlkit.nowplaying import box as _box
|
|
24
|
+
from controlkit.nowplaying import label as _label
|
|
25
|
+
from controlkit.nowplaying import show as _show
|
|
26
|
+
from controlkit.theme import BLACK
|
|
27
|
+
from icons import lvgl as lvicons
|
|
28
|
+
|
|
29
|
+
AMBER = 0xFFB74D # a warning about the sender: its battery, its signal
|
|
30
|
+
GREEN = 0x66BB6A # answer
|
|
31
|
+
RED = 0xEF5350 # decline and hang up
|
|
32
|
+
|
|
33
|
+
BANDS = 12 # the spectrum under the cover, while there's a stream to show
|
|
34
|
+
WEAK_DB = -10 # a link this far below the radio's ideal range is weak
|
|
35
|
+
# The phone's battery as its hands-free link reports it, 0 to 5, and the icon
|
|
36
|
+
# for each. At LOW_BATTERY or under it turns amber. A sender with no
|
|
37
|
+
# hands-free link, such as a computer, reports none.
|
|
38
|
+
BATTERY = ("battery_0_bar", "battery_1_bar", "battery_2_bar", "battery_4_bar", "battery_5_bar", "battery_full")
|
|
39
|
+
LOW_BATTERY = 1
|
|
40
|
+
# The sender's battery as AVRCP reports it, a state rather than a level, and
|
|
41
|
+
# the icon and colour for each: what shows without the hands-free link's. A
|
|
42
|
+
# sender that reports neither shows none.
|
|
43
|
+
PLAYER_BATTERY = {"full": ("battery_full", MUTED), "normal": ("battery_5_bar", MUTED),
|
|
44
|
+
"warning": ("battery_2_bar", AMBER), "critical": ("battery_0_bar", AMBER),
|
|
45
|
+
"external": ("battery_charging_full", MUTED)}
|
|
46
|
+
SIGNAL_BARS = 4 # the phone's signal, 0 to 5, as this many bars
|
|
47
|
+
# What the card says over the caller for each of HandsFree's call states.
|
|
48
|
+
# The calls setting's label, beside its switch in the header.
|
|
49
|
+
CALLS_LABEL = "Phone calls and battery"
|
|
50
|
+
STATUS_W = 120 # the shell's status line, moved to the label's left
|
|
51
|
+
HEADER_ROOM = 480 # the least header width the switch, its label and the status line share with the title
|
|
52
|
+
# The pairing steps as one paragraph, where there's no room for them numbered.
|
|
53
|
+
STEPS_TEXT = "Open Bluetooth on your phone, choose this name in its list, and play anything."
|
|
54
|
+
CALL_WORDS = {"incoming": "INCOMING CALL", "dialing": "CALLING", "alerting": "RINGING", "active": "ON A CALL",
|
|
55
|
+
"held": "ON HOLD"}
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
# The call card's small ring, main ring and gap on each size of screen.
|
|
59
|
+
CALL_RINGS = {"large": (64, 80, 40), "medium": (48, 60, 24), "small": (36, 44, 20)}
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
class Layout(nowplaying.Layout):
|
|
63
|
+
"""Where everything goes in an app area *w* x *h* pixels: controlkit's
|
|
64
|
+
now-playing layout, with the pairing steps and the call card.
|
|
65
|
+
|
|
66
|
+
*switch* is True when the calls setting sits in the app's area, not in
|
|
67
|
+
the shell's header: room is kept for it at the top. *round_* keeps
|
|
68
|
+
everything inside a round screen's circle.
|
|
69
|
+
"""
|
|
70
|
+
|
|
71
|
+
def __init__(self, w, h, switch=False, round_=False):
|
|
72
|
+
nowplaying.Layout.__init__(self, w, h, switch, round_)
|
|
73
|
+
size = self.size
|
|
74
|
+
self.call_rings = CALL_RINGS[size]
|
|
75
|
+
if size == "large":
|
|
76
|
+
self.caller_font = F_HUGE
|
|
77
|
+
self.step_font, self.step_pitch, self.step_ring = F_BODY, 52, 32
|
|
78
|
+
elif size == "medium":
|
|
79
|
+
self.caller_font = F_TITLE
|
|
80
|
+
self.step_font, self.step_pitch, self.step_ring = F_SMALL, 36, 26
|
|
81
|
+
else:
|
|
82
|
+
self.caller_font = F_MID
|
|
83
|
+
self.step_font, self.step_pitch, self.step_ring = F_TINY, 30, 22
|
|
84
|
+
tx, ty, tw = self.text[:3]
|
|
85
|
+
if self.kind == "wide":
|
|
86
|
+
self.steps = (tx, tw, 150)
|
|
87
|
+
self._call_side(tx, tw, ty)
|
|
88
|
+
elif self.kind == "side":
|
|
89
|
+
# A small screen has no room for the numbered steps: they're a
|
|
90
|
+
# paragraph under the name, and the stream's details are left out.
|
|
91
|
+
top = ty + 4
|
|
92
|
+
self.steps = (tx, tw, top + 50) if size == "medium" else None
|
|
93
|
+
self._call_side(tx, tw, top)
|
|
94
|
+
else:
|
|
95
|
+
self._call_stack()
|
|
96
|
+
self.pair_ring = self.cover[2] * 300 // 368
|
|
97
|
+
|
|
98
|
+
def _call_side(self, cx, cw, ty):
|
|
99
|
+
"""The call card beside the cover: its lines, then its buttons along
|
|
100
|
+
the bottom, under the lines when they fit there."""
|
|
101
|
+
small, big, gap = self.call_rings
|
|
102
|
+
by = self.h - big - 36 if self.kind == "wide" else self.h - self.m - (26 if self.size == "medium" else 20) - big
|
|
103
|
+
x = cx if cw >= 2 * small + big + 2 * gap else self.m
|
|
104
|
+
self.call_text = (cx, ty, cw, by - 8 - ty)
|
|
105
|
+
self.call_buttons = (x, by, x)
|
|
106
|
+
|
|
107
|
+
def _call_stack(self):
|
|
108
|
+
w, bottom = self.w, self.bottom
|
|
109
|
+
self.steps = None # the steps go in a paragraph under the name
|
|
110
|
+
self.paragraph = self._band(self.text[1] + 40, bottom - 30)
|
|
111
|
+
small, big, gap = self.call_rings
|
|
112
|
+
by = bottom - 20 - big
|
|
113
|
+
# Its captions' row has to fit inside a round screen too.
|
|
114
|
+
while self.round and self._band(by + big, by + big + 20)[1] < 2 * small + big + 4 * gap and by > self.text[1] + 60:
|
|
115
|
+
by -= 4
|
|
116
|
+
ty = self.text[1]
|
|
117
|
+
x, bw = self._band(ty, by - 4)
|
|
118
|
+
self.call_text = (x, ty, bw, by - 4 - ty)
|
|
119
|
+
self.call_buttons = ((w - 2 * big - 2 * gap) // 2, by, (w - 2 * small - big - 2 * gap) // 2)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
class Screen(nowplaying.NowPlaying):
|
|
123
|
+
"""Everything on the receiver's screen, in *root* (*size* pixels), laid
|
|
124
|
+
out for that size by `Layout`. *switch* and *round_* are `Layout`'s.
|
|
125
|
+
|
|
126
|
+
*on* maps ``"play"``, ``"next"``, ``"previous"``, ``"seek"``, ``"repeat"``,
|
|
127
|
+
``"shuffle"`` and ``"volume"`` to what the buttons and the slider do, and
|
|
128
|
+
``"answer"``, ``"hangup"``, ``"mute"`` and ``"route"`` to the call card's
|
|
129
|
+
buttons.
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
def __init__(self, root, size, on, switch=False, round_=False):
|
|
133
|
+
lay = Layout(size[0], size[1], switch, round_)
|
|
134
|
+
nowplaying.NowPlaying.__init__(self, root, lay, on, mark="bluetooth", bands=BANDS)
|
|
135
|
+
self._link_notes = []
|
|
136
|
+
self._phone_notes = []
|
|
137
|
+
self._phone_battery = None
|
|
138
|
+
self._player_battery = None
|
|
139
|
+
self.call_state = None
|
|
140
|
+
self._build_pairing(*lay.cover)
|
|
141
|
+
self._build_status()
|
|
142
|
+
self._build_modes()
|
|
143
|
+
self._build_call(size)
|
|
144
|
+
# The sender's line stays over the call card: the battery always shows.
|
|
145
|
+
for o in (self.src_mark, self.src_name, self.signal, self.battery, self.warn):
|
|
146
|
+
o.move_foreground()
|
|
147
|
+
self.set_accent(TEAL)
|
|
148
|
+
|
|
149
|
+
# -- building -------------------------------------------------------
|
|
150
|
+
|
|
151
|
+
def _build_pairing(self, x, y, s):
|
|
152
|
+
# Pairing: the Bluetooth mark in rings, where the cover goes.
|
|
153
|
+
pair = self.pair = _box(self.root, x, y, s, s)
|
|
154
|
+
ring = self.lay.pair_ring
|
|
155
|
+
self.rings = []
|
|
156
|
+
for d, opa in ((ring, 50), (ring * 7 // 10, 90), (ring * 2 // 5, 255)):
|
|
157
|
+
c = _box(pair, (s - d) // 2, (s - d) // 2, d, d)
|
|
158
|
+
c.set_style_radius(lv.RADIUS_CIRCLE, 0)
|
|
159
|
+
c.set_style_border_width(1, 0)
|
|
160
|
+
c.set_style_border_opa(opa, 0)
|
|
161
|
+
self.rings.append(c)
|
|
162
|
+
self.pair_mark = glyphs.tinted(pair, "bluetooth", max(8, ring // 4), lv.color_hex(TEAL))
|
|
163
|
+
self.pair_mark.center()
|
|
164
|
+
_show(pair, False)
|
|
165
|
+
# Beside it, the steps, and the PIN an older device asks for.
|
|
166
|
+
lay = self.lay
|
|
167
|
+
sx, sw, _ = lay.steps or (0, COLUMN, 0)
|
|
168
|
+
pitch, d, font = lay.step_pitch, lay.step_ring, lay.step_font
|
|
169
|
+
steps = self.steps = _box(self.root, sx, 150, sw, 4 * pitch + 10)
|
|
170
|
+
self.step_rings = []
|
|
171
|
+
for i, text in enumerate(("Open Bluetooth on your phone", "Choose this name in its list", "Play anything")):
|
|
172
|
+
ring = _box(steps, 0, i * pitch, d, d)
|
|
173
|
+
ring.set_style_radius(lv.RADIUS_CIRCLE, 0)
|
|
174
|
+
ring.set_style_border_width(1, 0)
|
|
175
|
+
num = _label(ring, F_SMALL if d > 24 else F_TINY, TEXT)
|
|
176
|
+
num.set_text(str(i + 1))
|
|
177
|
+
num.center()
|
|
178
|
+
lbl = _label(steps, font, SUB)
|
|
179
|
+
lbl.set_width(sw - d * 3 // 2)
|
|
180
|
+
lbl.set_text(text)
|
|
181
|
+
lbl.set_pos(d * 3 // 2, i * pitch + (d - font.get_line_height()) // 2)
|
|
182
|
+
self.step_rings.append(ring)
|
|
183
|
+
self.pin = _label(steps, F_SMALL if d > 24 else F_TINY, MUTED, 1)
|
|
184
|
+
self.pin.set_width(sw)
|
|
185
|
+
self.pin.set_pos(0, 3 * pitch + 12)
|
|
186
|
+
_show(steps, False)
|
|
187
|
+
# The pairing steps as a paragraph, where they don't fit numbered.
|
|
188
|
+
# Lower down a round screen is wider: it takes the width it has there.
|
|
189
|
+
tx, ty, tw = lay.text[:3]
|
|
190
|
+
px, pw = lay.paragraph if lay.center else (tx, tw)
|
|
191
|
+
self.para = _label(self.root, F_BODY if lay.size == "medium" else F_SMALL, SUB)
|
|
192
|
+
self.para.set_pos(px, ty)
|
|
193
|
+
self.para.set_width(pw)
|
|
194
|
+
if lay.center:
|
|
195
|
+
self.para.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
196
|
+
_show(self.para, False)
|
|
197
|
+
|
|
198
|
+
def _build_status(self):
|
|
199
|
+
# The sender's battery at the right end of its line, on its side like
|
|
200
|
+
# a phone's, its signal beside it, and a warning about the link.
|
|
201
|
+
root = self.src_root
|
|
202
|
+
cx, sy, cw = self.lay.source or (0, 0, COLUMN)
|
|
203
|
+
wx = self.src_room
|
|
204
|
+
self.battery = lvicons.image(root, "battery_full", 24, lv.color_hex(MUTED))
|
|
205
|
+
self.battery.set_rotation(900)
|
|
206
|
+
self.battery.set_pos(cx + cw - 22, sy - 3)
|
|
207
|
+
self.battery_state = None
|
|
208
|
+
_show(self.battery, False)
|
|
209
|
+
# The phone's signal beside it: thin bars, filled up to the level.
|
|
210
|
+
sig = self.signal = _box(root, cx + cw - 56, sy + 3, 4 * SIGNAL_BARS + 3 * (SIGNAL_BARS - 1), 14)
|
|
211
|
+
self.signal_bars = []
|
|
212
|
+
for i in range(SIGNAL_BARS):
|
|
213
|
+
h = 5 + i * 3
|
|
214
|
+
bar = _box(sig, i * 7, 14 - h, 4, h)
|
|
215
|
+
bar.set_style_radius(1, 0)
|
|
216
|
+
bar.set_style_border_width(1, 0)
|
|
217
|
+
bar.set_style_border_color(lv.color_hex(MUTED), 0)
|
|
218
|
+
bar.set_style_bg_color(lv.color_hex(MUTED), 0)
|
|
219
|
+
self.signal_bars.append(bar)
|
|
220
|
+
self.signal_state = None
|
|
221
|
+
_show(sig, False)
|
|
222
|
+
self.warn = _label(root, F_SMALL, AMBER)
|
|
223
|
+
self.warn.set_size(cw - wx - 68, F_SMALL.get_line_height())
|
|
224
|
+
self.warn.set_long_mode(lv.label.LONG_MODE.DOTS)
|
|
225
|
+
self.warn.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
|
|
226
|
+
self.warn.set_pos(cx + wx, sy + 1)
|
|
227
|
+
|
|
228
|
+
def _build_modes(self):
|
|
229
|
+
# Repeat and shuffle, lit in the accent while on; "single" marks the
|
|
230
|
+
# repeat with a small 1, as the icons package has no repeat-one icon.
|
|
231
|
+
# Over the volume they line up with its mark and the slider's end; on
|
|
232
|
+
# a row with it, they sit at its ends.
|
|
233
|
+
sx, rx = self.lay.modes
|
|
234
|
+
y = self.lay.volume[3]
|
|
235
|
+
self._modes = (None, None)
|
|
236
|
+
self._modes_on = False
|
|
237
|
+
self.shuffle, self.shuffle_icon = self._mode_button(sx, y, "shuffle")
|
|
238
|
+
self.repeat, self.repeat_icon = self._mode_button(rx, y, "repeat")
|
|
239
|
+
one = self.repeat_one = _label(self.repeat, F_TINY, TEXT)
|
|
240
|
+
one.set_text("1")
|
|
241
|
+
one.align_to(self.repeat_icon, lv.ALIGN.TOP_RIGHT, 6, -8)
|
|
242
|
+
_show(one, False)
|
|
243
|
+
|
|
244
|
+
def _mode_button(self, x, y, name):
|
|
245
|
+
"""A button for mode *name* with the icon of that name: ``(button, icon)``."""
|
|
246
|
+
b = _box(self.root, x, y - MODE_HIT // 2, MODE_HIT, MODE_HIT)
|
|
247
|
+
b.add_flag(lv.obj.FLAG.CLICKABLE)
|
|
248
|
+
b.add_event_cb(lambda e: self.on[name](), lv.EVENT.CLICKED, None)
|
|
249
|
+
img = lvicons.image(b, name, MODE_ICON, lv.color_hex(MUTED))
|
|
250
|
+
img.center()
|
|
251
|
+
img.remove_flag(lv.obj.FLAG.CLICKABLE)
|
|
252
|
+
_show(b, False)
|
|
253
|
+
return b, img
|
|
254
|
+
|
|
255
|
+
# -- what the app calls ---------------------------------------------
|
|
256
|
+
|
|
257
|
+
def set_accent(self, rgb):
|
|
258
|
+
"""Take *rgb* as the screen's colour: from the cover, or the default."""
|
|
259
|
+
nowplaying.NowPlaying.set_accent(self, rgb)
|
|
260
|
+
c = lv.color_hex(rgb)
|
|
261
|
+
for ring in self.rings:
|
|
262
|
+
ring.set_style_border_color(c, 0)
|
|
263
|
+
for ring in self.step_rings:
|
|
264
|
+
ring.set_style_border_color(c, 0)
|
|
265
|
+
glyphs.tint(self.pair_mark, c)
|
|
266
|
+
self._paint_modes()
|
|
267
|
+
|
|
268
|
+
def show_pairing(self, name, pin=None):
|
|
269
|
+
"""Nothing connected: the name to pick on the phone, and the steps."""
|
|
270
|
+
self._pairing(True)
|
|
271
|
+
self._cover_shown(False)
|
|
272
|
+
self.set_accent(TEAL)
|
|
273
|
+
self._set_title(name)
|
|
274
|
+
self.eyebrow.set_text("READY TO PAIR")
|
|
275
|
+
_show(self.eyebrow, self.lay.eyebrow)
|
|
276
|
+
self._lines("", "", "", "")
|
|
277
|
+
# The steps start under the name, however many lines it takes.
|
|
278
|
+
self.text.update_layout()
|
|
279
|
+
lay = self.lay
|
|
280
|
+
pin_text = "PIN FOR OLDER DEVICES %s" % pin if pin else ""
|
|
281
|
+
self.pin.set_text(pin_text)
|
|
282
|
+
if lay.steps is None:
|
|
283
|
+
# No room for the numbered steps: they're a paragraph under the name.
|
|
284
|
+
para = self.para
|
|
285
|
+
para.set_text(STEPS_TEXT + ("\n" + pin_text if pin else ""))
|
|
286
|
+
para.set_y(lay.text[1] + self.title.get_y() + self.title.get_height() + 8)
|
|
287
|
+
_show(para, True)
|
|
288
|
+
else:
|
|
289
|
+
self.steps.set_y(max(lay.steps[2], lay.text[1] + self.title.get_y() + self.title.get_height() + 22))
|
|
290
|
+
self.show_source("", None)
|
|
291
|
+
self._playback(False)
|
|
292
|
+
|
|
293
|
+
def show_idle(self, peer):
|
|
294
|
+
"""Connected, nothing playing yet."""
|
|
295
|
+
self._pairing(False)
|
|
296
|
+
self._set_title(peer or "Connected")
|
|
297
|
+
self.eyebrow.set_text("CONNECTED")
|
|
298
|
+
_show(self.eyebrow, True)
|
|
299
|
+
self._lines("", "", "", "Play something on your phone, or tap play.")
|
|
300
|
+
self._playback(False, transport=True)
|
|
301
|
+
|
|
302
|
+
def show_track(self, title, artist, album, number, count, genre):
|
|
303
|
+
"""A track: every line the sender filled in, and nothing for the rest."""
|
|
304
|
+
self._pairing(False)
|
|
305
|
+
self._set_title(title or "Untitled")
|
|
306
|
+
meta = []
|
|
307
|
+
if number:
|
|
308
|
+
meta.append("TRACK %d OF %d" % (number, count) if count else "TRACK %d" % number)
|
|
309
|
+
if genre:
|
|
310
|
+
meta.append(genre.upper())
|
|
311
|
+
self._lines(artist, album, " / ".join(meta), "")
|
|
312
|
+
self._playback(True)
|
|
313
|
+
|
|
314
|
+
def show_status(self, status):
|
|
315
|
+
"""The play status: the eyebrow over the title, and play or pause."""
|
|
316
|
+
word = {"playing": "NOW PLAYING", "paused": "PAUSED", "stopped": "STOPPED", "error": "PLAYER ERROR",
|
|
317
|
+
"seeking forward": "FAST FORWARD", "seeking back": "REWIND"}.get(status, "")
|
|
318
|
+
self.show_eyebrow(word)
|
|
319
|
+
self.show_playing(status == "playing")
|
|
320
|
+
|
|
321
|
+
def show_source(self, name, link):
|
|
322
|
+
"""The sender's name and what its link says: the codec, rate and
|
|
323
|
+
channels under the progress bar once the rate is known, its battery
|
|
324
|
+
whenever it reports one, and a weak signal."""
|
|
325
|
+
self.src_name.set_text(name)
|
|
326
|
+
_show(self.src_mark, bool(name))
|
|
327
|
+
parts = []
|
|
328
|
+
notes = []
|
|
329
|
+
if link:
|
|
330
|
+
if link.get("codec"):
|
|
331
|
+
parts.append(link["codec"])
|
|
332
|
+
rate = link.get("sample_rate")
|
|
333
|
+
if rate:
|
|
334
|
+
parts.append("%g kHz" % (rate / 1000))
|
|
335
|
+
mode = link.get("channel_mode")
|
|
336
|
+
if mode:
|
|
337
|
+
parts.append(mode[0].upper() + mode[1:])
|
|
338
|
+
else:
|
|
339
|
+
parts = [] # no stream yet: no codec to speak of
|
|
340
|
+
rssi = link.get("rssi_delta")
|
|
341
|
+
if rssi is not None and rssi <= WEAK_DB:
|
|
342
|
+
notes.append("Weak signal")
|
|
343
|
+
self.codec.set_text(" / ".join(parts))
|
|
344
|
+
self._link_notes = notes
|
|
345
|
+
self._notes()
|
|
346
|
+
self._player_battery = link.get("battery") if link else None
|
|
347
|
+
self._show_battery()
|
|
348
|
+
|
|
349
|
+
def show_phone(self, battery, signal, service):
|
|
350
|
+
"""The phone's battery and signal from its hands-free link, each 0 to
|
|
351
|
+
5 or None for none, and whether it has network service (None when it
|
|
352
|
+
hasn't said). Its battery shows in place of the player's."""
|
|
353
|
+
self._phone_battery = battery
|
|
354
|
+
self._show_battery()
|
|
355
|
+
state = (signal, service)
|
|
356
|
+
if state != self.signal_state:
|
|
357
|
+
self.signal_state = state
|
|
358
|
+
_show(self.signal, signal is not None)
|
|
359
|
+
if signal is not None:
|
|
360
|
+
lit = 0 if service is False else (max(0, min(5, signal)) * SIGNAL_BARS + 2) // 5
|
|
361
|
+
for i, bar in enumerate(self.signal_bars):
|
|
362
|
+
bar.set_style_bg_opa(lv.OPA.COVER if i < lit else lv.OPA.TRANSP, 0)
|
|
363
|
+
self._phone_notes = ["No service"] if service is False else []
|
|
364
|
+
self._notes()
|
|
365
|
+
|
|
366
|
+
def _notes(self):
|
|
367
|
+
self.warn.set_text(" / ".join(self._phone_notes + self._link_notes))
|
|
368
|
+
|
|
369
|
+
def _show_battery(self):
|
|
370
|
+
# The hands-free link's level, 0 to 5, else the player's state.
|
|
371
|
+
state = self._phone_battery if self._phone_battery is not None else self._player_battery
|
|
372
|
+
if state == self.battery_state:
|
|
373
|
+
return
|
|
374
|
+
self.battery_state = state
|
|
375
|
+
if state is None or (isinstance(state, str) and state not in PLAYER_BATTERY):
|
|
376
|
+
_show(self.battery, False)
|
|
377
|
+
return
|
|
378
|
+
if isinstance(state, str):
|
|
379
|
+
icon, colour = PLAYER_BATTERY[state]
|
|
380
|
+
else:
|
|
381
|
+
level = max(0, min(5, state))
|
|
382
|
+
icon, colour = BATTERY[level], AMBER if level <= LOW_BATTERY else MUTED
|
|
383
|
+
self.battery.set_src(lvicons.dsc(icon, 24))
|
|
384
|
+
self.battery.set_style_image_recolor(lv.color_hex(colour), 0)
|
|
385
|
+
_show(self.battery, True)
|
|
386
|
+
|
|
387
|
+
def show_modes(self, repeat, shuffle):
|
|
388
|
+
"""The sender's *repeat* ("off", "single", "all" or "group") and
|
|
389
|
+
*shuffle* ("off", "all" or "group"). A button for a mode the sender
|
|
390
|
+
doesn't report (None) is hidden; with neither, the volume moves back
|
|
391
|
+
beside the play button."""
|
|
392
|
+
modes = (repeat, shuffle)
|
|
393
|
+
if modes == self._modes:
|
|
394
|
+
return
|
|
395
|
+
self._modes = modes
|
|
396
|
+
self._place_modes()
|
|
397
|
+
self._paint_modes()
|
|
398
|
+
|
|
399
|
+
def show_call(self, state, caller, phone, here, muted, mic, takes=True):
|
|
400
|
+
"""The call card for HandsFree's call *state*, or none for ``None``
|
|
401
|
+
and ``"idle"``.
|
|
402
|
+
|
|
403
|
+
*caller* is the other side's number, *phone* the phone's name, *here*
|
|
404
|
+
whether the call's audio is on the board, *muted* whether the
|
|
405
|
+
microphone is off, and *mic* whether the board has one to send.
|
|
406
|
+
*takes* is False on a board that can't take a call's audio at all:
|
|
407
|
+
the card then answers and hangs up only, and the call stays on the
|
|
408
|
+
phone.
|
|
409
|
+
"""
|
|
410
|
+
on = state in CALL_WORDS
|
|
411
|
+
self.call_state = state if on else None
|
|
412
|
+
_show(self.card, on)
|
|
413
|
+
if not on:
|
|
414
|
+
return
|
|
415
|
+
ringing = state == "incoming"
|
|
416
|
+
self.call_word.set_text(CALL_WORDS[state])
|
|
417
|
+
self.caller.set_text(caller or "Unknown number")
|
|
418
|
+
self.call_phone.set_text("on %s" % phone if phone else "")
|
|
419
|
+
_show(self.call_phone, bool(phone))
|
|
420
|
+
if not takes:
|
|
421
|
+
note = "The call's audio stays on the phone"
|
|
422
|
+
elif ringing:
|
|
423
|
+
note = "Answer here to talk through this speaker"
|
|
424
|
+
elif not here:
|
|
425
|
+
note = "Talking on the phone"
|
|
426
|
+
elif not mic:
|
|
427
|
+
note = "This board can't send its microphones: the caller can't hear you"
|
|
428
|
+
elif muted:
|
|
429
|
+
note = "Microphones off"
|
|
430
|
+
else:
|
|
431
|
+
note = "Talking through this speaker and its microphones"
|
|
432
|
+
self.call_note.set_text(note)
|
|
433
|
+
_show(self.call_time, state == "active")
|
|
434
|
+
colour = GREEN if ringing else self.accent
|
|
435
|
+
for ring in self.call_rings:
|
|
436
|
+
ring.set_style_border_color(lv.color_hex(colour), 0)
|
|
437
|
+
glyphs.tint(self.call_mark, lv.color_hex(colour))
|
|
438
|
+
self.call_word.set_style_text_color(lv.color_hex(colour), 0)
|
|
439
|
+
for b in (self.answer, self.decline):
|
|
440
|
+
_show(b.obj, ringing)
|
|
441
|
+
for b in (self.mute, self.route):
|
|
442
|
+
_show(b.obj, not ringing and takes)
|
|
443
|
+
_show(self.hang.obj, not ringing)
|
|
444
|
+
for lbl in self.ring_labels:
|
|
445
|
+
_show(lbl, ringing)
|
|
446
|
+
for i, lbl in enumerate(self.call_labels):
|
|
447
|
+
_show(lbl, not ringing and (takes or i == 2))
|
|
448
|
+
self.mute.set_icon(glyphs.image("mic_off" if muted else "mic", self._icon_small))
|
|
449
|
+
self.mute.set_enabled(here and mic)
|
|
450
|
+
self.call_labels[0].set_text("Unmute" if muted else "Mute")
|
|
451
|
+
self.route.set_icon(glyphs.image("phone" if here else "volume", self._icon_small))
|
|
452
|
+
self.call_labels[1].set_text("Use phone" if here else "Use speaker")
|
|
453
|
+
|
|
454
|
+
def show_call_time(self, ms):
|
|
455
|
+
"""How long the call has been answered."""
|
|
456
|
+
self.call_time.set_text(clock(ms))
|
|
457
|
+
|
|
458
|
+
# -- inside ---------------------------------------------------------
|
|
459
|
+
|
|
460
|
+
def _place_modes(self):
|
|
461
|
+
repeat, shuffle = self._modes
|
|
462
|
+
on = self._modes_on
|
|
463
|
+
_show(self.repeat, on and repeat is not None)
|
|
464
|
+
_show(self.shuffle, on and shuffle is not None)
|
|
465
|
+
_, _, alone, _, under = self.lay.volume
|
|
466
|
+
y = under if repeat is not None or shuffle is not None else alone
|
|
467
|
+
self.vol_mark.set_y(y - 9)
|
|
468
|
+
self.vol.set_y(y)
|
|
469
|
+
|
|
470
|
+
def _paint_modes(self):
|
|
471
|
+
repeat, shuffle = self._modes
|
|
472
|
+
for icon, mode in ((self.repeat_icon, repeat), (self.shuffle_icon, shuffle)):
|
|
473
|
+
lit = mode not in (None, "off")
|
|
474
|
+
icon.set_style_image_recolor(lv.color_hex(self.accent if lit else MUTED), 0)
|
|
475
|
+
_show(self.repeat_one, repeat == "single")
|
|
476
|
+
self.repeat_one.set_style_text_color(lv.color_hex(self.accent), 0)
|
|
477
|
+
|
|
478
|
+
def _build_call(self, size):
|
|
479
|
+
"""The call card: over everything but the sender's line, hidden
|
|
480
|
+
until a call."""
|
|
481
|
+
on = self.on
|
|
482
|
+
card = self.card = _box(self.root, 0, 0, size[0], size[1])
|
|
483
|
+
card.add_flag(lv.obj.FLAG.CLICKABLE) # nothing under it takes a touch
|
|
484
|
+
card.set_style_bg_opa(lv.OPA.COVER, 0)
|
|
485
|
+
card.set_style_bg_color(lv.color_hex(BG), 0)
|
|
486
|
+
lay = self.lay
|
|
487
|
+
x, y, s = lay.cover
|
|
488
|
+
rings = _box(card, x, y, s, s)
|
|
489
|
+
self.call_rings = []
|
|
490
|
+
ring = lay.pair_ring
|
|
491
|
+
for d, opa in ((ring, 50), (ring * 7 // 10, 90), (ring * 2 // 5, 255)):
|
|
492
|
+
c = _box(rings, (s - d) // 2, (s - d) // 2, d, d)
|
|
493
|
+
c.set_style_radius(lv.RADIUS_CIRCLE, 0)
|
|
494
|
+
c.set_style_border_width(1, 0)
|
|
495
|
+
c.set_style_border_opa(opa, 0)
|
|
496
|
+
self.call_rings.append(c)
|
|
497
|
+
self.call_mark = glyphs.tinted(rings, "handset", max(8, ring // 4), lv.color_hex(GREEN))
|
|
498
|
+
self.call_mark.center()
|
|
499
|
+
_show(rings, s > 0)
|
|
500
|
+
cx, cy, cw, ch = lay.call_text
|
|
501
|
+
col = _box(card, cx, cy, cw, ch)
|
|
502
|
+
col.set_flex_flow(lv.FLEX_FLOW.COLUMN)
|
|
503
|
+
col.set_style_pad_row(8 if lay.size == "large" else 4, 0)
|
|
504
|
+
if lay.center:
|
|
505
|
+
col.set_flex_align(lv.FLEX_ALIGN.START, lv.FLEX_ALIGN.CENTER, lv.FLEX_ALIGN.CENTER)
|
|
506
|
+
small_font = lay.size == "small"
|
|
507
|
+
self.call_word = _label(col, F_SMALL, GREEN, 2)
|
|
508
|
+
self.caller = _label(col, lay.caller_font, TEXT)
|
|
509
|
+
self.caller.set_size(cw, lay.caller_font.get_line_height())
|
|
510
|
+
self.caller.set_long_mode(lv.label.LONG_MODE.DOTS)
|
|
511
|
+
self.call_phone = _label(col, F_SMALL if small_font else F_BODY, SUB)
|
|
512
|
+
self.call_time = _label(col, F_BODY if small_font else F_BIG, MUTED, 1)
|
|
513
|
+
self.call_note = _label(col, F_TINY if small_font else F_SMALL, MUTED)
|
|
514
|
+
self.call_note.set_width(cw)
|
|
515
|
+
if lay.size != "large":
|
|
516
|
+
self.call_note.set_height((F_TINY if small_font else F_SMALL).get_line_height())
|
|
517
|
+
self.call_note.set_long_mode(lv.label.LONG_MODE.DOTS)
|
|
518
|
+
if lay.center:
|
|
519
|
+
for lbl in (self.caller, self.call_note):
|
|
520
|
+
lbl.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
521
|
+
bx, by, ax = lay.call_buttons
|
|
522
|
+
small, big, gap = lay.call_rings
|
|
523
|
+
self._icon_small = small * 3 // 8
|
|
524
|
+
dy = (big - small) // 2
|
|
525
|
+
|
|
526
|
+
def button(x, y, d, icon, colour, fn):
|
|
527
|
+
return RingButton(card, x, y, d, BLACK, icon=glyphs.image(icon, d * 3 // 8), on_press=lambda b: fn(),
|
|
528
|
+
color=colour, ring=1 if d == small else 2, hit=d + 20)
|
|
529
|
+
|
|
530
|
+
def caption(x, d, text):
|
|
531
|
+
lbl = _label(card, F_TINY if small_font else F_SMALL, MUTED)
|
|
532
|
+
lbl.set_text(text)
|
|
533
|
+
lbl.update_layout() # one line, centred under its button
|
|
534
|
+
lbl.set_pos(x + d // 2 - lbl.get_width() // 2, by + big + (4 if small_font else 10))
|
|
535
|
+
return lbl
|
|
536
|
+
|
|
537
|
+
# Ringing: decline, then answer.
|
|
538
|
+
self.decline = button(bx, by, big, "hangup", RED, lambda: on["hangup"]())
|
|
539
|
+
self.answer = button(bx + big + gap * 2, by, big, "handset", GREEN, lambda: on["answer"]())
|
|
540
|
+
self.ring_labels = [caption(bx, big, "Decline"), caption(bx + big + gap * 2, big, "Answer")]
|
|
541
|
+
# Answered: mute, where the audio goes, and hang up.
|
|
542
|
+
self.mute = button(ax, by + dy, small, "mic", 0xDCE3EC, lambda: on["mute"]())
|
|
543
|
+
self.route = button(ax + small + gap, by + dy, small, "phone", 0xDCE3EC, lambda: on["route"]())
|
|
544
|
+
hx = ax + 2 * (small + gap)
|
|
545
|
+
self.hang = button(hx, by, big, "hangup", RED, lambda: on["hangup"]())
|
|
546
|
+
self.call_labels = [caption(ax, small, "Mute"), caption(ax + small + gap, small, "Use phone"),
|
|
547
|
+
caption(hx, big, "Hang up")]
|
|
548
|
+
_show(card, False)
|
|
549
|
+
|
|
550
|
+
def _pairing(self, on):
|
|
551
|
+
lay = self.lay
|
|
552
|
+
cover = lay.cover[2] > 0
|
|
553
|
+
_show(self.pair, on and cover)
|
|
554
|
+
_show(self.steps, on and lay.steps is not None)
|
|
555
|
+
if not on:
|
|
556
|
+
_show(self.para, False)
|
|
557
|
+
_show(self.cover_box, not on and cover)
|
|
558
|
+
_show(self.edge, not on and cover)
|
|
559
|
+
|
|
560
|
+
def _playback(self, on, transport=None):
|
|
561
|
+
"""Show the progress and spectrum while a track is loaded; the
|
|
562
|
+
transport while connected."""
|
|
563
|
+
nowplaying.NowPlaying._playback(self, on, transport)
|
|
564
|
+
self._modes_on = on if transport is None else transport
|
|
565
|
+
self._place_modes()
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
def switch_header(scope):
|
|
569
|
+
"""The shell's header when the calls setting fits in it, else None: a
|
|
570
|
+
short header (a narrow bar) keeps its room for the title."""
|
|
571
|
+
header = getattr(scope, "header", None)
|
|
572
|
+
if header is not None:
|
|
573
|
+
header.update_layout()
|
|
574
|
+
if header.get_width() < HEADER_ROOM:
|
|
575
|
+
return None
|
|
576
|
+
return header
|
|
577
|
+
|
|
578
|
+
|
|
579
|
+
def calls_switch(scope, on, changed, lay=None):
|
|
580
|
+
"""The calls setting, a labelled switch at the right of the shell's
|
|
581
|
+
header, or where *lay* (the screen's `Layout`) keeps room for it in the
|
|
582
|
+
app's area, *on* or off. *changed* gets the new setting each time it's
|
|
583
|
+
flipped. The status line moves to its left."""
|
|
584
|
+
header = switch_header(scope)
|
|
585
|
+
parent = header or scope.root
|
|
586
|
+
small = lay is not None and lay.size == "small" and header is None
|
|
587
|
+
sw = lv.switch(parent)
|
|
588
|
+
sw.set_size(40, 22) if small else sw.set_size(48, 26)
|
|
589
|
+
sw.set_style_bg_color(lv.color_hex(LINE), lv.PART.MAIN)
|
|
590
|
+
sw.set_style_bg_color(lv.color_hex(TEAL), lv.PART.INDICATOR | lv.STATE.CHECKED)
|
|
591
|
+
sw.set_style_bg_color(lv.color_hex(TEXT), lv.PART.KNOB)
|
|
592
|
+
sw.set_ext_click_area(12)
|
|
593
|
+
if on:
|
|
594
|
+
sw.add_state(lv.STATE.CHECKED)
|
|
595
|
+
lbl = _label(parent, F_TINY if small else F_SMALL, SUB)
|
|
596
|
+
lbl.set_text(CALLS_LABEL)
|
|
597
|
+
where = lay.switch_at if lay is not None else None
|
|
598
|
+
centred = header is None and where is not None and where[0] == "center"
|
|
599
|
+
if small and not centred:
|
|
600
|
+
# Two short lines beside the switch.
|
|
601
|
+
lbl.set_width(SWITCH_ROOM[1] - 40 - 10 - 16)
|
|
602
|
+
if centred:
|
|
603
|
+
# A row of its own in the band *where* gives, the label on two
|
|
604
|
+
# lines when one is too wide for it, or a handset in its place.
|
|
605
|
+
_, y, bx, bw = where
|
|
606
|
+
if lay.switch_icon:
|
|
607
|
+
lbl.delete()
|
|
608
|
+
lbl = glyphs.tinted(parent, "handset", 20, lv.color_hex(SUB))
|
|
609
|
+
lbl.update_layout()
|
|
610
|
+
room = bw - 10 - sw.get_width()
|
|
611
|
+
if lbl.get_width() > room:
|
|
612
|
+
lbl.set_width(room)
|
|
613
|
+
lbl.update_layout()
|
|
614
|
+
row = lbl.get_width() + 10 + sw.get_width()
|
|
615
|
+
sw.set_pos(bx + (bw - row) // 2 + row - sw.get_width(), y + (lay.switch_h - sw.get_height()) // 2)
|
|
616
|
+
elif header is not None:
|
|
617
|
+
sw.align(lv.ALIGN.RIGHT_MID, -16, 0)
|
|
618
|
+
else:
|
|
619
|
+
sw.align(lv.ALIGN.TOP_RIGHT, -16 if lay is None else -lay.m - 4, 8 if where is None else where[1])
|
|
620
|
+
lbl.align_to(sw, lv.ALIGN.OUT_LEFT_MID, -10, 0)
|
|
621
|
+
status = getattr(scope, "status", None)
|
|
622
|
+
if status is not None and header is not None:
|
|
623
|
+
# Its text changes after this: right-aligned in a fixed width, it
|
|
624
|
+
# stays clear of the label.
|
|
625
|
+
status.set_width(STATUS_W)
|
|
626
|
+
status.set_style_text_align(lv.TEXT_ALIGN.RIGHT, 0)
|
|
627
|
+
status.align_to(lbl, lv.ALIGN.OUT_LEFT_MID, -24, 0)
|
|
628
|
+
|
|
629
|
+
def flipped(e):
|
|
630
|
+
changed(sw.has_state(lv.STATE.CHECKED))
|
|
631
|
+
|
|
632
|
+
sw.add_event_cb(flipped, lv.EVENT.VALUE_CHANGED, None)
|
|
633
|
+
return sw
|