Skip to content

Commit 7635c52

Browse files
Improve HowTo app
1 parent a13af57 commit 7635c52

4 files changed

Lines changed: 63 additions & 12 deletions

File tree

internal_filesystem/builtin/apps/com.micropythonos.howto/assets/howto.py

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,39 @@ class HowTo(Activity):
1111
def onCreate(self):
1212
screen = lv.obj()
1313
screen.set_flex_flow(lv.FLEX_FLOW.COLUMN)
14+
'''
15+
welcome_label = lv.label(screen)
16+
welcome_label.set_width(lv.pct(100))
17+
welcome_label.set_text("Welcome!")
18+
welcome_label.set_style_text_font(lv.font_montserrat_34, lv.PART.MAIN)
19+
welcome_label.set_style_margin_bottom(2, lv.PART.MAIN)
20+
'''
21+
preamble = "How to Navigate"
22+
title_label = lv.label(screen)
23+
title_label.set_width(lv.pct(100))
24+
title_label.set_text(preamble)
25+
title_label.set_style_text_font(lv.font_montserrat_24, lv.PART.MAIN)
1426
label = lv.label(screen)
1527
label.set_width(lv.pct(100))
16-
touchhelp = "swipe from the left edge to go back and from the top edge to open the menu."
17-
label.set_text(f'''
18-
Welcome!
28+
label.set_style_text_font(lv.font_montserrat_14, lv.PART.MAIN)
29+
buttonhelp = '''As you don't have a touch screen, you need to use the buttons to navigate:
30+
31+
- 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.
1932
20-
This app will explain how to move around in MicroPythonOS.
33+
- If you have 3 buttons, then one is PREVIOUS, one is ENTER and one is NEXT. To go back, press PREVIOUS and NEXT together.
2134
22-
If you're on a touch screen, {touchhelp}
23-
24-
If you've got 3 buttons, one is PREVIOUS, one is ENTER and one is NEXT. To go back, press PREVIOUS and NEXT together.
25-
26-
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.
27-
''')
35+
- 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.
36+
'''
37+
touchhelp = "Swipe from the left edge to go back and from the top edge to open the menu."
38+
from mpos import InputManager
39+
if InputManager.has_pointer():
40+
label.set_text(f'''
41+
{touchhelp}
42+
''')
43+
else:
44+
label.set_text(f'''
45+
{buttonhelp}
46+
''')
2847
label.set_long_mode(lv.label.LONG_MODE.WRAP)
2948

3049
self.dontshow_checkbox = lv.checkbox(screen)

internal_filesystem/lib/mpos/board/lilygo_t_watch_s3_plus.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
i2c_bus = i2c.I2C.Bus(host=0, sda=39, scl=40, freq=400000, use_locks=False)
4848
touch_dev = i2c.I2C.Device(bus=i2c_bus, dev_id=ft6x36.I2C_ADDR, reg_bits=ft6x36.BITS)
4949
import pointer_framework
50-
indev=ft6x36.FT6x36(touch_dev, startup_rotation=pointer_framework.lv.DISPLAY_ROTATION._180)
50+
indev = ft6x36.FT6x36(touch_dev, startup_rotation=pointer_framework.lv.DISPLAY_ROTATION._180)
51+
from mpos import InputManager
52+
InputManager.register_indev(indev)
5153

5254
mpos.ui.main_display.set_rotation(lv.DISPLAY_ROTATION._180)
5355

internal_filesystem/lib/mpos/board/linux.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,10 @@
5050
# display.set_dpi(65) # doesn't seem to change the default 130...
5151
mpos.ui.main_display.init()
5252
# main_display.set_dpi(65) # doesn't seem to change the default 130...
53-
5453
import sdl_pointer
5554
mouse = sdl_pointer.SDLPointer()
55+
InputManager.register_indev(mouse)
56+
5657

5758
def catch_escape_key(indev, indev_data):
5859
global sdlkeyboard

internal_filesystem/lib/mpos/ui/input_manager.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,35 @@ def has_indev_type(cls, indev_type):
6565
return True
6666
return False
6767

68+
@classmethod
69+
def has_pointer(cls):
70+
"""Check if any registered input device is a pointer/touch device."""
71+
import lvgl as lv
72+
if cls.has_indev_type(lv.INDEV_TYPE.POINTER):
73+
return True
74+
get_next = getattr(lv, "indev_get_next", None)
75+
if get_next:
76+
indev = get_next(None)
77+
while indev:
78+
try:
79+
if indev.get_type() == lv.INDEV_TYPE.POINTER:
80+
return True
81+
except Exception:
82+
pass
83+
indev = get_next(indev)
84+
get_active = getattr(lv, "indev_active", None) or getattr(lv, "indev_get_act", None)
85+
if get_active:
86+
try:
87+
indev = get_active()
88+
except Exception:
89+
indev = None
90+
if indev:
91+
try:
92+
return indev.get_type() == lv.INDEV_TYPE.POINTER
93+
except Exception:
94+
return False
95+
return False
96+
6897
@classmethod
6998
def pointer_xy(cls):
7099
"""Get current pointer/touch coordinates."""

0 commit comments

Comments
 (0)