GHIElectronics.Endpoint.UI 0.5.3__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.
|
@@ -0,0 +1,1014 @@
|
|
|
1
|
+
"""GHIElectronics.Endpoint.UI — widgets on top of the embedded LVGL in
|
|
2
|
+
libendpoint. API mirrors the .NET package character-for-character
|
|
3
|
+
(PascalCase properties and methods).
|
|
4
|
+
|
|
5
|
+
Usage::
|
|
6
|
+
|
|
7
|
+
from GHIElectronics.Endpoint.Devices.Display import DisplayController
|
|
8
|
+
from GHIElectronics.Endpoint.UI import UI, Screen, Button
|
|
9
|
+
|
|
10
|
+
display = DisplayController.GetDefault()
|
|
11
|
+
display.Enable()
|
|
12
|
+
UI.Initialize()
|
|
13
|
+
|
|
14
|
+
screen = Screen()
|
|
15
|
+
button = Button(screen)
|
|
16
|
+
button.Text = "Click me"
|
|
17
|
+
button.Clicked += lambda: print("clicked")
|
|
18
|
+
screen.Load()
|
|
19
|
+
UI.Run()
|
|
20
|
+
"""
|
|
21
|
+
|
|
22
|
+
import ctypes
|
|
23
|
+
|
|
24
|
+
from GHIElectronics.Endpoint.Core._native import native, UiEventCallback, CustomFlushCallback
|
|
25
|
+
from GHIElectronics.Endpoint.Core._errors import ArgumentException, NotSupportedException
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
# ------------------------------------------------------------------
|
|
29
|
+
# Event helper
|
|
30
|
+
# ------------------------------------------------------------------
|
|
31
|
+
|
|
32
|
+
class _Event:
|
|
33
|
+
"""Mimics the .NET += / -= event idiom. Internal; use via Widget events."""
|
|
34
|
+
|
|
35
|
+
def __init__(self):
|
|
36
|
+
self._handlers = []
|
|
37
|
+
|
|
38
|
+
def __iadd__(self, handler):
|
|
39
|
+
self._handlers.append(handler)
|
|
40
|
+
return self
|
|
41
|
+
|
|
42
|
+
def __isub__(self, handler):
|
|
43
|
+
if handler in self._handlers:
|
|
44
|
+
self._handlers.remove(handler)
|
|
45
|
+
return self
|
|
46
|
+
|
|
47
|
+
def _fire(self):
|
|
48
|
+
for h in self._handlers:
|
|
49
|
+
try:
|
|
50
|
+
h()
|
|
51
|
+
except Exception:
|
|
52
|
+
# A C callback must not propagate Python exceptions back into
|
|
53
|
+
# native code (would unwind through LVGL). Swallow.
|
|
54
|
+
pass
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
# ------------------------------------------------------------------
|
|
58
|
+
# UI subsystem lifecycle
|
|
59
|
+
# ------------------------------------------------------------------
|
|
60
|
+
|
|
61
|
+
class UI:
|
|
62
|
+
"""UI subsystem lifecycle. Call Initialize() once after the display is
|
|
63
|
+
enabled; call Run() to drive the event loop; Stop() to exit.
|
|
64
|
+
|
|
65
|
+
Initialize() has two forms:
|
|
66
|
+
- ``UI.Initialize()`` binds LVGL to the on-board parallel-RGB framebuffer
|
|
67
|
+
(/dev/fb0). Call after DisplayController.Enable().
|
|
68
|
+
- ``UI.Initialize(width, height, pixel_format, flush)`` binds LVGL to a
|
|
69
|
+
custom display of any transport. LVGL renders each frame into an
|
|
70
|
+
internal buffer and calls ``flush(pixels_bytes)``; the callback pushes
|
|
71
|
+
them to the destination (SPI/I2C/UART/HDMI/file/network).
|
|
72
|
+
"""
|
|
73
|
+
|
|
74
|
+
# Pinned at module scope so ctypes doesn't collect them while the native
|
|
75
|
+
# display driver still holds pointers. One slot, one custom display.
|
|
76
|
+
_custom_flush = None
|
|
77
|
+
_custom_trampoline = None
|
|
78
|
+
|
|
79
|
+
@staticmethod
|
|
80
|
+
def Initialize(*args):
|
|
81
|
+
if len(args) == 0:
|
|
82
|
+
native.ui_initialize()
|
|
83
|
+
return
|
|
84
|
+
if len(args) != 4:
|
|
85
|
+
raise ArgumentException(
|
|
86
|
+
"UI.Initialize takes 0 or 4 arguments (width, height, pixel_format, flush).")
|
|
87
|
+
width, height, pixel_format, flush = args
|
|
88
|
+
if flush is None:
|
|
89
|
+
raise ArgumentException("flush must not be None")
|
|
90
|
+
|
|
91
|
+
def trampoline(_context, pixels_ptr, byte_count):
|
|
92
|
+
try:
|
|
93
|
+
managed = bytes(ctypes.string_at(pixels_ptr, byte_count))
|
|
94
|
+
flush(managed)
|
|
95
|
+
except Exception:
|
|
96
|
+
# A C callback must not propagate Python exceptions back into
|
|
97
|
+
# native code (would unwind through LVGL). Swallow.
|
|
98
|
+
pass
|
|
99
|
+
|
|
100
|
+
UI._custom_flush = flush
|
|
101
|
+
UI._custom_trampoline = CustomFlushCallback(trampoline)
|
|
102
|
+
native.ui_initialize_custom(int(width), int(height), int(pixel_format),
|
|
103
|
+
UI._custom_trampoline, None)
|
|
104
|
+
|
|
105
|
+
@staticmethod
|
|
106
|
+
def Run():
|
|
107
|
+
native.ui_run()
|
|
108
|
+
|
|
109
|
+
@staticmethod
|
|
110
|
+
def Stop():
|
|
111
|
+
native.ui_stop()
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
class TouchBridge:
|
|
115
|
+
"""Touch input bridge. Call Attach() once after UI.Initialize(), then
|
|
116
|
+
call Feed(x, y, pressed) from your touch chip's event handler. LVGL will
|
|
117
|
+
dispatch Clicked / ValueChanged accordingly on its event loop."""
|
|
118
|
+
|
|
119
|
+
@staticmethod
|
|
120
|
+
def Attach():
|
|
121
|
+
native.ui_touch_attach()
|
|
122
|
+
|
|
123
|
+
@staticmethod
|
|
124
|
+
def Feed(x, y, pressed):
|
|
125
|
+
native.ui_touch_feed(x, y, 1 if pressed else 0)
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
class UiTimer:
|
|
129
|
+
"""Thread-safe periodic callback that runs on the UI thread. The callable
|
|
130
|
+
fires inside UI.Run()'s LVGL pump every period_ms milliseconds, so widget
|
|
131
|
+
updates in it are safe (LVGL itself is single-threaded). Dispose() /
|
|
132
|
+
__del__ cancels the timer. Create / set_period / Dispose are safe from any
|
|
133
|
+
thread; the body runs on the UI thread.
|
|
134
|
+
|
|
135
|
+
Example::
|
|
136
|
+
|
|
137
|
+
def tick():
|
|
138
|
+
gauge.Value = int(1650 + 1450 * math.sin(phase))
|
|
139
|
+
timer = UiTimer(100, tick)
|
|
140
|
+
"""
|
|
141
|
+
|
|
142
|
+
def __init__(self, period_ms, callback):
|
|
143
|
+
if callback is None:
|
|
144
|
+
raise ValueError("callback is required")
|
|
145
|
+
self._callback = callback
|
|
146
|
+
# Keep a reference to the trampoline so ctypes doesn't collect it while
|
|
147
|
+
# the native timer still holds a pointer to it.
|
|
148
|
+
self._trampoline = UiEventCallback(lambda _ctx: self._fire())
|
|
149
|
+
handle = native.out_handle()
|
|
150
|
+
native.ui_timer_create(int(period_ms), self._trampoline, None, native.ref(handle))
|
|
151
|
+
self._handle = handle.value
|
|
152
|
+
|
|
153
|
+
def _fire(self):
|
|
154
|
+
try:
|
|
155
|
+
self._callback()
|
|
156
|
+
except Exception:
|
|
157
|
+
# A C callback must not propagate Python exceptions back into
|
|
158
|
+
# native code (would unwind through LVGL). Swallow.
|
|
159
|
+
pass
|
|
160
|
+
|
|
161
|
+
def SetPeriod(self, period_ms):
|
|
162
|
+
if self._handle:
|
|
163
|
+
native.ui_timer_set_period(self._handle, int(period_ms))
|
|
164
|
+
|
|
165
|
+
def Dispose(self):
|
|
166
|
+
if self._handle:
|
|
167
|
+
native.ui_timer_delete(self._handle)
|
|
168
|
+
self._handle = None
|
|
169
|
+
|
|
170
|
+
def __del__(self):
|
|
171
|
+
try: self.Dispose()
|
|
172
|
+
except Exception: pass
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
# ------------------------------------------------------------------
|
|
176
|
+
# Widget font (LVGL lv_tiny_ttf)
|
|
177
|
+
# ------------------------------------------------------------------
|
|
178
|
+
|
|
179
|
+
class Font:
|
|
180
|
+
"""A TrueType / OpenType font for widget text (Button caption, Label text,
|
|
181
|
+
Chart axis labels, ...). Rasterized on demand by LVGL's lv_tiny_ttf; the
|
|
182
|
+
same Font can be assigned to any number of widgets. Separate from
|
|
183
|
+
GHIElectronics.Endpoint.Drawing.Font (which is stb_truetype for
|
|
184
|
+
off-screen Canvas drawing)."""
|
|
185
|
+
|
|
186
|
+
def __init__(self, handle):
|
|
187
|
+
self._native = handle
|
|
188
|
+
|
|
189
|
+
@staticmethod
|
|
190
|
+
def Load(ttf_bytes, size_px):
|
|
191
|
+
"""Load a TTF / OTF font at the given pixel height. Bytes are copied
|
|
192
|
+
into native storage, so the caller's buffer can be released as soon
|
|
193
|
+
as this returns."""
|
|
194
|
+
if ttf_bytes is None:
|
|
195
|
+
raise ArgumentException("ttf_bytes must not be None")
|
|
196
|
+
if len(ttf_bytes) == 0:
|
|
197
|
+
raise ArgumentException("Font bytes are empty.")
|
|
198
|
+
if size_px <= 0:
|
|
199
|
+
raise ArgumentException("size_px must be positive.")
|
|
200
|
+
|
|
201
|
+
data = bytes(ttf_bytes)
|
|
202
|
+
src = (ctypes.c_uint8 * len(data)).from_buffer_copy(data)
|
|
203
|
+
out_handle = native.out_handle()
|
|
204
|
+
native.ui_font_load_ttf(src, len(data), int(size_px), native.ref(out_handle))
|
|
205
|
+
return Font(out_handle.value)
|
|
206
|
+
|
|
207
|
+
def Dispose(self):
|
|
208
|
+
"""Release the native font. Do NOT dispose while any widget still
|
|
209
|
+
uses it - call after UI.Stop() returns, or let the process exit."""
|
|
210
|
+
if self._native is not None:
|
|
211
|
+
native.ui_font_free(self._native)
|
|
212
|
+
self._native = None
|
|
213
|
+
|
|
214
|
+
def __del__(self):
|
|
215
|
+
try: self.Dispose()
|
|
216
|
+
except Exception: pass
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
# ------------------------------------------------------------------
|
|
220
|
+
# Base + widgets
|
|
221
|
+
# ------------------------------------------------------------------
|
|
222
|
+
|
|
223
|
+
class Widget:
|
|
224
|
+
"""Base class for every widget. Holds the native handle and shared
|
|
225
|
+
geometry/visibility."""
|
|
226
|
+
|
|
227
|
+
def __init__(self, native_handle):
|
|
228
|
+
self._native = native_handle
|
|
229
|
+
# ctypes keeps weak references to CFUNCTYPE instances by default; we
|
|
230
|
+
# pin event trampolines here so GC doesn't collect them mid-use.
|
|
231
|
+
self._event_trampolines = []
|
|
232
|
+
|
|
233
|
+
@property
|
|
234
|
+
def X(self):
|
|
235
|
+
x, y = native.out_int(), native.out_int()
|
|
236
|
+
native.ui_widget_get_pos(self._native, native.ref(x), native.ref(y))
|
|
237
|
+
return x.value
|
|
238
|
+
|
|
239
|
+
@X.setter
|
|
240
|
+
def X(self, value):
|
|
241
|
+
# Single-axis set: LVGL's getters return 0 until first layout pass,
|
|
242
|
+
# so read-then-write-both would zero out the untouched axis.
|
|
243
|
+
native.ui_widget_set_x(self._native, value)
|
|
244
|
+
|
|
245
|
+
@property
|
|
246
|
+
def Y(self):
|
|
247
|
+
x, y = native.out_int(), native.out_int()
|
|
248
|
+
native.ui_widget_get_pos(self._native, native.ref(x), native.ref(y))
|
|
249
|
+
return y.value
|
|
250
|
+
|
|
251
|
+
@Y.setter
|
|
252
|
+
def Y(self, value):
|
|
253
|
+
native.ui_widget_set_y(self._native, value)
|
|
254
|
+
|
|
255
|
+
@property
|
|
256
|
+
def Width(self):
|
|
257
|
+
w, h = native.out_int(), native.out_int()
|
|
258
|
+
native.ui_widget_get_size(self._native, native.ref(w), native.ref(h))
|
|
259
|
+
return w.value
|
|
260
|
+
|
|
261
|
+
@Width.setter
|
|
262
|
+
def Width(self, value):
|
|
263
|
+
native.ui_widget_set_width(self._native, value)
|
|
264
|
+
|
|
265
|
+
@property
|
|
266
|
+
def Height(self):
|
|
267
|
+
w, h = native.out_int(), native.out_int()
|
|
268
|
+
native.ui_widget_get_size(self._native, native.ref(w), native.ref(h))
|
|
269
|
+
return h.value
|
|
270
|
+
|
|
271
|
+
@Height.setter
|
|
272
|
+
def Height(self, value):
|
|
273
|
+
native.ui_widget_set_height(self._native, value)
|
|
274
|
+
|
|
275
|
+
@property
|
|
276
|
+
def Visible(self):
|
|
277
|
+
v = native.out_int()
|
|
278
|
+
native.ui_widget_get_visible(self._native, native.ref(v))
|
|
279
|
+
return v.value != 0
|
|
280
|
+
|
|
281
|
+
@Visible.setter
|
|
282
|
+
def Visible(self, value):
|
|
283
|
+
native.ui_widget_set_visible(self._native, 1 if value else 0)
|
|
284
|
+
|
|
285
|
+
@property
|
|
286
|
+
def BackgroundColor(self):
|
|
287
|
+
raise AttributeError("BackgroundColor is write-only")
|
|
288
|
+
|
|
289
|
+
@BackgroundColor.setter
|
|
290
|
+
def BackgroundColor(self, rgb):
|
|
291
|
+
"""Solid background color (0x00RRGGBB)."""
|
|
292
|
+
native.ui_widget_set_bg_color(self._native, int(rgb))
|
|
293
|
+
|
|
294
|
+
def SetBackgroundGradient(self, rgb_start, rgb_end, direction=0):
|
|
295
|
+
"""Linear gradient background. direction: 0 = vertical (top->bottom), 1 = horizontal (left->right)."""
|
|
296
|
+
native.ui_widget_set_bg_gradient(self._native, int(rgb_start), int(rgb_end), int(direction))
|
|
297
|
+
|
|
298
|
+
def SetMargin(self, left, top, right, bottom):
|
|
299
|
+
"""WPF-style per-widget Margin. Works in any parent."""
|
|
300
|
+
native.ui_widget_set_margin(self._native, int(left), int(top), int(right), int(bottom))
|
|
301
|
+
|
|
302
|
+
def SetBackgroundImage(self, source, width=None, height=None):
|
|
303
|
+
"""Background image for the widget. Rendered at native size (no tile,
|
|
304
|
+
no scale). Two forms, mirroring the .NET overloads:
|
|
305
|
+
|
|
306
|
+
- ``SetBackgroundImage(rgb565_bytes, width, height)`` — raw RGB565
|
|
307
|
+
pixel bytes (little-endian).
|
|
308
|
+
- ``SetBackgroundImage(image)`` — a decoded ``Drawing.Image`` (JPG /
|
|
309
|
+
PNG / BMP / ...). The image's RGB888 pixels are converted to
|
|
310
|
+
RGB565 and copied into native storage.
|
|
311
|
+
"""
|
|
312
|
+
# Deferred import: Drawing module imports native too; keep the
|
|
313
|
+
# top-of-module import list short and avoid a circular hazard.
|
|
314
|
+
from GHIElectronics.Endpoint.Drawing import Image as _DrawingImage
|
|
315
|
+
from GHIElectronics.Endpoint.Drawing import PixelFormat as _DrawingPixelFormat
|
|
316
|
+
|
|
317
|
+
if isinstance(source, _DrawingImage):
|
|
318
|
+
if source.PixelFormat != _DrawingPixelFormat.Rgb888:
|
|
319
|
+
raise NotSupportedException(
|
|
320
|
+
f"SetBackgroundImage(Image): source format {source.PixelFormat} "
|
|
321
|
+
"not yet supported (Rgb888 only).")
|
|
322
|
+
w, h = source.Width, source.Height
|
|
323
|
+
src = source._pixels
|
|
324
|
+
rgb565 = bytearray(w * h * 2)
|
|
325
|
+
j = 0
|
|
326
|
+
for i in range(0, len(src), 3):
|
|
327
|
+
r, g, b = src[i], src[i + 1], src[i + 2]
|
|
328
|
+
px = ((r & 0xF8) << 8) | ((g & 0xFC) << 3) | (b >> 3)
|
|
329
|
+
rgb565[j] = px & 0xFF
|
|
330
|
+
rgb565[j + 1] = (px >> 8) & 0xFF
|
|
331
|
+
j += 2
|
|
332
|
+
self._set_bg_image_bytes(rgb565, w, h)
|
|
333
|
+
return
|
|
334
|
+
|
|
335
|
+
# Raw-bytes form.
|
|
336
|
+
if width is None or height is None:
|
|
337
|
+
raise ArgumentException("width and height are required when passing raw pixel bytes")
|
|
338
|
+
self._set_bg_image_bytes(source, int(width), int(height))
|
|
339
|
+
|
|
340
|
+
def _set_bg_image_bytes(self, rgb565_bytes, width, height):
|
|
341
|
+
self._bg_pixels = bytes(rgb565_bytes) # kept alive on the widget
|
|
342
|
+
buf = (ctypes.c_ubyte * len(self._bg_pixels)).from_buffer_copy(self._bg_pixels)
|
|
343
|
+
self._bg_pixels_buf = buf
|
|
344
|
+
native.ui_widget_set_bg_image(self._native, buf, len(self._bg_pixels), width, height)
|
|
345
|
+
|
|
346
|
+
@property
|
|
347
|
+
def Font(self):
|
|
348
|
+
raise AttributeError("Font is write-only")
|
|
349
|
+
|
|
350
|
+
@Font.setter
|
|
351
|
+
def Font(self, value):
|
|
352
|
+
"""Custom font for any text this widget renders (Button caption,
|
|
353
|
+
Label text, Chart axis labels, ...). Load once via Font.Load; the
|
|
354
|
+
same Font can be assigned to any number of widgets. Pass None to
|
|
355
|
+
clear."""
|
|
356
|
+
native.ui_widget_set_font(self._native, value._native if value is not None else None)
|
|
357
|
+
|
|
358
|
+
def Dispose(self):
|
|
359
|
+
if self._native:
|
|
360
|
+
native.ui_widget_destroy(self._native)
|
|
361
|
+
self._native = None
|
|
362
|
+
self._event_trampolines.clear()
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
class Screen(Widget):
|
|
366
|
+
"""A top-level container with no parent. Call Load() to make it active."""
|
|
367
|
+
|
|
368
|
+
def __init__(self):
|
|
369
|
+
h = native.out_handle()
|
|
370
|
+
native.ui_screen_create(native.ref(h))
|
|
371
|
+
super().__init__(h.value)
|
|
372
|
+
|
|
373
|
+
def Load(self):
|
|
374
|
+
native.ui_screen_load(self._native)
|
|
375
|
+
|
|
376
|
+
@staticmethod
|
|
377
|
+
def Active():
|
|
378
|
+
h = native.out_handle()
|
|
379
|
+
native.ui_screen_active(native.ref(h))
|
|
380
|
+
s = Screen.__new__(Screen)
|
|
381
|
+
Widget.__init__(s, h.value)
|
|
382
|
+
return s
|
|
383
|
+
|
|
384
|
+
|
|
385
|
+
class Container(Widget):
|
|
386
|
+
def __init__(self, parent):
|
|
387
|
+
h = native.out_handle()
|
|
388
|
+
native.ui_container_create(parent._native, native.ref(h))
|
|
389
|
+
super().__init__(h.value)
|
|
390
|
+
|
|
391
|
+
|
|
392
|
+
class Orientation:
|
|
393
|
+
"""StackPanel orientation (mirrors the .NET enum of the same name)."""
|
|
394
|
+
Vertical = 0
|
|
395
|
+
Horizontal = 1
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
class StackPanel(Widget):
|
|
399
|
+
"""WPF-style StackPanel: stacks children vertically (default) or
|
|
400
|
+
horizontally via LVGL flex. Spacing is the inter-child gap; each
|
|
401
|
+
child's SetMargin stacks on top of that."""
|
|
402
|
+
def __init__(self, parent):
|
|
403
|
+
h = native.out_handle()
|
|
404
|
+
native.ui_stackpanel_create(parent._native, native.ref(h))
|
|
405
|
+
super().__init__(h.value)
|
|
406
|
+
|
|
407
|
+
@property
|
|
408
|
+
def Orientation(self): raise AttributeError("Orientation is write-only")
|
|
409
|
+
@Orientation.setter
|
|
410
|
+
def Orientation(self, v): native.ui_stackpanel_set_orientation(self._native, int(v))
|
|
411
|
+
|
|
412
|
+
@property
|
|
413
|
+
def Spacing(self): raise AttributeError("Spacing is write-only")
|
|
414
|
+
@Spacing.setter
|
|
415
|
+
def Spacing(self, px): native.ui_stackpanel_set_spacing(self._native, int(px))
|
|
416
|
+
|
|
417
|
+
|
|
418
|
+
class Grid(Widget):
|
|
419
|
+
"""WPF-style Grid with ColumnDefinitions + RowDefinitions. Sizes:
|
|
420
|
+
positive = fixed px, 0 or negative = star (-1 = '*', -2 = '2*', ...)."""
|
|
421
|
+
def __init__(self, parent):
|
|
422
|
+
h = native.out_handle()
|
|
423
|
+
native.ui_grid_create(parent._native, native.ref(h))
|
|
424
|
+
super().__init__(h.value)
|
|
425
|
+
self._cols_buf = None # keep arrays alive while LVGL points into them
|
|
426
|
+
self._rows_buf = None
|
|
427
|
+
|
|
428
|
+
def SetDefinitions(self, columns, rows):
|
|
429
|
+
c_arr = (ctypes.c_int * len(columns))(*[int(v) for v in columns])
|
|
430
|
+
r_arr = (ctypes.c_int * len(rows))(*[int(v) for v in rows])
|
|
431
|
+
self._cols_buf = c_arr; self._rows_buf = r_arr
|
|
432
|
+
native.ui_grid_set_definitions(self._native, c_arr, len(columns), r_arr, len(rows))
|
|
433
|
+
|
|
434
|
+
@staticmethod
|
|
435
|
+
def SetCell(child, column, row, column_span=1, row_span=1):
|
|
436
|
+
native.ui_grid_set_cell(child._native, int(column), int(column_span), int(row), int(row_span))
|
|
437
|
+
|
|
438
|
+
|
|
439
|
+
class DockPanel(Widget):
|
|
440
|
+
"""WPF-style DockPanel. LVGL has no dock layout; the caller positions
|
|
441
|
+
children using their x/y/width/height after reading their `dock` side."""
|
|
442
|
+
def __init__(self, parent):
|
|
443
|
+
h = native.out_handle()
|
|
444
|
+
native.ui_dockpanel_create(parent._native, native.ref(h))
|
|
445
|
+
super().__init__(h.value)
|
|
446
|
+
self.LastChildFill = True
|
|
447
|
+
|
|
448
|
+
|
|
449
|
+
class Menu(Widget):
|
|
450
|
+
"""Horizontal menu bar."""
|
|
451
|
+
def __init__(self, parent):
|
|
452
|
+
h = native.out_handle()
|
|
453
|
+
native.ui_menu_create(parent._native, native.ref(h))
|
|
454
|
+
super().__init__(h.value)
|
|
455
|
+
|
|
456
|
+
@property
|
|
457
|
+
def Background(self): raise AttributeError("Background is write-only")
|
|
458
|
+
@Background.setter
|
|
459
|
+
def Background(self, rgb): native.ui_menu_set_background(self._native, int(rgb))
|
|
460
|
+
|
|
461
|
+
def AddItem(self, header, item_width=0):
|
|
462
|
+
out = native.out_handle()
|
|
463
|
+
native.ui_menuitem_create(self._native, header.encode("utf-8"), int(item_width), native.ref(out))
|
|
464
|
+
return MenuItem(out.value)
|
|
465
|
+
|
|
466
|
+
def AddDropdown(self, header, sub_items, item_width=0):
|
|
467
|
+
joined = "\n".join(sub_items or [])
|
|
468
|
+
out = native.out_handle()
|
|
469
|
+
native.ui_menuitem_create_dropdown(
|
|
470
|
+
self._native, header.encode("utf-8"), joined.encode("utf-8"), int(item_width), native.ref(out))
|
|
471
|
+
return MenuItem(out.value)
|
|
472
|
+
|
|
473
|
+
|
|
474
|
+
class MenuItem:
|
|
475
|
+
"""Handle to a menu item. Subscribe to Clicked / ValueChanged."""
|
|
476
|
+
def __init__(self, native_handle):
|
|
477
|
+
self._native = native_handle
|
|
478
|
+
# _subscribe appends to this list to keep CFUNCTYPE trampolines pinned
|
|
479
|
+
# (ctypes holds weak refs by default). MenuItem isn't a Widget subclass
|
|
480
|
+
# so we have to set it up ourselves.
|
|
481
|
+
self._event_trampolines = []
|
|
482
|
+
self.Clicked = _Event()
|
|
483
|
+
self.ValueChanged = _Event()
|
|
484
|
+
_subscribe(self, native.ui_subscribe_clicked, self.Clicked)
|
|
485
|
+
_subscribe(self, native.ui_subscribe_value_changed, self.ValueChanged)
|
|
486
|
+
|
|
487
|
+
@property
|
|
488
|
+
def Selected(self):
|
|
489
|
+
out = native.out_int()
|
|
490
|
+
native.ui_dropdown_get_selected(self._native, native.ref(out))
|
|
491
|
+
return out.value
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
class Calendar(Widget):
|
|
495
|
+
def __init__(self, parent):
|
|
496
|
+
h = native.out_handle()
|
|
497
|
+
native.ui_calendar_create(parent._native, native.ref(h))
|
|
498
|
+
super().__init__(h.value)
|
|
499
|
+
|
|
500
|
+
def SetShowedDate(self, year, month):
|
|
501
|
+
native.ui_calendar_set_showed_date(self._native, int(year), int(month))
|
|
502
|
+
|
|
503
|
+
def SetToday(self, year, month, day):
|
|
504
|
+
native.ui_calendar_set_today(self._native, int(year), int(month), int(day))
|
|
505
|
+
|
|
506
|
+
|
|
507
|
+
class DataGrid(Widget):
|
|
508
|
+
"""Simple grid of text cells (TinyCLR-style simple API)."""
|
|
509
|
+
def __init__(self, parent):
|
|
510
|
+
h = native.out_handle()
|
|
511
|
+
native.ui_datagrid_create(parent._native, native.ref(h))
|
|
512
|
+
super().__init__(h.value)
|
|
513
|
+
|
|
514
|
+
def SetSize(self, columns, rows):
|
|
515
|
+
native.ui_datagrid_set_size(self._native, int(columns), int(rows))
|
|
516
|
+
|
|
517
|
+
def SetCell(self, row, column, text):
|
|
518
|
+
native.ui_datagrid_set_cell(self._native, int(row), int(column), (text or "").encode("utf-8"))
|
|
519
|
+
|
|
520
|
+
def SetColumnWidth(self, column, px):
|
|
521
|
+
native.ui_datagrid_set_column_width(self._native, int(column), int(px))
|
|
522
|
+
|
|
523
|
+
|
|
524
|
+
class TreeView(Widget):
|
|
525
|
+
"""Hierarchical list of indented nodes."""
|
|
526
|
+
def __init__(self, parent):
|
|
527
|
+
h = native.out_handle()
|
|
528
|
+
native.ui_treeview_create(parent._native, native.ref(h))
|
|
529
|
+
super().__init__(h.value)
|
|
530
|
+
|
|
531
|
+
def AddNode(self, depth, is_expanded, has_children, header):
|
|
532
|
+
out = native.out_handle()
|
|
533
|
+
native.ui_treeview_add_node(
|
|
534
|
+
self._native, int(depth), 1 if is_expanded else 0, 1 if has_children else 0,
|
|
535
|
+
(header or "").encode("utf-8"), native.ref(out))
|
|
536
|
+
|
|
537
|
+
def Clear(self):
|
|
538
|
+
native.ui_treeview_clear(self._native)
|
|
539
|
+
|
|
540
|
+
|
|
541
|
+
class ChartMode:
|
|
542
|
+
Line = 0
|
|
543
|
+
Rectangle = 1
|
|
544
|
+
Area = 2
|
|
545
|
+
|
|
546
|
+
|
|
547
|
+
class Chart(Widget):
|
|
548
|
+
"""TinyCLR-style simple chart (not standard .NET)."""
|
|
549
|
+
def __init__(self, parent):
|
|
550
|
+
h = native.out_handle()
|
|
551
|
+
native.ui_chart_create(parent._native, native.ref(h))
|
|
552
|
+
super().__init__(h.value)
|
|
553
|
+
|
|
554
|
+
@property
|
|
555
|
+
def Mode(self): raise AttributeError("Mode is write-only")
|
|
556
|
+
@Mode.setter
|
|
557
|
+
def Mode(self, m): native.ui_chart_set_mode(self._native, int(m))
|
|
558
|
+
|
|
559
|
+
def SetColors(self, point_color, area_color, label_color):
|
|
560
|
+
native.ui_chart_set_colors(self._native, int(point_color), int(area_color), int(label_color))
|
|
561
|
+
|
|
562
|
+
@property
|
|
563
|
+
def DivisionAxisY(self): raise AttributeError("DivisionAxisY is write-only")
|
|
564
|
+
@DivisionAxisY.setter
|
|
565
|
+
def DivisionAxisY(self, d): native.ui_chart_set_division(self._native, int(d))
|
|
566
|
+
|
|
567
|
+
def SetPoints(self, values):
|
|
568
|
+
buf = (ctypes.c_int * len(values))(*[int(v) for v in values])
|
|
569
|
+
self._points_buf = buf
|
|
570
|
+
native.ui_chart_set_points(self._native, buf, len(values))
|
|
571
|
+
|
|
572
|
+
|
|
573
|
+
class Gauge(Widget):
|
|
574
|
+
"""Radial gauge (TinyCLR-style)."""
|
|
575
|
+
def __init__(self, parent, width, height):
|
|
576
|
+
h = native.out_handle()
|
|
577
|
+
native.ui_gauge_create(parent._native, int(width), int(height), native.ref(h))
|
|
578
|
+
super().__init__(h.value)
|
|
579
|
+
|
|
580
|
+
def SetRange(self, min_value, max_value):
|
|
581
|
+
native.ui_gauge_set_range(self._native, int(min_value), int(max_value))
|
|
582
|
+
|
|
583
|
+
@property
|
|
584
|
+
def Value(self): raise AttributeError("Value is write-only")
|
|
585
|
+
@Value.setter
|
|
586
|
+
def Value(self, v): native.ui_gauge_set_value(self._native, int(v))
|
|
587
|
+
|
|
588
|
+
@property
|
|
589
|
+
def SweepAngle(self): raise AttributeError("SweepAngle is write-only")
|
|
590
|
+
@SweepAngle.setter
|
|
591
|
+
def SweepAngle(self, deg): native.ui_gauge_set_sweep(self._native, int(deg))
|
|
592
|
+
|
|
593
|
+
def SetNeedleShape(self, center_y, length):
|
|
594
|
+
native.ui_gauge_set_needle_shape(self._native, int(center_y * 1000), int(length * 1000))
|
|
595
|
+
|
|
596
|
+
@property
|
|
597
|
+
def EnableScale(self): raise AttributeError("EnableScale is write-only")
|
|
598
|
+
@EnableScale.setter
|
|
599
|
+
def EnableScale(self, v): native.ui_gauge_show_scale(self._native, 1 if v else 0)
|
|
600
|
+
|
|
601
|
+
|
|
602
|
+
class Border(Widget):
|
|
603
|
+
"""Container with WPF-style Thickness / BorderBrush / CornerRadius /
|
|
604
|
+
Padding. Set Background via the inherited BackgroundColor."""
|
|
605
|
+
def __init__(self, parent):
|
|
606
|
+
h = native.out_handle()
|
|
607
|
+
native.ui_border_create(parent._native, native.ref(h))
|
|
608
|
+
super().__init__(h.value)
|
|
609
|
+
|
|
610
|
+
@property
|
|
611
|
+
def Thickness(self): raise AttributeError("Thickness is write-only")
|
|
612
|
+
@Thickness.setter
|
|
613
|
+
def Thickness(self, px): native.ui_border_set_thickness(self._native, int(px))
|
|
614
|
+
|
|
615
|
+
@property
|
|
616
|
+
def BorderBrush(self): raise AttributeError("BorderBrush is write-only")
|
|
617
|
+
@BorderBrush.setter
|
|
618
|
+
def BorderBrush(self, rgb): native.ui_border_set_brush(self._native, int(rgb))
|
|
619
|
+
|
|
620
|
+
@property
|
|
621
|
+
def CornerRadius(self): raise AttributeError("CornerRadius is write-only")
|
|
622
|
+
@CornerRadius.setter
|
|
623
|
+
def CornerRadius(self, px): native.ui_border_set_corner_radius(self._native, int(px))
|
|
624
|
+
|
|
625
|
+
@property
|
|
626
|
+
def Padding(self): raise AttributeError("Padding is write-only")
|
|
627
|
+
@Padding.setter
|
|
628
|
+
def Padding(self, px): native.ui_border_set_padding(self._native, int(px))
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
def _subscribe(widget, native_subscribe, event):
|
|
632
|
+
"""Register one trampoline for `event`, bind it to the given native
|
|
633
|
+
endpoint_ui_subscribe_* function."""
|
|
634
|
+
def trampoline(_context):
|
|
635
|
+
event._fire()
|
|
636
|
+
cb = UiEventCallback(trampoline)
|
|
637
|
+
widget._event_trampolines.append(cb)
|
|
638
|
+
native_subscribe(widget._native, cb, None)
|
|
639
|
+
|
|
640
|
+
|
|
641
|
+
class Button(Widget):
|
|
642
|
+
def __init__(self, parent):
|
|
643
|
+
h = native.out_handle()
|
|
644
|
+
native.ui_button_create(parent._native, native.ref(h))
|
|
645
|
+
super().__init__(h.value)
|
|
646
|
+
self.Clicked = _Event()
|
|
647
|
+
_subscribe(self, native.ui_subscribe_clicked, self.Clicked)
|
|
648
|
+
|
|
649
|
+
@property
|
|
650
|
+
def Text(self): raise AttributeError("Text is write-only")
|
|
651
|
+
@Text.setter
|
|
652
|
+
def Text(self, value):
|
|
653
|
+
native.ui_button_set_text(self._native, value.encode("utf-8"))
|
|
654
|
+
|
|
655
|
+
@property
|
|
656
|
+
def BackgroundColor(self): raise AttributeError("BackgroundColor is write-only")
|
|
657
|
+
@BackgroundColor.setter
|
|
658
|
+
def BackgroundColor(self, value):
|
|
659
|
+
native.ui_button_set_bg_color(self._native, value)
|
|
660
|
+
|
|
661
|
+
@property
|
|
662
|
+
def TextColor(self): raise AttributeError("TextColor is write-only")
|
|
663
|
+
@TextColor.setter
|
|
664
|
+
def TextColor(self, value):
|
|
665
|
+
native.ui_button_set_text_color(self._native, value)
|
|
666
|
+
|
|
667
|
+
@property
|
|
668
|
+
def FontSize(self): raise AttributeError("FontSize is write-only")
|
|
669
|
+
@FontSize.setter
|
|
670
|
+
def FontSize(self, value):
|
|
671
|
+
native.ui_button_set_font_size(self._native, value)
|
|
672
|
+
|
|
673
|
+
|
|
674
|
+
class TextAlignment:
|
|
675
|
+
"""Horizontal alignment for Label.Text. Matches .NET's
|
|
676
|
+
GHIElectronics.Endpoint.UI.TextAlignment enum."""
|
|
677
|
+
Left = 0
|
|
678
|
+
Center = 1
|
|
679
|
+
Right = 2
|
|
680
|
+
|
|
681
|
+
|
|
682
|
+
class Label(Widget):
|
|
683
|
+
def __init__(self, parent):
|
|
684
|
+
h = native.out_handle()
|
|
685
|
+
native.ui_label_create(parent._native, native.ref(h))
|
|
686
|
+
super().__init__(h.value)
|
|
687
|
+
|
|
688
|
+
@property
|
|
689
|
+
def Text(self): raise AttributeError("Text is write-only")
|
|
690
|
+
@Text.setter
|
|
691
|
+
def Text(self, value):
|
|
692
|
+
native.ui_label_set_text(self._native, value.encode("utf-8"))
|
|
693
|
+
|
|
694
|
+
@property
|
|
695
|
+
def Color(self): raise AttributeError("Color is write-only")
|
|
696
|
+
@Color.setter
|
|
697
|
+
def Color(self, value):
|
|
698
|
+
native.ui_label_set_color(self._native, value)
|
|
699
|
+
|
|
700
|
+
@property
|
|
701
|
+
def FontSize(self): raise AttributeError("FontSize is write-only")
|
|
702
|
+
@FontSize.setter
|
|
703
|
+
def FontSize(self, value):
|
|
704
|
+
native.ui_label_set_font_size(self._native, value)
|
|
705
|
+
|
|
706
|
+
@property
|
|
707
|
+
def TextAlignment(self): raise AttributeError("TextAlignment is write-only")
|
|
708
|
+
@TextAlignment.setter
|
|
709
|
+
def TextAlignment(self, value):
|
|
710
|
+
native.ui_label_set_text_align(self._native, int(value))
|
|
711
|
+
|
|
712
|
+
|
|
713
|
+
class Image(Widget):
|
|
714
|
+
def __init__(self, parent):
|
|
715
|
+
h = native.out_handle()
|
|
716
|
+
native.ui_image_create(parent._native, native.ref(h))
|
|
717
|
+
super().__init__(h.value)
|
|
718
|
+
self._pixels = None # keep user bytes alive while LVGL points into them
|
|
719
|
+
|
|
720
|
+
def SetSource(self, rgb565_pixels, width, height):
|
|
721
|
+
# Hold a reference so GC doesn't free the buffer underneath LVGL.
|
|
722
|
+
self._pixels = bytes(rgb565_pixels)
|
|
723
|
+
ptr = (ctypes.c_uint8 * len(self._pixels)).from_buffer_copy(self._pixels)
|
|
724
|
+
self._pixels_ptr = ptr # also hold the ctypes array
|
|
725
|
+
native.ui_image_set_source(self._native, ptr, len(self._pixels), width, height)
|
|
726
|
+
|
|
727
|
+
|
|
728
|
+
class TextBox(Widget):
|
|
729
|
+
def __init__(self, parent):
|
|
730
|
+
h = native.out_handle()
|
|
731
|
+
native.ui_textbox_create(parent._native, native.ref(h))
|
|
732
|
+
super().__init__(h.value)
|
|
733
|
+
self.ValueChanged = _Event()
|
|
734
|
+
_subscribe(self, native.ui_subscribe_value_changed, self.ValueChanged)
|
|
735
|
+
|
|
736
|
+
@property
|
|
737
|
+
def Text(self):
|
|
738
|
+
buf = ctypes.create_string_buffer(256)
|
|
739
|
+
native.ui_textbox_get_text(self._native, buf, 256)
|
|
740
|
+
return buf.value.decode("utf-8", errors="replace")
|
|
741
|
+
|
|
742
|
+
@Text.setter
|
|
743
|
+
def Text(self, value):
|
|
744
|
+
native.ui_textbox_set_text(self._native, value.encode("utf-8"))
|
|
745
|
+
|
|
746
|
+
@property
|
|
747
|
+
def Placeholder(self): raise AttributeError("Placeholder is write-only")
|
|
748
|
+
@Placeholder.setter
|
|
749
|
+
def Placeholder(self, value):
|
|
750
|
+
native.ui_textbox_set_placeholder(self._native, value.encode("utf-8"))
|
|
751
|
+
|
|
752
|
+
|
|
753
|
+
class Slider(Widget):
|
|
754
|
+
def __init__(self, parent):
|
|
755
|
+
h = native.out_handle()
|
|
756
|
+
native.ui_slider_create(parent._native, native.ref(h))
|
|
757
|
+
super().__init__(h.value)
|
|
758
|
+
self._min = 0
|
|
759
|
+
self._max = 100
|
|
760
|
+
self.ValueChanged = _Event()
|
|
761
|
+
_subscribe(self, native.ui_subscribe_value_changed, self.ValueChanged)
|
|
762
|
+
|
|
763
|
+
# LVGL stores min and max as a pair, so we track them on the Python side
|
|
764
|
+
# and push both whenever either changes.
|
|
765
|
+
@property
|
|
766
|
+
def Minimum(self):
|
|
767
|
+
return self._min
|
|
768
|
+
|
|
769
|
+
@Minimum.setter
|
|
770
|
+
def Minimum(self, value):
|
|
771
|
+
self._min = value
|
|
772
|
+
native.ui_slider_set_range(self._native, self._min, self._max)
|
|
773
|
+
|
|
774
|
+
@property
|
|
775
|
+
def Maximum(self):
|
|
776
|
+
return self._max
|
|
777
|
+
|
|
778
|
+
@Maximum.setter
|
|
779
|
+
def Maximum(self, value):
|
|
780
|
+
self._max = value
|
|
781
|
+
native.ui_slider_set_range(self._native, self._min, self._max)
|
|
782
|
+
|
|
783
|
+
@property
|
|
784
|
+
def Value(self):
|
|
785
|
+
v = native.out_int()
|
|
786
|
+
native.ui_slider_get_value(self._native, native.ref(v))
|
|
787
|
+
return v.value
|
|
788
|
+
|
|
789
|
+
@Value.setter
|
|
790
|
+
def Value(self, value):
|
|
791
|
+
native.ui_slider_set_value(self._native, value)
|
|
792
|
+
|
|
793
|
+
|
|
794
|
+
class CheckBox(Widget):
|
|
795
|
+
def __init__(self, parent):
|
|
796
|
+
h = native.out_handle()
|
|
797
|
+
native.ui_checkbox_create(parent._native, native.ref(h))
|
|
798
|
+
super().__init__(h.value)
|
|
799
|
+
self.ValueChanged = _Event()
|
|
800
|
+
_subscribe(self, native.ui_subscribe_value_changed, self.ValueChanged)
|
|
801
|
+
|
|
802
|
+
@property
|
|
803
|
+
def Text(self): raise AttributeError("Text is write-only")
|
|
804
|
+
@Text.setter
|
|
805
|
+
def Text(self, value):
|
|
806
|
+
native.ui_checkbox_set_text(self._native, value.encode("utf-8"))
|
|
807
|
+
|
|
808
|
+
@property
|
|
809
|
+
def IsChecked(self):
|
|
810
|
+
v = native.out_int()
|
|
811
|
+
native.ui_checkbox_get_checked(self._native, native.ref(v))
|
|
812
|
+
return v.value != 0
|
|
813
|
+
|
|
814
|
+
@IsChecked.setter
|
|
815
|
+
def IsChecked(self, value):
|
|
816
|
+
native.ui_checkbox_set_checked(self._native, 1 if value else 0)
|
|
817
|
+
|
|
818
|
+
|
|
819
|
+
class MessageBoxButton:
|
|
820
|
+
"""A button inside a MessageBox. Subscribe to Clicked (an _Event)."""
|
|
821
|
+
|
|
822
|
+
def __init__(self, native_handle):
|
|
823
|
+
self._native = native_handle
|
|
824
|
+
self.Clicked = _Event()
|
|
825
|
+
cb = UiEventCallback(lambda _ctx: self.Clicked._fire())
|
|
826
|
+
self._cb = cb # keep alive
|
|
827
|
+
native.ui_subscribe_clicked(self._native, cb, None)
|
|
828
|
+
|
|
829
|
+
|
|
830
|
+
class MessageBox(Widget):
|
|
831
|
+
"""Modal dialog with title, body, and footer buttons. AddButton returns
|
|
832
|
+
a handle whose Clicked event you subscribe to. Hide dismisses."""
|
|
833
|
+
|
|
834
|
+
def __init__(self, parent):
|
|
835
|
+
h = native.out_handle()
|
|
836
|
+
native.ui_messagebox_create(parent._native, native.ref(h))
|
|
837
|
+
super().__init__(h.value)
|
|
838
|
+
self._buttons = [] # keep MessageBoxButton refs alive
|
|
839
|
+
|
|
840
|
+
def SetTitle(self, title):
|
|
841
|
+
native.ui_messagebox_set_title(self._native, title.encode("utf-8"))
|
|
842
|
+
|
|
843
|
+
def SetBody(self, body):
|
|
844
|
+
native.ui_messagebox_set_body(self._native, body.encode("utf-8"))
|
|
845
|
+
|
|
846
|
+
def AddButton(self, text):
|
|
847
|
+
out = native.out_handle()
|
|
848
|
+
native.ui_messagebox_add_button(self._native, text.encode("utf-8"), native.ref(out))
|
|
849
|
+
btn = MessageBoxButton(out.value)
|
|
850
|
+
self._buttons.append(btn)
|
|
851
|
+
return btn
|
|
852
|
+
|
|
853
|
+
def Hide(self):
|
|
854
|
+
native.ui_messagebox_hide(self._native)
|
|
855
|
+
|
|
856
|
+
|
|
857
|
+
class ListBoxItem:
|
|
858
|
+
"""An item inside a ListBox. Subscribe to Clicked (an _Event)."""
|
|
859
|
+
|
|
860
|
+
def __init__(self, native_handle):
|
|
861
|
+
self._native = native_handle
|
|
862
|
+
self.Clicked = _Event()
|
|
863
|
+
cb = UiEventCallback(lambda _ctx: self.Clicked._fire())
|
|
864
|
+
self._cb = cb
|
|
865
|
+
native.ui_subscribe_clicked(self._native, cb, None)
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
class ListBox(Widget):
|
|
869
|
+
"""Vertical scrollable list. AddItem returns a handle whose Clicked
|
|
870
|
+
event you subscribe to. Clear drops all items."""
|
|
871
|
+
|
|
872
|
+
def __init__(self, parent):
|
|
873
|
+
h = native.out_handle()
|
|
874
|
+
native.ui_listbox_create(parent._native, native.ref(h))
|
|
875
|
+
super().__init__(h.value)
|
|
876
|
+
self._items = []
|
|
877
|
+
|
|
878
|
+
def AddItem(self, text):
|
|
879
|
+
out = native.out_handle()
|
|
880
|
+
native.ui_listbox_add_item(self._native, text.encode("utf-8"), native.ref(out))
|
|
881
|
+
item = ListBoxItem(out.value)
|
|
882
|
+
self._items.append(item)
|
|
883
|
+
return item
|
|
884
|
+
|
|
885
|
+
def Clear(self):
|
|
886
|
+
native.ui_listbox_clear(self._native)
|
|
887
|
+
self._items.clear()
|
|
888
|
+
|
|
889
|
+
|
|
890
|
+
class RadioButton(Widget):
|
|
891
|
+
"""Circular-indicator CheckBox. Grouping (mutual exclusion) is up to the
|
|
892
|
+
caller — subscribe to ValueChanged on each and clear the others on select."""
|
|
893
|
+
|
|
894
|
+
def __init__(self, parent):
|
|
895
|
+
h = native.out_handle()
|
|
896
|
+
native.ui_radiobutton_create(parent._native, native.ref(h))
|
|
897
|
+
super().__init__(h.value)
|
|
898
|
+
self.ValueChanged = _Event()
|
|
899
|
+
_subscribe(self, native.ui_subscribe_value_changed, self.ValueChanged)
|
|
900
|
+
|
|
901
|
+
@property
|
|
902
|
+
def Text(self): raise AttributeError("Text is write-only")
|
|
903
|
+
@Text.setter
|
|
904
|
+
def Text(self, value):
|
|
905
|
+
native.ui_radiobutton_set_text(self._native, value.encode("utf-8"))
|
|
906
|
+
|
|
907
|
+
@property
|
|
908
|
+
def IsChecked(self):
|
|
909
|
+
v = native.out_int()
|
|
910
|
+
native.ui_radiobutton_get_checked(self._native, native.ref(v))
|
|
911
|
+
return v.value != 0
|
|
912
|
+
|
|
913
|
+
@IsChecked.setter
|
|
914
|
+
def IsChecked(self, value):
|
|
915
|
+
native.ui_radiobutton_set_checked(self._native, 1 if value else 0)
|
|
916
|
+
|
|
917
|
+
|
|
918
|
+
class Dropdown(Widget):
|
|
919
|
+
"""Select one item from a list. ValueChanged fires on selection change."""
|
|
920
|
+
|
|
921
|
+
def __init__(self, parent):
|
|
922
|
+
h = native.out_handle()
|
|
923
|
+
native.ui_dropdown_create(parent._native, native.ref(h))
|
|
924
|
+
super().__init__(h.value)
|
|
925
|
+
self.ValueChanged = _Event()
|
|
926
|
+
_subscribe(self, native.ui_subscribe_value_changed, self.ValueChanged)
|
|
927
|
+
|
|
928
|
+
def SetOptions(self, options):
|
|
929
|
+
"""Set items; iterable of strings, joined with newline internally."""
|
|
930
|
+
joined = "\n".join(options)
|
|
931
|
+
native.ui_dropdown_set_options(self._native, joined.encode("utf-8"))
|
|
932
|
+
|
|
933
|
+
@property
|
|
934
|
+
def Selected(self):
|
|
935
|
+
v = native.out_int()
|
|
936
|
+
native.ui_dropdown_get_selected(self._native, native.ref(v))
|
|
937
|
+
return v.value
|
|
938
|
+
|
|
939
|
+
@Selected.setter
|
|
940
|
+
def Selected(self, value):
|
|
941
|
+
native.ui_dropdown_set_selected(self._native, value)
|
|
942
|
+
|
|
943
|
+
|
|
944
|
+
class ProgressBar(Widget):
|
|
945
|
+
"""Horizontal progress bar. No events; owner drives it via Value."""
|
|
946
|
+
|
|
947
|
+
def __init__(self, parent):
|
|
948
|
+
h = native.out_handle()
|
|
949
|
+
native.ui_progressbar_create(parent._native, native.ref(h))
|
|
950
|
+
super().__init__(h.value)
|
|
951
|
+
self._min = 0
|
|
952
|
+
self._max = 100
|
|
953
|
+
|
|
954
|
+
@property
|
|
955
|
+
def Minimum(self): return self._min
|
|
956
|
+
@Minimum.setter
|
|
957
|
+
def Minimum(self, value):
|
|
958
|
+
self._min = value
|
|
959
|
+
native.ui_progressbar_set_range(self._native, self._min, self._max)
|
|
960
|
+
|
|
961
|
+
@property
|
|
962
|
+
def Maximum(self): return self._max
|
|
963
|
+
@Maximum.setter
|
|
964
|
+
def Maximum(self, value):
|
|
965
|
+
self._max = value
|
|
966
|
+
native.ui_progressbar_set_range(self._native, self._min, self._max)
|
|
967
|
+
|
|
968
|
+
@property
|
|
969
|
+
def Value(self):
|
|
970
|
+
v = native.out_int()
|
|
971
|
+
native.ui_progressbar_get_value(self._native, native.ref(v))
|
|
972
|
+
return v.value
|
|
973
|
+
|
|
974
|
+
@Value.setter
|
|
975
|
+
def Value(self, value):
|
|
976
|
+
native.ui_progressbar_set_value(self._native, value)
|
|
977
|
+
|
|
978
|
+
|
|
979
|
+
class Switch(Widget):
|
|
980
|
+
"""Binary on/off toggle. ValueChanged fires on each flip."""
|
|
981
|
+
|
|
982
|
+
def __init__(self, parent):
|
|
983
|
+
h = native.out_handle()
|
|
984
|
+
native.ui_switch_create(parent._native, native.ref(h))
|
|
985
|
+
super().__init__(h.value)
|
|
986
|
+
self.ValueChanged = _Event()
|
|
987
|
+
_subscribe(self, native.ui_subscribe_value_changed, self.ValueChanged)
|
|
988
|
+
|
|
989
|
+
@property
|
|
990
|
+
def IsChecked(self):
|
|
991
|
+
v = native.out_int()
|
|
992
|
+
native.ui_switch_get_checked(self._native, native.ref(v))
|
|
993
|
+
return v.value != 0
|
|
994
|
+
|
|
995
|
+
@IsChecked.setter
|
|
996
|
+
def IsChecked(self, value):
|
|
997
|
+
native.ui_switch_set_checked(self._native, 1 if value else 0)
|
|
998
|
+
|
|
999
|
+
|
|
1000
|
+
class Keyboard(Widget):
|
|
1001
|
+
"""Virtual on-screen keyboard. Attach to a TextBox via SetTarget so taps
|
|
1002
|
+
on keys type into it. Positions itself at the bottom half of the display
|
|
1003
|
+
by default; override via inherited X / Y / Width / Height."""
|
|
1004
|
+
|
|
1005
|
+
def __init__(self, parent):
|
|
1006
|
+
h = native.out_handle()
|
|
1007
|
+
native.ui_keyboard_create(parent._native, native.ref(h))
|
|
1008
|
+
super().__init__(h.value)
|
|
1009
|
+
|
|
1010
|
+
def SetTarget(self, textbox):
|
|
1011
|
+
native.ui_keyboard_set_textbox(self._native, textbox._native)
|
|
1012
|
+
|
|
1013
|
+
def ClearTarget(self):
|
|
1014
|
+
native.ui_keyboard_set_textbox(self._native, None)
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: GHIElectronics.Endpoint.UI
|
|
3
|
+
Version: 0.5.3
|
|
4
|
+
Summary: UI widgets for Endpoint: Button, Label, Container, Image, TextBox, Slider, CheckBox on top of the embedded LVGL in libendpoint. Pair with the GHI Electronics UI designer.
|
|
5
|
+
Author-email: "GHI Electronics, LLC" <support@ghielectronics.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://www.ghielectronics.com/
|
|
8
|
+
Project-URL: Repository, https://github.com/ghi-electronics/Endpoint-Libraries
|
|
9
|
+
Project-URL: Issues, https://github.com/ghi-electronics/Endpoint-Libraries/issues
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
12
|
+
Requires-Python: >=3.9
|
|
13
|
+
Description-Content-Type: text/markdown
|
|
14
|
+
Requires-Dist: GHIElectronics.Endpoint.Core<0.6,>=0.5.3
|
|
15
|
+
Requires-Dist: GHIElectronics.Endpoint.Devices.Display<0.6,>=0.5.3
|
|
16
|
+
Requires-Dist: GHIElectronics.Endpoint.Drawing<0.6,>=0.5.3
|
|
17
|
+
|
|
18
|
+
# GHIElectronics.Endpoint.UI
|
|
19
|
+
|
|
20
|
+
UI widgets for Endpoint: Button, Label, Container, Image, TextBox, Slider, CheckBox on top of the embedded LVGL in libendpoint. Pair with the GHI Electronics UI designer.
|
|
21
|
+
|
|
22
|
+
Part of the [GHI Electronics Endpoint](https://github.com/ghi-electronics/Endpoint-Libraries) libraries. See the repository README for the full package list and getting-started guide.
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
GHIElectronics/Endpoint/UI/__init__.py,sha256=ViA5le0JwJ_Fb6id04qei0-oom8e_47tk5w3Uatk3oE,35336
|
|
2
|
+
ghielectronics_endpoint_ui-0.5.3.dist-info/METADATA,sha256=59XGlPtn5qAYMmr0foUf5nZYOkC9QWICYVbMJUxPYtE,1305
|
|
3
|
+
ghielectronics_endpoint_ui-0.5.3.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
4
|
+
ghielectronics_endpoint_ui-0.5.3.dist-info/top_level.txt,sha256=NpOZNgd0iquwrRPrTOhUDxc2V9TtNFLv5Z_Dx3YZtIU,15
|
|
5
|
+
ghielectronics_endpoint_ui-0.5.3.dist-info/RECORD,,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
GHIElectronics
|