You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Improve icon handling
This commit is contained in:
Binary file not shown.
@@ -29,6 +29,23 @@ iconcont_height = icon_size + label_height
|
||||
import time
|
||||
start = time.ticks_ms()
|
||||
|
||||
def load_icon(icon_path):
|
||||
with open(icon_path, 'rb') as f:
|
||||
f.seek(12) # first 12 bytes are headers
|
||||
image_data = f.read()
|
||||
image_dsc = lv.image_dsc_t({
|
||||
"header": {
|
||||
"magic": lv.IMAGE_HEADER_MAGIC,
|
||||
"w": 64,
|
||||
"h": 64,
|
||||
"stride": 64 * 2,
|
||||
"cf": lv.COLOR_FORMAT.RGB565A8
|
||||
},
|
||||
'data_size': len(image_data),
|
||||
'data': image_data
|
||||
})
|
||||
return image_dsc
|
||||
|
||||
# Get list of app directories
|
||||
# Should we skip 'Launcher' apps from the list here?
|
||||
apps_dir = "/apps"
|
||||
@@ -43,27 +60,17 @@ for app_dir in [d for d in uos.listdir(apps_dir) if uos.stat(f"{apps_dir}/{d}")[
|
||||
app_cont.set_style_pad_all(0, 0)
|
||||
# Load and display icon
|
||||
icon_path = f"{app_dir_fullpath}/res/mipmap-mdpi/icon_64x64.bin"
|
||||
#icon_path = "/resources/default_icon_64x64.bin"
|
||||
image = lv.image(app_cont)
|
||||
try:
|
||||
with open(icon_path, 'rb') as f:
|
||||
f.seek(12) # first 12 bytes are headers
|
||||
image_data = f.read()
|
||||
image_dsc = lv.image_dsc_t({
|
||||
"header": {
|
||||
"magic": lv.IMAGE_HEADER_MAGIC,
|
||||
"w": 64,
|
||||
"h": 64,
|
||||
"stride": 64 * 2,
|
||||
"cf": lv.COLOR_FORMAT.RGB565A8
|
||||
},
|
||||
'data_size': len(image_data),
|
||||
'data': image_data
|
||||
})
|
||||
image.set_src(image_dsc)
|
||||
image.set_src(load_icon(icon_path))
|
||||
except Exception as e:
|
||||
print(f"Error loading icon {icon_path}: {e}")
|
||||
image.set_src(lv.SYMBOL.STOP) # square block
|
||||
print(f"Error loading icon {icon_path}: {e} - loading default icon")
|
||||
icon_path = "/resources/default_icon_64x64.bin"
|
||||
try:
|
||||
image.set_src(load_icon(icon_path))
|
||||
except Exception as e:
|
||||
print(f"Error loading default icon {icon_path}: {e} - using symbol")
|
||||
image.set_src(lv.SYMBOL.STOP) # square block
|
||||
image.align(lv.ALIGN.TOP_MID, 0, 0)
|
||||
image.set_size(icon_size, icon_size)
|
||||
# Create label
|
||||
|
||||
@@ -349,11 +349,8 @@ def start_app(app_dir, is_launcher=False):
|
||||
start_script_fullpath = f"{app_dir}/{start_script}"
|
||||
execute_script_new_thread(start_script_fullpath, True, is_launcher, True)
|
||||
|
||||
def run_launcher():
|
||||
start_app("/apps/com.example.launcher", True)
|
||||
|
||||
execute_script_new_thread("/autorun.py", True, False, False)
|
||||
run_launcher()
|
||||
start_app("/apps/com.example.launcher", True)
|
||||
|
||||
# If we got this far without crashing, then no need to rollback the update
|
||||
import ota.rollback
|
||||
|
||||
+2
-1
@@ -1,2 +1,3 @@
|
||||
#~/sources/lvgl_micropython/lib/lvgl/scripts/LVGLImage.py --ofmt BIN --cf RGB565 -o icon_64x64.bin icon_64x64.png
|
||||
~/sources/lvgl_micropython/lib/lvgl/scripts/LVGLImage.py --ofmt BIN --cf RGB565 icon_64x64.png
|
||||
#~/sources/lvgl_micropython/lib/lvgl/scripts/LVGLImage.py --ofmt BIN --cf RGB565 icon_64x64.png
|
||||
~/sources/lvgl_micropython/lib/lvgl/scripts/LVGLImage.py --ofmt BIN --cf RGB565A8 "$1"
|
||||
|
||||
Reference in New Issue
Block a user