You've already forked MicroPythonOS
mirror of
https://github.com/m5stack/MicroPythonOS.git
synced 2026-05-20 11:51:27 -07:00
Configurable entry point
This commit is contained in:
@@ -4,17 +4,18 @@ import machine
|
||||
|
||||
def parse_manifest(manifest_path):
|
||||
name = "Unknown"
|
||||
main_script = None # Default to None if Main-Script is not found
|
||||
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()
|
||||
break
|
||||
elif line.startswith("Main-Script:"):
|
||||
main_script = line.split(":", 1)[1].strip()
|
||||
except OSError:
|
||||
print(f"Error reading {manifest_path}")
|
||||
return name
|
||||
return name, main_script
|
||||
|
||||
|
||||
def on_app_click(event, app_name, main_script, app_dir):
|
||||
@@ -44,9 +45,12 @@ for app_dir in [d for d in uos.listdir(apps_dir) if uos.stat(f"{apps_dir}/{d}")[
|
||||
#icon_path = f"{base_path}/res/mipmap-mdpi/launcher_icon.png"
|
||||
icon_path = "/resources/icon_64x64.bin"
|
||||
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)
|
||||
app_name, main_script = parse_manifest(manifest_path)
|
||||
if main_script:
|
||||
main_script = f"{base_path}/{main_script}"
|
||||
else:
|
||||
main_script = f"{base_path}/assets/main.py" # default
|
||||
# Create a container for each app (icon + label)
|
||||
app_cont = lv.obj(cont)
|
||||
app_cont.set_size(iconcont_width, iconcont_height)
|
||||
|
||||
@@ -1,2 +1,3 @@
|
||||
Manifest-Version: 1.0
|
||||
Name: WSTest
|
||||
Main-Script: assets/bitcoin_price.py
|
||||
|
||||
@@ -236,6 +236,18 @@ restart_btn.add_event_cb(lambda event: machine.reset(),lv.EVENT.CLICKED,None)
|
||||
import _thread
|
||||
import traceback
|
||||
|
||||
def get_filename(path):
|
||||
try:
|
||||
if not path or not isinstance(path, str):
|
||||
return None
|
||||
# Extract filename using rsplit and take the last part
|
||||
filename = path.rsplit('/', 1)[-1]
|
||||
# Limit to the first 7 characters
|
||||
return filename[:7]
|
||||
except Exception as e:
|
||||
print(f"Error extracting filename: {str(e)}")
|
||||
return None
|
||||
|
||||
def execute_script(script_source, is_file, lvgl_obj, return_to_launcher):
|
||||
thread_id = _thread.get_ident()
|
||||
print(f"Thread {thread_id}: executing script")
|
||||
@@ -252,8 +264,7 @@ def execute_script(script_source, is_file, lvgl_obj, return_to_launcher):
|
||||
script_source = f.read()
|
||||
print(f"Thread {thread_id}: starting script")
|
||||
try:
|
||||
# Use a short filename for compile() to avoid 'name too long' error
|
||||
compile_name = 'script' if not is_file else 'main.py' # Shortened name
|
||||
compile_name = 'script' if not is_file else get_filename(script_source) # Only filename, to avoid 'name too long' error
|
||||
compiled_script = compile(script_source, compile_name, 'exec')
|
||||
exec(compiled_script, script_globals)
|
||||
except Exception as e:
|
||||
|
||||
Reference in New Issue
Block a user