diff --git a/preload/menu.py b/preload/menu.py index 2cf1f74b5292aae1d068d0d96e7d3df0862d9dfc..5d623a6b589a50284e5edadc781cf2de10a45180 100644 --- a/preload/menu.py +++ b/preload/menu.py @@ -7,19 +7,25 @@ next run. """ import buttons import color -import display -import os - +import display, os, ujson, sys + +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(): - """Create a list of available apps.""" - apps = sorted(os.listdir(".")) - - # Filter for apps - apps = [app for app in apps if app.endswith(".elf") or app.endswith(".py")] - - if "menu.py" in apps: - apps.remove("menu.py") + """Create a list of available apps.""" + appFolders = sorted(os.listdir("/apps")) + + apps = [] + for appFolder in appFolders: + apps.append([appFolder, read_metadata(appFolder)]) return apps @@ -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 for y, i in enumerate(range(len(applist) + idx - 3, len(applist) + idx + 4)): disp.print( - " " + applist[i % len(applist)] + " ", + " " + applist[i % len(applist)][1]['name'] + " ", posy=offset + y * 20 - 40, bg=COLOR1 if i % 2 == 0 else COLOR2, ) @@ -103,7 +109,7 @@ def main(): disp.clear().update() disp.close() try: - os.exec(applist[current]) + os.exec("/apps/%s/__init__.py" % applist[current][0]) except OSError as e: print("Loading failed: ", e) os.exit(1) diff --git a/pycardium/main.c b/pycardium/main.c index f8f3f793b3d3467ddafbe577792afbb2f58f30ea..983d4487a952423fd129aa168359cc2ddb702294 100644 --- a/pycardium/main.c +++ b/pycardium/main.c @@ -44,6 +44,10 @@ int main(void) gc_init(&__HeapBase + 1024 * 10, &__HeapLimit); 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) { pyexec_file_if_exists(script_name); diff --git a/pycardium/modules/qstrdefs.h b/pycardium/modules/qstrdefs.h index 3300907012a50e3df7d3815458832a0c8ba0ddea..afe87735b2bd98386260ffd32829f80c6c3cb6ee 100644 --- a/pycardium/modules/qstrdefs.h +++ b/pycardium/modules/qstrdefs.h @@ -118,3 +118,7 @@ Q(INPUT) Q(OUTPUT) Q(PULL_UP) Q(PULL_DOWN) + +/* path */ +Q(/apps) +Q(/lib)