From 7635c52baacf5d6b706a6401bb9443a0650ed47c Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Wed, 18 Mar 2026 13:33:07 +0100 Subject: [PATCH] Improve HowTo app --- .../com.micropythonos.howto/assets/howto.py | 39 ++++++++++++++----- .../lib/mpos/board/lilygo_t_watch_s3_plus.py | 4 +- internal_filesystem/lib/mpos/board/linux.py | 3 +- .../lib/mpos/ui/input_manager.py | 29 ++++++++++++++ 4 files changed, 63 insertions(+), 12 deletions(-) diff --git a/internal_filesystem/builtin/apps/com.micropythonos.howto/assets/howto.py b/internal_filesystem/builtin/apps/com.micropythonos.howto/assets/howto.py index 276844b0..a656478d 100644 --- a/internal_filesystem/builtin/apps/com.micropythonos.howto/assets/howto.py +++ b/internal_filesystem/builtin/apps/com.micropythonos.howto/assets/howto.py @@ -11,20 +11,39 @@ class HowTo(Activity): def onCreate(self): screen = lv.obj() screen.set_flex_flow(lv.FLEX_FLOW.COLUMN) + ''' + welcome_label = lv.label(screen) + welcome_label.set_width(lv.pct(100)) + welcome_label.set_text("Welcome!") + welcome_label.set_style_text_font(lv.font_montserrat_34, lv.PART.MAIN) + welcome_label.set_style_margin_bottom(2, lv.PART.MAIN) + ''' + preamble = "How to Navigate" + title_label = lv.label(screen) + title_label.set_width(lv.pct(100)) + title_label.set_text(preamble) + title_label.set_style_text_font(lv.font_montserrat_24, lv.PART.MAIN) label = lv.label(screen) label.set_width(lv.pct(100)) - touchhelp = "swipe from the left edge to go back and from the top edge to open the menu." - label.set_text(f''' -Welcome! + label.set_style_text_font(lv.font_montserrat_14, lv.PART.MAIN) + buttonhelp = '''As you don't have a touch screen, you need to use the buttons to navigate: + +- If you have a joystick and at least 2 buttons, then use the joystick to move around. Use one of the buttons to ENTER and another to go BACK. -This app will explain how to move around in MicroPythonOS. +- If you have 3 buttons, then one is PREVIOUS, one is ENTER and one is NEXT. To go back, press PREVIOUS and NEXT together. -If you're on a touch screen, {touchhelp} - -If you've got 3 buttons, one is PREVIOUS, one is ENTER and one is NEXT. To go back, press PREVIOUS and NEXT together. - -If you've got 2 buttons, one is PREVIOUS, the other is NEXT. To ENTER, press both at the same time. To go back, long-press PREVIOUS. - ''') +- If you have just 2 buttons, then one is PREVIOUS, the other is NEXT. To ENTER, press both at the same time. To go back, long-press the PREVIOUS button. + ''' + touchhelp = "Swipe from the left edge to go back and from the top edge to open the menu." + from mpos import InputManager + if InputManager.has_pointer(): + label.set_text(f''' +{touchhelp} + ''') + else: + label.set_text(f''' +{buttonhelp} + ''') label.set_long_mode(lv.label.LONG_MODE.WRAP) self.dontshow_checkbox = lv.checkbox(screen) diff --git a/internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py b/internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py index 1b7092fd..a9f6cfc0 100644 --- a/internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py +++ b/internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py @@ -47,7 +47,9 @@ import drivers.indev.ft6x36 as ft6x36 i2c_bus = i2c.I2C.Bus(host=0, sda=39, scl=40, freq=400000, use_locks=False) touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=ft6x36.I2C_ADDR, reg_bits=ft6x36.BITS) import pointer_framework -indev=ft6x36.FT6x36(touch_dev, startup_rotation=pointer_framework.lv.DISPLAY_ROTATION._180) +indev = ft6x36.FT6x36(touch_dev, startup_rotation=pointer_framework.lv.DISPLAY_ROTATION._180) +from mpos import InputManager +InputManager.register_indev(indev) mpos.ui.main_display.set_rotation(lv.DISPLAY_ROTATION._180) diff --git a/internal_filesystem/lib/mpos/board/linux.py b/internal_filesystem/lib/mpos/board/linux.py index f6725998..7cc72bb8 100644 --- a/internal_filesystem/lib/mpos/board/linux.py +++ b/internal_filesystem/lib/mpos/board/linux.py @@ -50,9 +50,10 @@ mpos.ui.main_display = sdl_display.SDLDisplay(data_bus=bus,display_width=TFT_HOR # display.set_dpi(65) # doesn't seem to change the default 130... mpos.ui.main_display.init() # main_display.set_dpi(65) # doesn't seem to change the default 130... - import sdl_pointer mouse = sdl_pointer.SDLPointer() +InputManager.register_indev(mouse) + def catch_escape_key(indev, indev_data): global sdlkeyboard diff --git a/internal_filesystem/lib/mpos/ui/input_manager.py b/internal_filesystem/lib/mpos/ui/input_manager.py index 00e1b372..95e6358f 100644 --- a/internal_filesystem/lib/mpos/ui/input_manager.py +++ b/internal_filesystem/lib/mpos/ui/input_manager.py @@ -65,6 +65,35 @@ class InputManager: return True return False + @classmethod + def has_pointer(cls): + """Check if any registered input device is a pointer/touch device.""" + import lvgl as lv + if cls.has_indev_type(lv.INDEV_TYPE.POINTER): + return True + get_next = getattr(lv, "indev_get_next", None) + if get_next: + indev = get_next(None) + while indev: + try: + if indev.get_type() == lv.INDEV_TYPE.POINTER: + return True + except Exception: + pass + indev = get_next(indev) + get_active = getattr(lv, "indev_active", None) or getattr(lv, "indev_get_act", None) + if get_active: + try: + indev = get_active() + except Exception: + indev = None + if indev: + try: + return indev.get_type() == lv.INDEV_TYPE.POINTER + except Exception: + return False + return False + @classmethod def pointer_xy(cls): """Get current pointer/touch coordinates."""