omnipython-applibs 0.1.2__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.
- appkit/__init__.py +52 -0
- appkit/__init__.pyi +17 -0
- appkit/data.py +149 -0
- appkit/data.pyi +25 -0
- appkit/foreground.py +357 -0
- appkit/foreground.pyi +45 -0
- appkit/home.py +19 -0
- appkit/home.pyi +8 -0
- appkit/hover.py +59 -0
- appkit/hover.pyi +13 -0
- appkit/index.py +199 -0
- appkit/index.pyi +30 -0
- appkit/launcher.py +1075 -0
- appkit/launcher.pyi +96 -0
- appkit/manifest.py +75 -0
- appkit/manifest.pyi +8 -0
- appkit/net.py +167 -0
- appkit/net.pyi +34 -0
- appkit/places.py +202 -0
- appkit/places.pyi +39 -0
- appkit/py.typed +0 -0
- appkit/scope.py +636 -0
- appkit/scope.pyi +110 -0
- appkit/shell.py +121 -0
- appkit/shell.pyi +32 -0
- appkit/worker.py +409 -0
- appkit/worker.pyi +83 -0
- controlkit/__init__.py +19 -0
- controlkit/__init__.pyi +10 -0
- controlkit/_draw.py +88 -0
- controlkit/_safe.py +29 -0
- controlkit/dotmatrix.py +101 -0
- controlkit/dotmatrix.pyi +23 -0
- controlkit/encoder.py +297 -0
- controlkit/encoder.pyi +55 -0
- controlkit/font5x7.py +22 -0
- controlkit/font5x7.pyi +11 -0
- controlkit/lamp_button.py +92 -0
- controlkit/lamp_button.pyi +40 -0
- controlkit/meter.py +86 -0
- controlkit/meter.pyi +30 -0
- controlkit/mock.py +116 -0
- controlkit/mock.pyi +35 -0
- controlkit/pad_grid.py +113 -0
- controlkit/pad_grid.pyi +41 -0
- controlkit/py.typed +0 -0
- controlkit/slider.py +185 -0
- controlkit/slider.pyi +49 -0
- controlkit/sprites.py +279 -0
- controlkit/sprites.pyi +22 -0
- controlkit/theme.py +120 -0
- controlkit/theme.pyi +15 -0
- deskkit/__init__.py +74 -0
- deskkit/__init__.pyi +18 -0
- deskkit/forecast.py +261 -0
- deskkit/forecast.pyi +40 -0
- deskkit/localtime.py +215 -0
- deskkit/localtime.pyi +33 -0
- deskkit/py.typed +0 -0
- deskkit/shell.py +113 -0
- deskkit/shell.pyi +33 -0
- omnipython_applibs-0.1.2.dist-info/METADATA +90 -0
- omnipython_applibs-0.1.2.dist-info/RECORD +143 -0
- omnipython_applibs-0.1.2.dist-info/WHEEL +5 -0
- omnipython_applibs-0.1.2.dist-info/licenses/LICENSE +21 -0
- omnipython_applibs-0.1.2.dist-info/top_level.txt +9 -0
- programkit/__init__.py +27 -0
- programkit/__init__.pyi +8 -0
- programkit/board.py +56 -0
- programkit/board.pyi +20 -0
- programkit/press.py +63 -0
- programkit/press.pyi +17 -0
- programkit/py.typed +0 -0
- programkit/rows.py +149 -0
- programkit/rows.pyi +34 -0
- sayso/__init__.py +109 -0
- sayso/__init__.pyi +124 -0
- sayso/auth.py +811 -0
- sayso/auth.pyi +102 -0
- sayso/client.py +1286 -0
- sayso/client.pyi +138 -0
- sayso/keepalive.py +371 -0
- sayso/keepalive.pyi +53 -0
- sayso/local.py +85 -0
- sayso/local.pyi +28 -0
- sayso/object_specs.py +706 -0
- sayso/object_specs.pyi +8 -0
- sayso/objects.py +411 -0
- sayso/objects.pyi +854 -0
- sayso/py.typed +0 -0
- sayso/schema_coverage.py +210 -0
- sayso/schema_coverage.pyi +13 -0
- sayso/transport.py +426 -0
- sayso/transport.pyi +47 -0
- songmodel/__init__.py +30 -0
- songmodel/__init__.pyi +9 -0
- songmodel/link.py +189 -0
- songmodel/link.pyi +53 -0
- songmodel/model.py +238 -0
- songmodel/model.pyi +40 -0
- songmodel/page.html +225 -0
- songmodel/page_data.py +236 -0
- songmodel/page_data.pyi +6 -0
- songmodel/py.typed +0 -0
- soundmodule/__init__.py +7 -0
- soundmodule/__init__.pyi +6 -0
- soundmodule/engine.py +1001 -0
- soundmodule/engine.pyi +196 -0
- soundmodule/names.py +298 -0
- soundmodule/names.pyi +30 -0
- soundmodule/pipes.py +105 -0
- soundmodule/pipes.pyi +31 -0
- soundmodule/py.typed +0 -0
- soundmodule/run.py +249 -0
- soundmodule/run.pyi +49 -0
- spectrum/__init__.py +72 -0
- spectrum/__init__.pyi +30 -0
- spectrum/analyzer.py +231 -0
- spectrum/analyzer.pyi +67 -0
- spectrum/fake_music.py +201 -0
- spectrum/fake_music.pyi +36 -0
- spectrum/pump_levels.py +126 -0
- spectrum/pump_levels.pyi +46 -0
- spectrum/py.typed +0 -0
- spectrum/spectrum_view.py +403 -0
- spectrum/spectrum_view.pyi +80 -0
- touchkit/__init__.py +4 -0
- touchkit/__init__.pyi +4 -0
- touchkit/cam.py +146 -0
- touchkit/cam.pyi +35 -0
- touchkit/clock.py +18 -0
- touchkit/clock.pyi +6 -0
- touchkit/ecp.py +134 -0
- touchkit/ecp.pyi +28 -0
- touchkit/net.py +347 -0
- touchkit/net.pyi +27 -0
- touchkit/py.typed +0 -0
- touchkit/settings.py +85 -0
- touchkit/settings.pyi +17 -0
- touchkit/shell.py +268 -0
- touchkit/shell.pyi +42 -0
- touchkit/ui.py +167 -0
- touchkit/ui.pyi +53 -0
controlkit/slider.py
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""A fader: a groove, a cap that slides along it, and an optional lamp.
|
|
5
|
+
|
|
6
|
+
Vertical by default, with the lamp above the groove; horizontal puts the lamp
|
|
7
|
+
past its right end. Values run 0 to 127, as every control here does.
|
|
8
|
+
|
|
9
|
+
- drag the cap along the groove; the value follows the pointer, to the pixel;
|
|
10
|
+
- the wheel and the arrow keys step it one at a time, Home and End go to the ends;
|
|
11
|
+
- ``set_value()`` shows a value without calling ``on_change``, so a host that
|
|
12
|
+
moves the slider never hears its own echo back.
|
|
13
|
+
|
|
14
|
+
The slider's ``obj`` takes focus like an encoder, so add it to a group to
|
|
15
|
+
turn it from a wheel. ``set_led(rgb)`` lights the lamp, and ``None`` darkens
|
|
16
|
+
it; a slider built without ``led=True`` has no lamp and ignores the call.
|
|
17
|
+
"""
|
|
18
|
+
|
|
19
|
+
import lvgl as lv
|
|
20
|
+
|
|
21
|
+
from ._draw import Lamp, box, fill, label, plain
|
|
22
|
+
from ._safe import safe
|
|
23
|
+
|
|
24
|
+
MAX = 127
|
|
25
|
+
_LEGEND_H = 16
|
|
26
|
+
_LAMP_R = 4
|
|
27
|
+
_LAMP_SPACE = 14
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class Slider:
|
|
31
|
+
"""A fader at (*x*, *y*) in *parent*, *width* x *height*, edited 0 to 127."""
|
|
32
|
+
|
|
33
|
+
def __init__(self, parent, x, y, width, height, theme, legend="", vertical=True, value=0, led=False, on_change=None):
|
|
34
|
+
self.theme = theme
|
|
35
|
+
self.vertical = vertical
|
|
36
|
+
self.value = 0
|
|
37
|
+
self.on_change = on_change
|
|
38
|
+
self._drag = None
|
|
39
|
+
self.legend_h = _LEGEND_H if legend else 0
|
|
40
|
+
|
|
41
|
+
cell = plain(lv.obj(parent), clickable=True)
|
|
42
|
+
cell.set_pos(x, y)
|
|
43
|
+
cell.set_size(width, height)
|
|
44
|
+
self.obj = cell
|
|
45
|
+
self.width = width
|
|
46
|
+
self.height = height
|
|
47
|
+
|
|
48
|
+
if legend:
|
|
49
|
+
text = label(cell, legend.upper(), theme["legend"], None, 1)
|
|
50
|
+
text.set_width(width)
|
|
51
|
+
text.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
|
|
52
|
+
text.set_pos(0, 0)
|
|
53
|
+
self.legend = text
|
|
54
|
+
|
|
55
|
+
lamp_space = _LAMP_SPACE if led else 0
|
|
56
|
+
if vertical:
|
|
57
|
+
self.cap_w = min(width - 6, 34)
|
|
58
|
+
self.cap_h = 12
|
|
59
|
+
cx = width // 2
|
|
60
|
+
top = self.legend_h + lamp_space + self.cap_h // 2 + 2
|
|
61
|
+
bottom = height - self.cap_h // 2 - 2
|
|
62
|
+
self._span = (top, bottom)
|
|
63
|
+
self._cx = cx
|
|
64
|
+
self._groove(cell, box(cell, cx - max(2, width // 16), top, max(4, width // 8), bottom - top))
|
|
65
|
+
if led:
|
|
66
|
+
self.lamp = Lamp(cell, cx, self.legend_h + _LAMP_R + 2, _LAMP_R, theme)
|
|
67
|
+
else:
|
|
68
|
+
self.cap_w = 12
|
|
69
|
+
self.cap_h = min(height - self.legend_h - 6, 34)
|
|
70
|
+
cy = self.legend_h + (height - self.legend_h) // 2
|
|
71
|
+
left = self.cap_w // 2 + 2
|
|
72
|
+
right = width - self.cap_w // 2 - 2 - lamp_space
|
|
73
|
+
self._span = (left, right)
|
|
74
|
+
self._cy = cy
|
|
75
|
+
self._groove(cell, box(cell, left, cy - max(2, self.cap_h // 6), right - left, max(4, self.cap_h // 3)))
|
|
76
|
+
if led:
|
|
77
|
+
self.lamp = Lamp(cell, width - _LAMP_R - 2, cy, _LAMP_R, theme)
|
|
78
|
+
if not led:
|
|
79
|
+
self.lamp = None
|
|
80
|
+
|
|
81
|
+
self.cap = box(cell, 0, 0, self.cap_w, self.cap_h)
|
|
82
|
+
fill(self.cap, theme["knob_cap_light"], theme["knob_cap"])
|
|
83
|
+
self.cap.set_style_radius(3, 0)
|
|
84
|
+
self.cap.set_style_border_width(1, 0)
|
|
85
|
+
self.cap.set_style_border_color(lv.color_hex(theme["pad_edge"]), 0)
|
|
86
|
+
line = box(self.cap, 2, self.cap_h // 2 - 1, self.cap_w - 4, 2) if vertical else box(self.cap, self.cap_w // 2 - 1, 2, 2, self.cap_h - 4)
|
|
87
|
+
fill(line, theme["pointer"])
|
|
88
|
+
|
|
89
|
+
cell.add_event_cb(safe(self._on_pressed), lv.EVENT.PRESSED, None)
|
|
90
|
+
cell.add_event_cb(safe(self._on_pressing), lv.EVENT.PRESSING, None)
|
|
91
|
+
cell.add_event_cb(safe(self._on_released), lv.EVENT.RELEASED, None)
|
|
92
|
+
cell.add_event_cb(safe(self._on_released), lv.EVENT.PRESS_LOST, None)
|
|
93
|
+
cell.add_event_cb(safe(self._on_key), lv.EVENT.KEY, None)
|
|
94
|
+
cell.add_event_cb(safe(self._on_focus), lv.EVENT.FOCUSED, None)
|
|
95
|
+
cell.add_event_cb(safe(self._on_defocus), lv.EVENT.DEFOCUSED, None)
|
|
96
|
+
self._show(max(0, min(MAX, int(value))))
|
|
97
|
+
|
|
98
|
+
def _groove(self, cell, groove):
|
|
99
|
+
fill(groove, self.theme["display_bezel"], self.theme["pad_edge"])
|
|
100
|
+
groove.set_style_radius(2, 0)
|
|
101
|
+
|
|
102
|
+
# ---- what the host calls -------------------------------------------------
|
|
103
|
+
|
|
104
|
+
def set_value(self, value):
|
|
105
|
+
"""Show *value* (0 to 127) without calling ``on_change``."""
|
|
106
|
+
self._show(0 if value < 0 else (MAX if value > MAX else int(value)))
|
|
107
|
+
|
|
108
|
+
def set_led(self, rgb):
|
|
109
|
+
"""Light the lamp in *rgb*, or darken it with None. No-op without a lamp."""
|
|
110
|
+
if self.lamp is not None:
|
|
111
|
+
self.lamp.set(rgb)
|
|
112
|
+
|
|
113
|
+
# ---- drawing -------------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
def _show(self, value):
|
|
116
|
+
self.value = value
|
|
117
|
+
start, end = self._span
|
|
118
|
+
t = value / MAX
|
|
119
|
+
if self.vertical:
|
|
120
|
+
y = end - t * (end - start)
|
|
121
|
+
self.cap.set_pos(self._cx - self.cap_w // 2, int(y - self.cap_h / 2))
|
|
122
|
+
else:
|
|
123
|
+
x = start + t * (end - start)
|
|
124
|
+
self.cap.set_pos(int(x - self.cap_w / 2), self._cy - self.cap_h // 2)
|
|
125
|
+
|
|
126
|
+
def _change(self, value):
|
|
127
|
+
value = 0 if value < 0 else (MAX if value > MAX else int(value))
|
|
128
|
+
if value == self.value:
|
|
129
|
+
return
|
|
130
|
+
self._show(value)
|
|
131
|
+
if self.on_change is not None:
|
|
132
|
+
self.on_change(self, value)
|
|
133
|
+
|
|
134
|
+
# ---- input ---------------------------------------------------------------
|
|
135
|
+
|
|
136
|
+
def _point(self):
|
|
137
|
+
indev = lv.indev_active()
|
|
138
|
+
if indev is None:
|
|
139
|
+
return None
|
|
140
|
+
p = lv.point_t()
|
|
141
|
+
indev.get_point(p)
|
|
142
|
+
return p.x, p.y
|
|
143
|
+
|
|
144
|
+
def _on_pressed(self, _event):
|
|
145
|
+
point = self._point()
|
|
146
|
+
if point is not None:
|
|
147
|
+
self._drag = (point[0], point[1], self.value)
|
|
148
|
+
|
|
149
|
+
def _on_released(self, _event):
|
|
150
|
+
self._drag = None
|
|
151
|
+
|
|
152
|
+
def _on_pressing(self, _event):
|
|
153
|
+
point = self._point()
|
|
154
|
+
if point is None:
|
|
155
|
+
return
|
|
156
|
+
if self._drag is None:
|
|
157
|
+
# The first report of a press anchors the drag where the pointer is.
|
|
158
|
+
self._drag = (point[0], point[1], self.value)
|
|
159
|
+
x0, y0, start = self._drag
|
|
160
|
+
low, high = self._span
|
|
161
|
+
travel = max(1, high - low)
|
|
162
|
+
if self.vertical:
|
|
163
|
+
moved = (y0 - point[1]) * MAX / travel
|
|
164
|
+
else:
|
|
165
|
+
moved = (point[0] - x0) * MAX / travel
|
|
166
|
+
self._change(start + int(moved))
|
|
167
|
+
|
|
168
|
+
def _on_key(self, event):
|
|
169
|
+
key = event.get_key()
|
|
170
|
+
if key in (lv.KEY.RIGHT, lv.KEY.UP):
|
|
171
|
+
self._change(self.value + 1)
|
|
172
|
+
elif key in (lv.KEY.LEFT, lv.KEY.DOWN):
|
|
173
|
+
self._change(self.value - 1)
|
|
174
|
+
elif key == lv.KEY.HOME:
|
|
175
|
+
self._change(0)
|
|
176
|
+
elif key == lv.KEY.END:
|
|
177
|
+
self._change(MAX)
|
|
178
|
+
|
|
179
|
+
def _on_focus(self, _event):
|
|
180
|
+
if self.legend_h:
|
|
181
|
+
self.legend.set_style_text_color(lv.color_hex(self.theme["legend_lit"]), 0)
|
|
182
|
+
|
|
183
|
+
def _on_defocus(self, _event):
|
|
184
|
+
if self.legend_h:
|
|
185
|
+
self.legend.set_style_text_color(lv.color_hex(self.theme["legend"]), 0)
|
controlkit/slider.pyi
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""A fader: a groove, a cap that slides along it, and an optional lamp."""
|
|
5
|
+
from collections.abc import Callable
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .theme import _Theme
|
|
9
|
+
|
|
10
|
+
MAX: int
|
|
11
|
+
|
|
12
|
+
class _Lamp:
|
|
13
|
+
rgb: int | None
|
|
14
|
+
def set(self, rgb: int | None) -> None: ...
|
|
15
|
+
|
|
16
|
+
class Slider:
|
|
17
|
+
"""A fader at (`x`, `y`) in `parent`, `width` x `height`, edited 0 to 127."""
|
|
18
|
+
|
|
19
|
+
theme: _Theme
|
|
20
|
+
vertical: bool
|
|
21
|
+
value: int
|
|
22
|
+
on_change: Callable[[Slider, int], None] | None
|
|
23
|
+
legend_h: int
|
|
24
|
+
obj: Any
|
|
25
|
+
width: int
|
|
26
|
+
height: int
|
|
27
|
+
legend: Any
|
|
28
|
+
cap_w: int
|
|
29
|
+
cap_h: int
|
|
30
|
+
lamp: _Lamp | None
|
|
31
|
+
cap: Any
|
|
32
|
+
def __init__(
|
|
33
|
+
self,
|
|
34
|
+
parent: Any,
|
|
35
|
+
x: int,
|
|
36
|
+
y: int,
|
|
37
|
+
width: int,
|
|
38
|
+
height: int,
|
|
39
|
+
theme: _Theme,
|
|
40
|
+
legend: str = '',
|
|
41
|
+
vertical: bool = True,
|
|
42
|
+
value: int = 0,
|
|
43
|
+
led: bool = False,
|
|
44
|
+
on_change: Callable[[Slider, int], None] | None = None,
|
|
45
|
+
) -> None: ...
|
|
46
|
+
def set_value(self, value: float) -> None:
|
|
47
|
+
"""Show `value` (0 to 127) without calling `on_change`."""
|
|
48
|
+
def set_led(self, rgb: int | None) -> None:
|
|
49
|
+
"""Light the lamp in `rgb`, or darken it with None. No-op without a lamp."""
|
controlkit/sprites.py
ADDED
|
@@ -0,0 +1,279 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The panel's artwork, painted once and shared.
|
|
5
|
+
|
|
6
|
+
Everything that looks machined (a knob, its ring of unlit LEDs, a lit LED
|
|
7
|
+
with its glow, a screw head) is painted here onto a canvas, once per size
|
|
8
|
+
and theme, and then shown as an image as many times as the panel needs it.
|
|
9
|
+
Sixteen encoders cost one painting, and a redraw is an image copy.
|
|
10
|
+
The buffers are kept for the life of the program, so a panel built again
|
|
11
|
+
at the same size paints nothing.
|
|
12
|
+
"""
|
|
13
|
+
|
|
14
|
+
import math
|
|
15
|
+
|
|
16
|
+
import lvgl as lv
|
|
17
|
+
|
|
18
|
+
_cache = {}
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _color(rgb):
|
|
22
|
+
return lv.color_hex(rgb)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class _Painter:
|
|
26
|
+
"""A transparent ARGB canvas and the few strokes the artwork needs."""
|
|
27
|
+
|
|
28
|
+
def __init__(self, width, height):
|
|
29
|
+
self.width = width
|
|
30
|
+
self.height = height
|
|
31
|
+
self.buf = lv.draw_buf_create(width, height, lv.COLOR_FORMAT.ARGB8888, 0)
|
|
32
|
+
self.canvas = lv.canvas(lv.layer_top())
|
|
33
|
+
self.canvas.add_flag(lv.obj.FLAG.HIDDEN)
|
|
34
|
+
self.canvas.set_draw_buf(self.buf)
|
|
35
|
+
self.canvas.fill_bg(_color(0), lv.OPA.TRANSP)
|
|
36
|
+
self.layer = lv.layer_t()
|
|
37
|
+
self.canvas.init_layer(self.layer)
|
|
38
|
+
self._rect = lv.draw_rect_dsc_t()
|
|
39
|
+
self._arc = lv.draw_arc_dsc_t()
|
|
40
|
+
self._line = lv.draw_line_dsc_t()
|
|
41
|
+
|
|
42
|
+
def disc(self, cx, cy, r, rgb, opa=255):
|
|
43
|
+
"""A filled circle of radius *r* (pixels, may be fractional)."""
|
|
44
|
+
if r <= 0 or opa <= 0:
|
|
45
|
+
return
|
|
46
|
+
d = self._rect
|
|
47
|
+
d.init()
|
|
48
|
+
d.bg_color = _color(rgb)
|
|
49
|
+
d.bg_opa = int(opa)
|
|
50
|
+
d.radius = lv.RADIUS_CIRCLE
|
|
51
|
+
area = lv.area_t()
|
|
52
|
+
area.x1 = int(cx - r + 0.5)
|
|
53
|
+
area.y1 = int(cy - r + 0.5)
|
|
54
|
+
area.x2 = int(cx + r - 0.5)
|
|
55
|
+
area.y2 = int(cy + r - 0.5)
|
|
56
|
+
lv.draw_rect(self.layer, d, area)
|
|
57
|
+
|
|
58
|
+
def ring(self, cx, cy, r, width, rgb, opa=255, start=0, end=360):
|
|
59
|
+
"""An arc of outer radius *r*, *width* thick, from *start* to *end* degrees."""
|
|
60
|
+
if opa <= 0:
|
|
61
|
+
return
|
|
62
|
+
a = self._arc
|
|
63
|
+
a.init()
|
|
64
|
+
a.center = lv.point_t({"x": int(cx), "y": int(cy)})
|
|
65
|
+
a.radius = int(r)
|
|
66
|
+
a.width = int(width)
|
|
67
|
+
a.color = _color(rgb)
|
|
68
|
+
a.opa = int(opa)
|
|
69
|
+
a.start_angle = start
|
|
70
|
+
a.end_angle = end
|
|
71
|
+
a.rounded = False
|
|
72
|
+
lv.draw_arc(self.layer, a)
|
|
73
|
+
|
|
74
|
+
def line(self, x1, y1, x2, y2, width, rgb, opa=255, round_ends=False):
|
|
75
|
+
d = self._line
|
|
76
|
+
d.init()
|
|
77
|
+
d.p1 = lv.point_precise_t({"x": x1, "y": y1})
|
|
78
|
+
d.p2 = lv.point_precise_t({"x": x2, "y": y2})
|
|
79
|
+
d.width = int(width)
|
|
80
|
+
d.color = _color(rgb)
|
|
81
|
+
d.opa = int(opa)
|
|
82
|
+
d.round_start = 1 if round_ends else 0
|
|
83
|
+
d.round_end = 1 if round_ends else 0
|
|
84
|
+
lv.draw_line(self.layer, d)
|
|
85
|
+
|
|
86
|
+
def glow(self, cx, cy, r_inner, r_outer, rgb, peak, steps=None):
|
|
87
|
+
"""A soft halo: stacked discs that add up to *peak* at *r_inner*."""
|
|
88
|
+
span = r_outer - r_inner
|
|
89
|
+
if span <= 0:
|
|
90
|
+
return
|
|
91
|
+
if steps is None:
|
|
92
|
+
steps = max(3, int(span))
|
|
93
|
+
each = max(1, int(peak / steps))
|
|
94
|
+
for i in range(steps):
|
|
95
|
+
r = r_outer - span * i / steps
|
|
96
|
+
self.disc(cx, cy, r, rgb, each)
|
|
97
|
+
|
|
98
|
+
def finish(self):
|
|
99
|
+
self.canvas.finish_layer(self.layer)
|
|
100
|
+
self.canvas.delete()
|
|
101
|
+
self.canvas = None
|
|
102
|
+
return self.buf
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
def led_angles(count=16, start=135, sweep=270):
|
|
106
|
+
"""The angle of each LED, in degrees clockwise from three o'clock."""
|
|
107
|
+
if count < 2:
|
|
108
|
+
return [start]
|
|
109
|
+
return [start + sweep * i / (count - 1) for i in range(count)]
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def knob(geometry, theme):
|
|
113
|
+
"""The encoder's static art: unlit LEDs, the knob's shadow, skirt and cap.
|
|
114
|
+
|
|
115
|
+
*geometry* is the dict ``encoder.geometry()`` returns.
|
|
116
|
+
"""
|
|
117
|
+
key = ("knob", geometry["size"], geometry["led_ring"], geometry["knob_r"], theme["name"])
|
|
118
|
+
if key in _cache:
|
|
119
|
+
return _cache[key]
|
|
120
|
+
size = geometry["size"]
|
|
121
|
+
c = size / 2
|
|
122
|
+
led_ring = geometry["led_ring"]
|
|
123
|
+
lens = geometry["lens_r"]
|
|
124
|
+
knob_r = geometry["knob_r"]
|
|
125
|
+
p = _Painter(size, size)
|
|
126
|
+
|
|
127
|
+
# The unlit LEDs: dark red lenses set into the faceplate, each with a
|
|
128
|
+
# thin dark collar and a pin-point of reflected light.
|
|
129
|
+
for angle in led_angles():
|
|
130
|
+
a = math.radians(angle)
|
|
131
|
+
x = c + led_ring * math.cos(a)
|
|
132
|
+
y = c + led_ring * math.sin(a)
|
|
133
|
+
p.disc(x, y, lens + 1, theme["led_rim"])
|
|
134
|
+
p.disc(x, y, lens, theme["led_off"])
|
|
135
|
+
p.disc(x - lens * 0.35, y - lens * 0.35, max(0.8, lens * 0.35), 0xFFFFFF, 40)
|
|
136
|
+
|
|
137
|
+
# The knob's shadow, cast down and a little to the right.
|
|
138
|
+
p.glow(c + 1, c + knob_r * 0.12, knob_r * 0.9, knob_r * 1.22, theme["shadow"], 200)
|
|
139
|
+
|
|
140
|
+
# The skirt: a dark collar with knurled ridges round its edge.
|
|
141
|
+
p.disc(c, c, knob_r, theme["knob_skirt"])
|
|
142
|
+
ridges = 36 if knob_r >= 20 else 24
|
|
143
|
+
inner = knob_r * 0.80
|
|
144
|
+
for i in range(ridges):
|
|
145
|
+
a = 2 * math.pi * i / ridges
|
|
146
|
+
ca = math.cos(a)
|
|
147
|
+
sa = math.sin(a)
|
|
148
|
+
# Ridges facing the light (top left) catch it; the rest fall dark.
|
|
149
|
+
lit = -(ca * 0.6 + sa * 0.8)
|
|
150
|
+
rgb = theme["knurl_light"] if lit > -0.2 else theme["knurl_dark"]
|
|
151
|
+
opa = int(90 + 120 * max(0.0, lit)) if lit > -0.2 else 220
|
|
152
|
+
p.line(c + inner * ca, c + inner * sa, c + (knob_r - 0.6) * ca, c + (knob_r - 0.6) * sa, 1, rgb, opa)
|
|
153
|
+
p.ring(c, c, knob_r, 1, theme["knurl_dark"], 255)
|
|
154
|
+
|
|
155
|
+
# The cap: a spun disc, lighter towards the top, with fine machining
|
|
156
|
+
# rings and a bright rim where the light catches it.
|
|
157
|
+
cap = knob_r * 0.74
|
|
158
|
+
p.disc(c, c, cap + 1, theme["knurl_dark"])
|
|
159
|
+
p.disc(c, c, cap, theme["knob_cap"])
|
|
160
|
+
p.disc(c, c - cap * 0.18, cap * 0.86, theme["knob_cap_light"], 46)
|
|
161
|
+
p.disc(c, c - cap * 0.32, cap * 0.62, theme["knob_cap_light"], 40)
|
|
162
|
+
radius = int(cap) - 2
|
|
163
|
+
while radius > 3:
|
|
164
|
+
p.ring(c, c, radius, 1, 0xFFFFFF, 10)
|
|
165
|
+
radius -= 3
|
|
166
|
+
p.ring(c, c, cap, 1, theme["knob_rim"], 200, 190, 350)
|
|
167
|
+
p.ring(c, c, cap, 1, 0x000000, 160, 10, 170)
|
|
168
|
+
buf = p.finish()
|
|
169
|
+
_cache[key] = buf
|
|
170
|
+
return buf
|
|
171
|
+
|
|
172
|
+
|
|
173
|
+
def led(lens, theme):
|
|
174
|
+
"""A lit LED: a hot core, its red lens, and a glow round it."""
|
|
175
|
+
key = ("led", lens, theme["name"])
|
|
176
|
+
if key in _cache:
|
|
177
|
+
return _cache[key]
|
|
178
|
+
halo = lens * 3 + 2
|
|
179
|
+
size = int(2 * halo) + 1
|
|
180
|
+
c = size / 2
|
|
181
|
+
p = _Painter(size, size)
|
|
182
|
+
p.glow(c, c, lens, halo, theme["led_glow"], 150)
|
|
183
|
+
p.disc(c, c, lens + 0.6, theme["led_on"])
|
|
184
|
+
p.disc(c, c, lens * 0.62, theme["led_core"], 210)
|
|
185
|
+
p.disc(c - lens * 0.3, c - lens * 0.3, max(0.8, lens * 0.32), 0xFFFFFF, 200)
|
|
186
|
+
buf = p.finish()
|
|
187
|
+
_cache[key] = (buf, size)
|
|
188
|
+
return _cache[key]
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
def small_led(lens, rgb, theme):
|
|
192
|
+
"""A lit indicator LED in colour *rgb*, for buttons and the status light."""
|
|
193
|
+
key = ("small", lens, rgb, theme["name"])
|
|
194
|
+
if key in _cache:
|
|
195
|
+
return _cache[key]
|
|
196
|
+
halo = lens * 3 + 2
|
|
197
|
+
size = int(2 * halo) + 1
|
|
198
|
+
c = size / 2
|
|
199
|
+
p = _Painter(size, size)
|
|
200
|
+
p.glow(c, c, lens, halo, rgb, 140)
|
|
201
|
+
p.disc(c, c, lens + 0.6, rgb)
|
|
202
|
+
p.disc(c, c, lens * 0.55, 0xFFFFFF, 150)
|
|
203
|
+
buf = p.finish()
|
|
204
|
+
_cache[key] = (buf, size)
|
|
205
|
+
return _cache[key]
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
def pointer(width, length, theme):
|
|
209
|
+
"""The cap's pointer, upright: a cream bar with rounded ends."""
|
|
210
|
+
key = ("pointer", width, length, theme["name"])
|
|
211
|
+
if key in _cache:
|
|
212
|
+
return _cache[key]
|
|
213
|
+
w = width + 2
|
|
214
|
+
p = _Painter(w, length)
|
|
215
|
+
half = w / 2
|
|
216
|
+
p.line(half, half, half, length - half, width + 1, 0x000000, 120, True)
|
|
217
|
+
p.line(half, half, half, length - half, width, theme["pointer"], 255, True)
|
|
218
|
+
buf = p.finish()
|
|
219
|
+
_cache[key] = buf
|
|
220
|
+
return buf
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
def screw(r, theme):
|
|
224
|
+
"""A cross-head screw, sunk flush."""
|
|
225
|
+
key = ("screw", r, theme["name"])
|
|
226
|
+
if key in _cache:
|
|
227
|
+
return _cache[key]
|
|
228
|
+
size = int(2 * r + 4)
|
|
229
|
+
c = size / 2
|
|
230
|
+
p = _Painter(size, size)
|
|
231
|
+
p.disc(c, c + 0.8, r + 1, 0x000000, 140)
|
|
232
|
+
p.disc(c, c, r, theme["screw"])
|
|
233
|
+
p.disc(c - r * 0.2, c - r * 0.25, r * 0.7, theme["screw_light"], 60)
|
|
234
|
+
p.ring(c, c, r, 1, theme["screw_light"], 120, 190, 340)
|
|
235
|
+
arm = r * 0.6
|
|
236
|
+
slot = max(1, int(r / 4))
|
|
237
|
+
p.line(c - arm, c - arm, c + arm, c + arm, slot, theme["screw_slot"], 255)
|
|
238
|
+
p.line(c - arm, c + arm, c + arm, c - arm, slot, theme["screw_slot"], 255)
|
|
239
|
+
buf = p.finish()
|
|
240
|
+
_cache[key] = (buf, size)
|
|
241
|
+
return _cache[key]
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
def _shade(rgb, delta):
|
|
245
|
+
r = min(255, max(0, ((rgb >> 16) & 255) + delta))
|
|
246
|
+
g = min(255, max(0, ((rgb >> 8) & 255) + delta))
|
|
247
|
+
b = min(255, max(0, (rgb & 255) + delta))
|
|
248
|
+
return (r << 16) | (g << 8) | b
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
def texture(rgb, brushed=False, size=64):
|
|
252
|
+
"""A tile of *rgb* with a fine grain, for a faceplate's finish.
|
|
253
|
+
|
|
254
|
+
Matte by default: speckled like bead-blasted metal. *brushed* adds the
|
|
255
|
+
long horizontal grain of brushed aluminium. The grain is a step or two
|
|
256
|
+
either side of *rgb*, which also hides the banding a smooth gradient
|
|
257
|
+
shows on a 16-bit panel.
|
|
258
|
+
"""
|
|
259
|
+
key = ("texture", rgb, brushed, size)
|
|
260
|
+
if key in _cache:
|
|
261
|
+
return _cache[key]
|
|
262
|
+
buf = lv.draw_buf_create(size, size, lv.COLOR_FORMAT.RGB565, 0)
|
|
263
|
+
canvas = lv.canvas(lv.layer_top())
|
|
264
|
+
canvas.add_flag(lv.obj.FLAG.HIDDEN)
|
|
265
|
+
canvas.set_draw_buf(buf)
|
|
266
|
+
shades = [lv.color_hex(_shade(rgb, d)) for d in (-6, -3, 0, 3, 6)]
|
|
267
|
+
seed = 12345
|
|
268
|
+
for y in range(size):
|
|
269
|
+
seed = (1103515245 * seed + 12345) & 0x7FFFFFFF
|
|
270
|
+
row = ((seed >> 16) % 3) - 1 if brushed else 0
|
|
271
|
+
for x in range(size):
|
|
272
|
+
seed = (1103515245 * seed + 12345) & 0x7FFFFFFF
|
|
273
|
+
n = (seed >> 16) % 8
|
|
274
|
+
level = 2 + row + (1 if n == 0 else (-1 if n == 1 else 0))
|
|
275
|
+
level = 0 if level < 0 else (4 if level > 4 else level)
|
|
276
|
+
canvas.set_px(x, y, shades[level], 255)
|
|
277
|
+
canvas.delete()
|
|
278
|
+
_cache[key] = buf
|
|
279
|
+
return buf
|
controlkit/sprites.pyi
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The panel's artwork, painted once and shared."""
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
from .theme import _Theme
|
|
8
|
+
|
|
9
|
+
def led_angles(count: int = 16, start: float = 135, sweep: float = 270) -> list[float]:
|
|
10
|
+
"""The angle of each LED, in degrees clockwise from three o'clock."""
|
|
11
|
+
def knob(geometry: dict[str, float], theme: _Theme) -> Any:
|
|
12
|
+
"""The encoder's static art: unlit LEDs, the knob's shadow, skirt and cap."""
|
|
13
|
+
def led(lens: float, theme: _Theme) -> tuple[Any, int]:
|
|
14
|
+
"""A lit LED: a hot core, its red lens, and a glow round it."""
|
|
15
|
+
def small_led(lens: float, rgb: int, theme: _Theme) -> tuple[Any, int]:
|
|
16
|
+
"""A lit indicator LED in colour `rgb`, for buttons and the status light."""
|
|
17
|
+
def pointer(width: int, length: int, theme: _Theme) -> Any:
|
|
18
|
+
"""The cap's pointer, upright: a cream bar with rounded ends."""
|
|
19
|
+
def screw(r: float, theme: _Theme) -> tuple[Any, int]:
|
|
20
|
+
"""A cross-head screw, sunk flush."""
|
|
21
|
+
def texture(rgb: int, brushed: bool = False, size: int = 64) -> Any:
|
|
22
|
+
"""A tile of `rgb` with a fine grain, for a faceplate's finish."""
|
controlkit/theme.py
ADDED
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The panel's finishes: every colour it draws, in one table per theme.
|
|
5
|
+
|
|
6
|
+
A theme is a plain dict of ``0xRRGGBB`` integers and a few strings. Copy one,
|
|
7
|
+
change what you like, and pass it to ``build(adapter, theme=...)``; any key
|
|
8
|
+
you leave out comes from ``black``.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
BLACK = {
|
|
12
|
+
"name": "black",
|
|
13
|
+
# The faceplate: matte black anodised aluminium, lit from above.
|
|
14
|
+
"face": 0x1B1C1F,
|
|
15
|
+
"face_bottom": 0x0E0F11,
|
|
16
|
+
"header": 0x121315,
|
|
17
|
+
"header_bottom": 0x0A0A0C,
|
|
18
|
+
"bevel_light": 0x34363B,
|
|
19
|
+
"bevel_dark": 0x000000,
|
|
20
|
+
# Screen-printed legends.
|
|
21
|
+
"legend": 0xC9CCD1,
|
|
22
|
+
"legend_dim": 0x6A6D73,
|
|
23
|
+
"legend_lit": 0xFF6A4D,
|
|
24
|
+
"rule": 0x3A3D43,
|
|
25
|
+
"header_legend": 0xC9CCD1,
|
|
26
|
+
"header_legend_dim": 0x6A6D73,
|
|
27
|
+
"brand": 0xE4E6EA,
|
|
28
|
+
# Encoder caps: a knurled black skirt and a spun cap.
|
|
29
|
+
"knob_skirt": 0x17181B,
|
|
30
|
+
"knurl_light": 0x45474D,
|
|
31
|
+
"knurl_dark": 0x050506,
|
|
32
|
+
"knob_cap": 0x26272B,
|
|
33
|
+
"knob_cap_light": 0x4A4C52,
|
|
34
|
+
"knob_rim": 0x5C5F66,
|
|
35
|
+
"pointer": 0xF2EEE4,
|
|
36
|
+
"shadow": 0x000000,
|
|
37
|
+
# The LEDs round each encoder.
|
|
38
|
+
"led_on": 0xFF2A14,
|
|
39
|
+
"led_core": 0xFFC2A8,
|
|
40
|
+
"led_glow": 0xFF2410,
|
|
41
|
+
"led_off": 0x3A0D08,
|
|
42
|
+
"led_rim": 0x0B0302,
|
|
43
|
+
# The dot-matrix display.
|
|
44
|
+
"display_bezel": 0x050506,
|
|
45
|
+
"display_bg": 0x120302,
|
|
46
|
+
"dot_on": 0xFF4A26,
|
|
47
|
+
"dot_off": 0x260805,
|
|
48
|
+
# Rubber pads, unlit and backlit.
|
|
49
|
+
"pad": 0x2E2F33,
|
|
50
|
+
"pad_bottom": 0x202124,
|
|
51
|
+
"pad_edge": 0x0A0A0B,
|
|
52
|
+
"pad_text": 0xA4A7AD,
|
|
53
|
+
"pad_empty_text": 0x46484D,
|
|
54
|
+
"pad_lit": 0xFF3A1E,
|
|
55
|
+
"pad_lit_bottom": 0xC8240F,
|
|
56
|
+
"pad_lit_text": 0xFFF3EC,
|
|
57
|
+
"pad_glow": 0xFF2A10,
|
|
58
|
+
"pad_tint": 0x3A2420,
|
|
59
|
+
# Small push buttons and their LEDs.
|
|
60
|
+
"button": 0x2A2B2F,
|
|
61
|
+
"button_bottom": 0x1A1B1E,
|
|
62
|
+
"button_text": 0xC9CCD1,
|
|
63
|
+
"status_ok": 0x37FF6E,
|
|
64
|
+
"status_bad": 0xFF2A14,
|
|
65
|
+
"status_wait": 0xFFB020,
|
|
66
|
+
"amber": 0xFFB020,
|
|
67
|
+
"screw": 0x3E4046,
|
|
68
|
+
"screw_light": 0x8A8D94,
|
|
69
|
+
"screw_slot": 0x0B0B0D,
|
|
70
|
+
# The line under the name on the faceplate; blank unless you want one.
|
|
71
|
+
"subtitle": "",
|
|
72
|
+
# The grain on the faceplate and the header strip: "matte", "brushed"
|
|
73
|
+
# or None for a flat colour (cheapest on a slow board).
|
|
74
|
+
"face_finish": "matte",
|
|
75
|
+
"header_finish": "brushed",
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
SILVER = dict(BLACK)
|
|
79
|
+
SILVER.update(
|
|
80
|
+
{
|
|
81
|
+
"name": "silver",
|
|
82
|
+
# Bead-blasted silver aluminium with black legends, the same black
|
|
83
|
+
# caps, and a black display window.
|
|
84
|
+
"face": 0xC7C9CC,
|
|
85
|
+
"face_bottom": 0xA9ACB0,
|
|
86
|
+
"header": 0x2A2B2E,
|
|
87
|
+
"header_bottom": 0x18191B,
|
|
88
|
+
"bevel_light": 0xE6E8EA,
|
|
89
|
+
"bevel_dark": 0x6E7176,
|
|
90
|
+
"legend": 0x1E1F22,
|
|
91
|
+
"legend_dim": 0x6A6D72,
|
|
92
|
+
"legend_lit": 0xD0200C,
|
|
93
|
+
"rule": 0x8C8F94,
|
|
94
|
+
"brand": 0xE4E6EA,
|
|
95
|
+
"pad": 0x3A3B3F,
|
|
96
|
+
"pad_bottom": 0x2A2B2E,
|
|
97
|
+
"pad_edge": 0x5A5C60,
|
|
98
|
+
"pad_tint": 0x4A2E28,
|
|
99
|
+
"led_off": 0x4A1510,
|
|
100
|
+
"led_rim": 0x2A2B2E,
|
|
101
|
+
"shadow": 0x2E3034,
|
|
102
|
+
"screw": 0x9EA1A6,
|
|
103
|
+
"screw_light": 0xEDEEF0,
|
|
104
|
+
"screw_slot": 0x3A3C40,
|
|
105
|
+
"face_finish": "brushed",
|
|
106
|
+
}
|
|
107
|
+
)
|
|
108
|
+
|
|
109
|
+
THEMES = {"black": BLACK, "silver": SILVER}
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
def resolve(theme):
|
|
113
|
+
"""A complete theme from a name, a dict, or None (``black``)."""
|
|
114
|
+
if theme is None:
|
|
115
|
+
return BLACK
|
|
116
|
+
if isinstance(theme, str):
|
|
117
|
+
return THEMES[theme]
|
|
118
|
+
merged = dict(BLACK)
|
|
119
|
+
merged.update(theme)
|
|
120
|
+
return merged
|
controlkit/theme.pyi
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# SPDX-FileCopyrightText: 2026 Brad Barnett
|
|
2
|
+
#
|
|
3
|
+
# SPDX-License-Identifier: MIT
|
|
4
|
+
"""The panel's finishes: every colour it draws, in one table per theme."""
|
|
5
|
+
from collections.abc import Mapping
|
|
6
|
+
from typing import TypeAlias
|
|
7
|
+
|
|
8
|
+
_Theme: TypeAlias = Mapping[str, int | str | None]
|
|
9
|
+
|
|
10
|
+
BLACK: dict[str, int | str | None]
|
|
11
|
+
SILVER: dict[str, int | str | None]
|
|
12
|
+
THEMES: dict[str, dict[str, int | str | None]]
|
|
13
|
+
|
|
14
|
+
def resolve(theme: str | Mapping[str, int | str | None] | None) -> Mapping[str, int | str | None]:
|
|
15
|
+
"""A complete theme from a name, a dict, or None (`black`)."""
|