From f8fac8a32fd84711b538793c2e15516151557531 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Mon, 12 May 2025 00:05:56 +0200 Subject: [PATCH] Explicitly use mpos. prefix + don't hide notification bar in launcher --- internal_filesystem/boot_unix.py | 10 +++++----- internal_filesystem/lib/mpos/apps.py | 18 +++++++++--------- internal_filesystem/lib/mpos/ui.py | 5 +++-- internal_filesystem/main.py | 8 ++++---- 4 files changed, 21 insertions(+), 20 deletions(-) diff --git a/internal_filesystem/boot_unix.py b/internal_filesystem/boot_unix.py index 12a10c69..344991a9 100644 --- a/internal_filesystem/boot_unix.py +++ b/internal_filesystem/boot_unix.py @@ -2,7 +2,7 @@ import lcd_bus import lvgl as lv import sdl_display import sdl_pointer -from mpos import ui +import mpos.ui TFT_HOR_RES=320 TFT_VER_RES=240 @@ -31,7 +31,7 @@ def swipe_read_cb(indev_drv, data): if pressed and start_y is None: start_y = y # Mouse button pressed (start of potential swipe) - if y <= ui.NOTIFICATION_BAR_HEIGHT: + if y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: # Store starting Y if press is in the notification bar area print(f"Mouse press at Y={start_y}") elif pressed and start_y is not None: @@ -39,15 +39,15 @@ def swipe_read_cb(indev_drv, data): # Check for downward swipe (y increased significantly) if y > start_y + 50: # Threshold for swipe detection (adjust as needed) print("long swipe down") - if start_y <= ui.NOTIFICATION_BAR_HEIGHT: + if start_y <= mpos.ui.NOTIFICATION_BAR_HEIGHT: print("Swipe Down Detected from Notification Bar") - ui.open_drawer() + mpos.ui.open_drawer() start_y = None # Reset after swipe else: # Mouse button released if start_y is not None and y < start_y - 50: # Threshold for swipe-up print("Swipe Up Detected") - ui.close_drawer() + mpos.ui.close_drawer() start_y = None # Reset on release # Register the custom read callback with the input device diff --git a/internal_filesystem/lib/mpos/apps.py b/internal_filesystem/lib/mpos/apps.py index 3f1fe44d..b2cf3de9 100644 --- a/internal_filesystem/lib/mpos/apps.py +++ b/internal_filesystem/lib/mpos/apps.py @@ -7,8 +7,8 @@ import uos import _thread import traceback -from mpos import ui import mpos.info +import mpos.ui # Run the script in the current thread: def execute_script(script_source, is_file, is_launcher, is_graphical): @@ -26,7 +26,7 @@ def execute_script(script_source, is_file, is_launcher, is_graphical): else: # is_graphical if is_launcher: prevscreen = None - newscreen = ui.rootscreen + newscreen = mpos.ui.rootscreen else: prevscreen = lv.screen_active() newscreen=lv.obj() @@ -34,12 +34,12 @@ def execute_script(script_source, is_file, is_launcher, is_graphical): lv.screen_load(newscreen) script_globals = { 'lv': lv, - 'NOTIFICATION_BAR_HEIGHT': ui.NOTIFICATION_BAR_HEIGHT, # for apps that want to leave space for notification bar + 'NOTIFICATION_BAR_HEIGHT': mpos.ui.NOTIFICATION_BAR_HEIGHT, # for apps that want to leave space for notification bar 'appscreen': newscreen, 'start_app': start_app, # for launcher apps 'parse_manifest': parse_manifest, # for launcher apps 'restart_launcher': restart_launcher, # for appstore apps - 'show_launcher': ui.show_launcher, # for apps that want to show the launcher + 'show_launcher': mpos.ui.show_launcher, # for apps that want to show the launcher 'CURRENT_OS_VERSION': mpos.info.CURRENT_OS_VERSION, # for osupdate '__name__': "__main__" } @@ -54,7 +54,7 @@ def execute_script(script_source, is_file, is_launcher, is_graphical): tb = getattr(e, '__traceback__', None) traceback.print_exception(type(e), e, tb) print(f"Thread {thread_id}: script {compile_name} finished") - # Note that newscreen isn't deleted, as it might still be foreground, or it might be ui.rootscreen + # Note that newscreen isn't deleted, as it might still be foreground, or it might be mpos.ui.rootscreen except Exception as e: print(f"Thread {thread_id}: error:") tb = getattr(e, '__traceback__', None) @@ -73,7 +73,7 @@ def execute_script_new_thread(scriptname, is_file, is_launcher, is_graphical): print("main.py: execute_script_new_thread(): error starting new thread thread: ", e) def start_app_by_name(app_name, is_launcher=False): - ui.set_foreground_app(app_name) + mpos.ui.set_foreground_app(app_name) custom_app_dir=f"apps/{app_name}" builtin_app_dir=f"builtin/apps/{app_name}" try: @@ -84,16 +84,16 @@ def start_app_by_name(app_name, is_launcher=False): def start_app(app_dir, is_launcher=False): print(f"main.py start_app({app_dir},{is_launcher}") - ui.set_foreground_app(app_dir) # would be better to store only the app name... + mpos.ui.set_foreground_app(app_dir) # would be better to store only the app name... manifest_path = f"{app_dir}/META-INF/MANIFEST.JSON" app = parse_manifest(manifest_path) start_script_fullpath = f"{app_dir}/{app.entrypoint}" execute_script_new_thread(start_script_fullpath, True, is_launcher, True) # Launchers have the bar, other apps don't have it if is_launcher: - ui.open_bar() + mpos.ui.open_bar() else: - ui.close_bar() + mpos.ui.close_bar() def restart_launcher(): diff --git a/internal_filesystem/lib/mpos/ui.py b/internal_filesystem/lib/mpos/ui.py index 90b29e1c..4f21ef84 100644 --- a/internal_filesystem/lib/mpos/ui.py +++ b/internal_filesystem/lib/mpos/ui.py @@ -1,5 +1,5 @@ import lvgl as lv -from mpos import apps +import mpos.apps NOTIFICATION_BAR_HEIGHT=24 @@ -38,7 +38,7 @@ def close_drawer(to_launcher=False): if drawer_open: drawer_open=False drawer.add_flag(lv.obj.FLAG.HIDDEN) - if not to_launcher and not apps.is_launcher(foreground_app_name): + if not to_launcher and not mpos.apps.is_launcher(foreground_app_name): close_bar() def open_bar(): @@ -55,6 +55,7 @@ def close_bar(): def show_launcher(): global rootscreen + set_foreground_app("com.example.launcher") open_bar() lv.screen_load(rootscreen) diff --git a/internal_filesystem/main.py b/internal_filesystem/main.py index aeb17930..754b4f59 100644 --- a/internal_filesystem/main.py +++ b/internal_filesystem/main.py @@ -1,10 +1,10 @@ import task_handler th = task_handler.TaskHandler(duration=5) # 5ms is recommended for MicroPython+LVGL on desktop -from mpos import ui -ui.create_rootscreen() -ui.create_notification_bar() -ui.create_drawer(display) +import mpos.ui +mpos.ui.create_rootscreen() +mpos.ui.create_notification_bar() +mpos.ui.create_drawer(display) try: import freezefs_mount_builtin