Skip to content

Commit 12ca041

Browse files
launcher.py: add support for builtin apps
1 parent 7cff865 commit 12ca041

File tree

1 file changed

+109
-0
lines changed
  • internal_filesystem/apps_builtin/com.example.launcher/assets

1 file changed

+109
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# bin files:
2+
# All icons took: 1085ms
3+
# All icons took: 1051ms
4+
# All icons took: 1032ms
5+
# All icons took: 1118ms
6+
# png files:
7+
# All icons took: 1258ms
8+
# All icons took: 1457ms
9+
# All icons took: 1250ms
10+
# Most of this time is actually spent reading and parsing manifests.
11+
12+
import uos
13+
import lvgl as lv
14+
15+
# Create a container for the grid
16+
cont = lv.obj(subwindow)
17+
cont.set_size(lv.pct(100), lv.pct(100))
18+
cont.set_style_pad_all(10, 0)
19+
cont.set_flex_flow(lv.FLEX_FLOW.ROW_WRAP)
20+
21+
# Grid parameters
22+
icon_size = 64 # Adjust based on your display
23+
label_height = 24
24+
iconcont_width = icon_size + 24
25+
iconcont_height = icon_size + label_height
26+
27+
import time
28+
start = time.ticks_ms()
29+
30+
def load_icon(icon_path):
31+
with open(icon_path, 'rb') as f:
32+
f.seek(12) # first 12 bytes are headers
33+
image_data = f.read()
34+
image_dsc = lv.image_dsc_t({
35+
"header": {
36+
"magic": lv.IMAGE_HEADER_MAGIC,
37+
"w": 64,
38+
"h": 64,
39+
"stride": 64 * 2,
40+
"cf": lv.COLOR_FORMAT.RGB565A8
41+
},
42+
'data_size': len(image_data),
43+
'data': image_data
44+
})
45+
return image_dsc
46+
47+
# Check and collect subdirectories from existing directories
48+
apps_dir = "/apps"
49+
apps_dir_builtin = "/apps_builtin"
50+
app_dirs = []
51+
seen_base_names = set()
52+
53+
# Check and collect unique subdirectories from existing directories
54+
for dir_path in [apps_dir, apps_dir_builtin]:
55+
try:
56+
# Verify directory exists and is a directory
57+
if uos.stat(dir_path)[0] & 0x4000:
58+
# Iterate over subdirectories
59+
for d in uos.listdir(dir_path):
60+
full_path = f"{dir_path}/{d}"
61+
# Check if it's a directory
62+
if uos.stat(full_path)[0] & 0x4000:
63+
# Extract base name (e.g., 'example' from '/apps/example')
64+
base_name = d
65+
# Only add if base name hasn't been seen
66+
if base_name not in seen_base_names:
67+
app_dirs.append(full_path)
68+
seen_base_names.add(base_name)
69+
except OSError:
70+
# Skip if directory doesn't exist or isn't accessible
71+
pass
72+
73+
# Should we skip 'Launcher' apps from the list here?
74+
for app_dir in app_dirs:
75+
# Paths
76+
app_dir_fullpath = f"{apps_dir}/{app_dir}"
77+
app_name, main_script = parse_manifest(f"{app_dir_fullpath}/META-INF/MANIFEST.MF")
78+
# Create a container for each app (icon + label)
79+
app_cont = lv.obj(cont)
80+
app_cont.set_size(iconcont_width, iconcont_height)
81+
app_cont.set_style_border_width(0, 0)
82+
app_cont.set_style_pad_all(0, 0)
83+
# Load and display icon
84+
icon_path = f"{app_dir_fullpath}/res/mipmap-mdpi/icon_64x64.bin"
85+
image = lv.image(app_cont)
86+
try:
87+
image.set_src(load_icon(icon_path))
88+
except Exception as e:
89+
print(f"Error loading icon {icon_path}: {e} - loading default icon")
90+
icon_path = "/resources/default_icon_64x64.bin"
91+
try:
92+
image.set_src(load_icon(icon_path))
93+
except Exception as e:
94+
print(f"Error loading default icon {icon_path}: {e} - using symbol")
95+
image.set_src(lv.SYMBOL.STOP) # square block
96+
image.align(lv.ALIGN.TOP_MID, 0, 0)
97+
image.set_size(icon_size, icon_size)
98+
# Create label
99+
label = lv.label(app_cont)
100+
label.set_text(app_name)
101+
label.set_long_mode(lv.label.LONG.WRAP)
102+
label.set_width(iconcont_width)
103+
label.align(lv.ALIGN.BOTTOM_MID, 0, 0)
104+
label.set_style_text_align(lv.TEXT_ALIGN.CENTER, 0)
105+
app_cont.add_event_cb(lambda e, app_dir_fullpath=app_dir_fullpath: start_app(app_dir_fullpath), lv.EVENT.CLICKED, None)
106+
107+
end = time.ticks_ms()
108+
print(f"Displaying all icons took: {end-start}ms")
109+

0 commit comments

Comments
 (0)