Improve HowTo app

This commit is contained in:
Thomas Farstrike
2026-03-18 13:33:07 +01:00
parent a13af57273
commit 7635c52baa
4 changed files with 63 additions and 12 deletions
@@ -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)
@@ -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)
+2 -1
View File
@@ -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
@@ -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."""