From 74c0041f2c4780e36aa95c4b4a446154180e1972 Mon Sep 17 00:00:00 2001 From: Thomas Farstrike Date: Wed, 23 Apr 2025 10:56:10 +0200 Subject: [PATCH] No useless functions --- apps/com.example.launcher/assets/main.py | 117 ++++++++++++----------- 1 file changed, 59 insertions(+), 58 deletions(-) diff --git a/apps/com.example.launcher/assets/main.py b/apps/com.example.launcher/assets/main.py index 1ecc1319..f3cd424c 100644 --- a/apps/com.example.launcher/assets/main.py +++ b/apps/com.example.launcher/assets/main.py @@ -23,64 +23,65 @@ def on_app_click(event, app_name, main_script, app_dir): print(f"Launching app: {app_name} by starting {main_script} in {app_dir})") run_app(main_script, True) -def create_app_launcher(): - # Get list of app directories - apps_dir = "/apps" - app_dirs = [] + +# Get list of app directories +apps_dir = "/apps" +app_dirs = [] +try: + app_dirs = [d for d in uos.listdir(apps_dir) if uos.stat(f"{apps_dir}/{d}")[0] & 0x4000] # Directories only +except OSError: + print("Error accessing /apps directory") + return +# Create a container for the grid +cont = lv.obj(subwindow) +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 +iconcont_size = icon_size + +label_height = 20 +col_gap = 20 +row_gap = 20 +for app_dir in app_dirs: # TODO: skip 'Launcher' apps from the list here + # 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" + main_script = f"{base_path}/assets/main.py" + # 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 + image = lv.image(app_cont) try: - app_dirs = [d for d in uos.listdir(apps_dir) if uos.stat(f"{apps_dir}/{d}")[0] & 0x4000] # Directories only - except OSError: - print("Error accessing /apps directory") - return - # Create a container for the grid - cont = lv.obj(subwindow) - 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: # TODO: skip 'Launcher' apps from the list here - # 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" - main_script = f"{base_path}/assets/main.py" - # 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 - image = lv.image(app_cont) - try: - with open(icon_path, 'rb') as f: - png_data = f.read() - png_image_dsc = lv.image_dsc_t({ - 'data_size': len(png_data), - 'data': png_data - }) - image.set_src(png_image_dsc) - except Exception as e: - print(f"Error loading icon {icon_path}: {e}") - # Fallback: create a placeholder image - image.set_src(lv.SYMBOL.DUMMY) # Or use a default image - 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) - label.set_long_mode(lv.label.LONG.WRAP) - label.set_width(icon_size) - label.align(lv.ALIGN.BOTTOM_MID, 0, 0) - label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) - app_cont.add_event_cb(lambda e, name=app_name, main_script=main_script, dir=app_dir: on_app_click(e, name, main_script, dir), lv.EVENT.CLICKED, None) + with open(icon_path, 'rb') as f: + png_data = f.read() + png_image_dsc = lv.image_dsc_t({ + 'data_size': len(png_data), + 'data': png_data + }) + image.set_src(png_image_dsc) + except Exception as e: + print(f"Error loading icon {icon_path}: {e}") + # Fallback: create a placeholder image + image.set_src(lv.SYMBOL.DUMMY) # Or use a default image + 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) + label.set_long_mode(lv.label.LONG.WRAP) + label.set_width(icon_size) + label.align(lv.ALIGN.BOTTOM_MID, 0, 0) + label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0) + app_cont.add_event_cb(lambda e, name=app_name, main_script=main_script, dir=app_dir: on_app_click(e, name, main_script, dir), lv.EVENT.CLICKED, None) + -create_app_launcher()