Skip to content
Snippets Groups Projects
Commit c2935c8c authored by Daniel Hoffend's avatar Daniel Hoffend
Browse files

fixed syntax

parent 3017591a
Branches
Tags
No related merge requests found
......@@ -17,12 +17,14 @@ BUTTON_TIMER_POPPED = -1
COLOR1, COLOR2 = (color.CHAOSBLUE_DARK, color.CHAOSBLUE)
MAXCHARS = 11
def create_folders():
try:
os.mkdir("/apps")
except:
pass
def read_metadata(app_folder):
try:
info_file = "/apps/%s/metadata.json" % (app_folder)
......@@ -31,7 +33,14 @@ def read_metadata(app_folder):
return ujson.loads(information)
except BaseException as e:
sys.print_exception(e)
return {'author':'', 'name':app_folder, 'description':'', 'category':'', 'revision': 0}
return {
"author": "",
"name": app_folder,
"descriptionr": "",
"category": "",
"revision": 0,
}
def list_apps():
"""Create a list of available apps."""
......@@ -40,7 +49,18 @@ def list_apps():
# add main application
for mainFile in os.listdir("/"):
if mainFile == "main.py":
apps.append(["/main.py", {'author':'', 'name':'Main Clock', 'description':'', 'category':'', 'revision': 0}])
apps.append(
[
"/main.py",
{
"author": "card10badge Team",
"name": "Main Clock",
"description": "",
"category": "",
"revision": 0,
},
]
)
# list all hatchary style apps (not .elf and not .py)
# with or without metadata.json
......@@ -51,15 +71,38 @@ def list_apps():
# list simple python scripts
for pyFile in sorted(os.listdir("/apps")):
if pyFile.endswith(".py"):
apps.append(["/apps/%s" % pyFile, {'author':'', 'name':pyFile, 'description':'', 'category':'', 'revision': 0}])
apps.append(
[
"/apps/%s" % pyFile,
{
"author": "",
"name": pyFile,
"description": "",
"category": "",
"revision": 0,
},
]
)
# list simple elf binaries
for elfFile in sorted(os.listdir("/apps")):
if elfFile.endswith(".elf"):
apps.append(["/apps/%s" % elfFile, {'author':'', 'name':elfFile, 'description':'', 'category':'', 'revision': 0}])
apps.append(
[
"/apps/%s" % elfFile,
{
"author": "",
"name": elfFile,
"description": "",
"category": "",
"revision": 0,
},
]
)
return apps
def button_events(timeout=0):
"""Iterate over button presses (event-loop)."""
yield 0
......@@ -90,6 +133,7 @@ def button_events(timeout=0):
utime.sleep_ms(10)
def triangle(disp, x, y, left, scale=6, color=[255, 0, 0]):
"""Draw a triangle to show there's more text in this line"""
yf = 1 if left else -1
......@@ -97,6 +141,7 @@ def triangle(disp, x, y, left, scale=6, color=[255,0,0]):
disp.line(x, y, x, y + scale, col=color)
disp.line(x, y + scale, x - scale * yf, y + int(scale / 2), col=color)
def draw_menu(disp, applist, pos, appcount, lineoffset):
disp.clear()
......@@ -113,24 +158,31 @@ def draw_menu(disp, applist, pos, appcount, lineoffset):
break
if i >= start:
disp.rect(
0, (i - start) * 20, 159, (i - start) * 20 + 20,
col=COLOR1 if i == pos else COLOR2
0,
(i - start) * 20,
159,
(i - start) * 20 + 20,
col=COLOR1 if i == pos else COLOR2,
)
line = app[1]['name']
line = app[1]["name"]
linelength = len(line)
off = 0
# calc line offset for scrolling
if i == pos and linelength > (MAXCHARS - 1) and lineoffset > 0:
off = lineoffset if lineoffset + (MAXCHARS - 1) < linelength else linelength - (MAXCHARS - 1)
off = (
lineoffset
if lineoffset + (MAXCHARS - 1) < linelength
else linelength - (MAXCHARS - 1)
)
if lineoffset > linelength:
off = 0
disp.print(
" " + line[off : (off + (MAXCHARS - 1))],
posy=(i - start) * 20,
bg=COLOR1 if i == pos else COLOR2
bg=COLOR1 if i == pos else COLOR2,
)
if i == pos:
disp.print(">", posy=(i - start) * 20, fg=color.COMMYELLOW, bg=COLOR1)
......@@ -191,7 +243,10 @@ def main():
elif ev == BUTTON_TIMER_POPPED:
timercountpopped += 1
if timercountpopped >= timerstartscroll and (timercountpopped - timerstartscroll) % timerscrollspeed == 0:
if (
timercountpopped >= timerstartscroll
and (timercountpopped - timerstartscroll) % timerscrollspeed == 0
):
lineoffset += 1
elif ev == buttons.TOP_RIGHT:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment