Skip to content
Snippets Groups Projects

Hatchery support

Closed Renze requested to merge renze/hatchery_apps into master
3 unresolved threads
Files
3
+ 35
12
@@ -9,21 +9,43 @@ import buttons
import color
import display
import os
import ujson
import sys
def create_folders():
try:
os.mkdir("/apps")
except:
pass
try:
os.mkdir("/elf")
except:
pass
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(["/apps/%s/__init__.py" % appFolder, read_metadata(appFolder)])
for elfFile in sorted(os.listdir("/elf")):
if elfFile.endswith(".elf"):
apps.append(["/elf/%s" % elfFile, {'author':'', 'name':"ELF: "+elfFile[:-4], 'description':'', 'category':'', 'revision': 0}])
return apps
def button_events():
"""Iterate over button presses (event-loop)."""
yield 0
@@ -56,7 +78,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,
)
@@ -66,6 +88,7 @@ def draw_menu(disp, applist, idx, offset):
def main():
create_folders()
disp = display.open()
applist = list_apps()
numapps = len(applist)
@@ -103,7 +126,7 @@ def main():
disp.clear().update()
disp.close()
try:
os.exec(applist[current])
os.exec(applist[current][0])
except OSError as e:
print("Loading failed: ", e)
os.exit(1)
Loading