From a91eb9b7cdae73a625bd1f239bba6b12033a4e74 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Tue, 22 Apr 2025 09:23:38 +0200 Subject: [PATCH] Images don't work because no image loader --- launcher.py | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/launcher.py b/launcher.py index b3893f55..d77deb2a 100644 --- a/launcher.py +++ b/launcher.py @@ -9,6 +9,7 @@ def parse_manifest(manifest_path): try: with uio.open(manifest_path, 'r') as f: for line in f: + print(f"Parsing line: {line}") line = line.strip() if line.startswith("Name:"): name = line.split(":", 1)[1].strip() @@ -17,24 +18,27 @@ def parse_manifest(manifest_path): print(f"Error reading {manifest_path}") return name + # Function to load PNG icon def load_icon(icon_path): try: - img = lv.img(lv.screen_active()) - img.set_src(icon_path) - return img + image = lv.image(lv.screen_active()) + image.set_src(icon_path) + return image except Exception as e: print(f"Error loading icon {icon_path}: {e}") # Fallback: create a placeholder image - img = lv.img(lv.screen_active()) - img.set_src(lv.SYMBOL.DUMMY) # Or use a default image - return img + image = lv.image(lv.screen_active()) + image.set_src(lv.SYMBOL.DUMMY) # Or use a default image + return image + # Function to handle icon/label click def on_app_click(event, app_name, app_dir): if event.get_code() == lv.EVENT.CLICKED: print(f"Launching app: {app_name} ({app_dir})") + # Create the app launcher def create_app_launcher(): # Get list of app directories @@ -45,40 +49,34 @@ def create_app_launcher(): except OSError: print("Error accessing /apps directory") return - # Create a container for the grid cont = lv.obj(lv.screen_active()) cont.set_size(lv.pct(100), lv.pct(100)) cont.set_style_pad_all(10, 0) cont.set_style_border_width(0, 0) cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP) - # Grid parameters icon_size = 64 # Adjust based on your display label_height = 20 col_gap = 20 row_gap = 20 - for app_dir in app_dirs: # Paths base_path = f"{apps_dir}/{app_dir}" icon_path = f"{base_path}/res/mipmap-mdpi/launcher_icon.png" manifest_path = f"{base_path}/META-INF/MANIFEST.MF" - # Get app name from MANIFEST.MF app_name = parse_manifest(manifest_path) - # Create a container for each app (icon + label) app_cont = lv.obj(cont) app_cont.set_size(icon_size, icon_size + label_height) app_cont.set_style_border_width(0, 0) app_cont.set_style_pad_all(0, 0) - + app_cont.set_style_bg_color(lv.color_hex(0x00FF00), 0) # Load and display icon - img = load_icon(icon_path) - img.align(lv.ALIGN.TOP_MID, 0, 0) - img.set_size(icon_size, icon_size) - + image = load_icon(icon_path) + image.align(lv.ALIGN.TOP_MID, 0, 0) + image.set_size(icon_size, icon_size) # Create label label = lv.label(app_cont) label.set_text(app_name) @@ -86,11 +84,19 @@ def create_app_launcher(): label.set_width(icon_size) label.align(lv.ALIGN.BOTTOM_MID, 0, 0) label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) - # Add click event to both icon and label - img.add_event_cb(lambda e: on_app_click(e, app_name, app_dir), lv.EVENT.CLICKED, None) + image.add_event_cb(lambda e: on_app_click(e, app_name, app_dir), lv.EVENT.CLICKED, None) label.add_event_cb(lambda e: on_app_click(e, app_name, app_dir), lv.EVENT.CLICKED, None) + # Run the app launcher create_app_launcher() +#import time +#while True: +# lv.task_handler() +# machine.idle() # Allow other tasks to run +# time.sleep_ms(100) + + +