EMF_Camp_Badge/badge_store/main.py

95 lines
2.3 KiB
Python
Raw Normal View History

"""Official TiLDA MK4 Badge Store App
switches between app libraries, updates and installs apps.
2018-07-15 06:53:48 -04:00
To publish apps use https://badge.emfcamp.org"""
___license___ = "MIT"
___title___ = "Badge Store"
___dependencies___ = ["app", "badge_store", "dialogs", "ugfx_helper"]
2018-07-22 06:34:07 -04:00
___categories___ = ["System"]
2018-07-15 06:53:48 -04:00
___bootstrapped___ = True
import ugfx_helper
2018-07-15 06:53:48 -04:00
import os
import wifi
2018-08-02 17:42:45 -04:00
from dialogs import *
import app
from lib.badge_store import BadgeStore
2018-07-15 06:53:48 -04:00
### VIEWS ###
ugfx_helper.init()
2018-08-02 17:42:45 -04:00
store = BadgeStore()
title = "TiLDA Badge Store"
2018-07-15 06:53:48 -04:00
def clear():
ugfx.clear(ugfx.html_color(0x7c1143))
2018-08-02 17:42:45 -04:00
def show_categories():
with WaitingMessage():
menu_items = [{"title": c, "category": c} for c in store.get_categories()]
2018-07-15 06:53:48 -04:00
2018-08-02 17:42:45 -04:00
option = prompt_option(menu_items, none_text="Back", text="Categories", title=title)
if option:
show_apps(option["category"])
else:
return
def show_apps(c):
menu_items = [{"title": a, "app": a} for a in store.get_apps(c)]
option = prompt_option(menu_items, none_text="Back", title=title)
2018-07-15 06:53:48 -04:00
2018-08-02 17:42:45 -04:00
if option:
show_app(option["app"])
else:
return
def show_app(a):
with WaitingMessage():
app_info = store.get_app(a)
install = prompt_boolean(app_info["description"], title=a, true_text="Install", false_text="Back")
if install:
with WaitingMessage(title="Installing %s" % a, text="Please wait...") as message:
installers = store.install(a)
n = len(installers)
for i, installer in enumerate(installers):
message.text = "%s (%s/%s)" % (installer.path, i + 1, n)
installer.download()
notice("App %s has been successfully installed" % a, title=title, close_text="Back")
def show_update():
2018-07-15 06:53:48 -04:00
None
2018-08-02 17:42:45 -04:00
def show_remove():
2018-07-15 06:53:48 -04:00
None
def main_menu():
while True:
clear()
print()
menu_items = [
2018-08-02 17:42:45 -04:00
{"title": "Install Apps", "function": show_categories},
{"title": "Update", "function": show_update},
{"title": "Manage Apps", "function": show_remove}
2018-07-15 06:53:48 -04:00
]
2018-08-02 17:42:45 -04:00
option = prompt_option(menu_items, none_text="Exit", text="What do you want to do?", title=title)
2018-07-15 06:53:48 -04:00
if option:
option["function"]()
else:
2018-08-05 17:14:31 -04:00
app.restart_to_default()
2018-07-15 06:53:48 -04:00
wifi.connect(show_wait_message=True)
2018-07-15 06:53:48 -04:00
main_menu()
2018-08-02 17:42:45 -04:00
#show_app("launcher")