|
| 1 | +# SPDX-FileCopyrightText: 2025 M5Stack Technology CO LTD |
| 2 | +# |
| 3 | +# SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +from m5ui.base import M5Base |
| 6 | +import lvgl as lv |
| 7 | + |
| 8 | + |
| 9 | +class M5Spinner(lv.spinner): |
| 10 | + """Create a spinner object. |
| 11 | +
|
| 12 | + :param int x: The x position of the spinner. |
| 13 | + :param int y: The y position of the spinner. |
| 14 | + :param int w: The width of the spinner. |
| 15 | + :param int h: The height of the spinner. |
| 16 | + :param int anim_t: The animation time in milliseconds. |
| 17 | + :param int angle: The angle of the spinner in degrees. |
| 18 | + :param lv.obj parent: The parent object to attach the spinner to. If not specified, the spinner will be attached to the default screen. |
| 19 | +
|
| 20 | + UiFlow2 Code Block: |
| 21 | +
|
| 22 | + None |
| 23 | +
|
| 24 | + MicroPython Code Block: |
| 25 | +
|
| 26 | + .. code-block:: python |
| 27 | +
|
| 28 | + from m5ui import M5Spinner |
| 29 | + import lvgl as lv |
| 30 | +
|
| 31 | + m5ui.init() |
| 32 | + spinner_0 = M5Spinner(x=120, y=80, w=60, h=30, anim_t=1000, angle=180, parent=page0) |
| 33 | + """ |
| 34 | + |
| 35 | + def __init__( |
| 36 | + self, |
| 37 | + x=0, |
| 38 | + y=0, |
| 39 | + w=0, |
| 40 | + h=0, |
| 41 | + anim_t=10000, |
| 42 | + angle=180, |
| 43 | + parent=None, |
| 44 | + ): |
| 45 | + if parent is None: |
| 46 | + parent = lv.screen_active() |
| 47 | + super().__init__(parent) |
| 48 | + self.set_pos(x, y) |
| 49 | + self.set_size(w, h) |
| 50 | + self.set_anim_params(anim_t, angle) |
| 51 | + |
| 52 | + def set_spinner_color(self, color, opa: int, part: int): |
| 53 | + """Set the color of the spinner. |
| 54 | +
|
| 55 | + :param int color: The color of the spinner in hexadecimal format. |
| 56 | +
|
| 57 | + UiFlow2 Code Block: |
| 58 | +
|
| 59 | + |set_spinner_color.png| |
| 60 | +
|
| 61 | + MicroPython Code Block: |
| 62 | +
|
| 63 | + .. code-block:: python |
| 64 | +
|
| 65 | + label_0.set_spinner_color(0x2196F3, lv.PART.MAIN | lv.STATE.DEFAULT) |
| 66 | + """ |
| 67 | + if isinstance(color, int): |
| 68 | + color = lv.color_hex(color) |
| 69 | + if part == lv.PART.KNOB | lv.STATE.DEFAULT: |
| 70 | + self.set_bg_color(color, opa, lv.PART.KNOB | lv.STATE.DEFAULT) |
| 71 | + else: |
| 72 | + self.set_style_arc_color(color, part) |
| 73 | + self.set_style_arc_opa(opa, part) |
| 74 | + |
| 75 | + def __getattr__(self, name): |
| 76 | + if hasattr(M5Base, name): |
| 77 | + method = getattr(M5Base, name) |
| 78 | + bound_method = lambda *args, **kwargs: method(self, *args, **kwargs) |
| 79 | + setattr(self, name, bound_method) |
| 80 | + return bound_method |
| 81 | + raise AttributeError(f"'{self.__class__.__name__}' object has no attribute '{name}'") |
0 commit comments