Skip to content
Snippets Groups Projects
Commit fd697190 authored by Renze's avatar Renze
Browse files

Add app directories to the path and change menu to use the provided metadata

parent 6c2d7e47
No related branches found
No related tags found
No related merge requests found
...@@ -7,19 +7,25 @@ next run. ...@@ -7,19 +7,25 @@ next run.
""" """
import buttons import buttons
import color import color
import display import display, os, ujson, sys
import os
def read_metadata(app_folder):
try:
info_file = "/apps/%s/metadata.json" % (app_folder)
with open(info_file) as f:
information = f.read()
return ujson.loads(information)
except BaseException as e:
sys.print_exception(e)
return {'author':'', 'name':app_folder, 'description':'', 'category':'', 'revision': 0}
def list_apps(): def list_apps():
"""Create a list of available apps.""" """Create a list of available apps."""
apps = sorted(os.listdir(".")) appFolders = sorted(os.listdir("/apps"))
# Filter for apps
apps = [app for app in apps if app.endswith(".elf") or app.endswith(".py")]
if "menu.py" in apps: apps = []
apps.remove("menu.py") for appFolder in appFolders:
apps.append([appFolder, read_metadata(appFolder)])
return apps return apps
...@@ -56,7 +62,7 @@ def draw_menu(disp, applist, idx, offset): ...@@ -56,7 +62,7 @@ def draw_menu(disp, applist, idx, offset):
# Wrap around the app-list and draw entries from idx - 3 to idx + 4 # Wrap around the app-list and draw entries from idx - 3 to idx + 4
for y, i in enumerate(range(len(applist) + idx - 3, len(applist) + idx + 4)): for y, i in enumerate(range(len(applist) + idx - 3, len(applist) + idx + 4)):
disp.print( disp.print(
" " + applist[i % len(applist)] + " ", " " + applist[i % len(applist)][1]['name'] + " ",
posy=offset + y * 20 - 40, posy=offset + y * 20 - 40,
bg=COLOR1 if i % 2 == 0 else COLOR2, bg=COLOR1 if i % 2 == 0 else COLOR2,
) )
...@@ -103,7 +109,7 @@ def main(): ...@@ -103,7 +109,7 @@ def main():
disp.clear().update() disp.clear().update()
disp.close() disp.close()
try: try:
os.exec(applist[current]) os.exec("/apps/%s/__init__.py" % applist[current][0])
except OSError as e: except OSError as e:
print("Loading failed: ", e) print("Loading failed: ", e)
os.exit(1) os.exit(1)
......
...@@ -44,6 +44,10 @@ int main(void) ...@@ -44,6 +44,10 @@ int main(void)
gc_init(&__HeapBase + 1024 * 10, &__HeapLimit); gc_init(&__HeapBase + 1024 * 10, &__HeapLimit);
mp_init(); mp_init();
mp_obj_list_init(mp_sys_path, 0);
mp_obj_list_append(mp_sys_path, MP_ROM_QSTR(MP_QSTR_));
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_lib));
mp_obj_list_append(mp_sys_path, MP_OBJ_NEW_QSTR(MP_QSTR__slash_apps));
if (cnt > 0) { if (cnt > 0) {
pyexec_file_if_exists(script_name); pyexec_file_if_exists(script_name);
......
...@@ -118,3 +118,7 @@ Q(INPUT) ...@@ -118,3 +118,7 @@ Q(INPUT)
Q(OUTPUT) Q(OUTPUT)
Q(PULL_UP) Q(PULL_UP)
Q(PULL_DOWN) Q(PULL_DOWN)
/* path */
Q(/apps)
Q(/lib)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment