diff --git a/badge_store/main.py b/badge_store/main.py index 5b53447..5708631 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -13,6 +13,7 @@ ___bootstrapped___ = True import ugfx_helper, os, database, wifi, app, ospath from dialogs import * from lib.badge_store import BadgeStore +from app import * ### VIEWS ### @@ -29,10 +30,10 @@ def clear(): def show_categories(): clear() - with WaitingMessage(): + with WaitingMessage(title=title, text="Loading categories..."): menu_items = [{"title": c, "category": c} for c in store.get_categories()] - option = prompt_option(menu_items, none_text="Back", text="Categories", title=title) + option = prompt_option(menu_items, none_text="Back", title="Install: Categories") if option: show_apps(option["category"]) @@ -43,51 +44,70 @@ def show_apps(c): clear() menu_items = [{"title": a, "app": a} for a in store.get_apps(c)] - option = prompt_option(menu_items, none_text="Back", title=title) + option = prompt_option(menu_items, none_text="Back", title="Install: " + c) if option: - show_app(option["app"]) + show_app(option["app"],c) else: - return + show_categories() -def show_app(a): +def show_app(a,c): clear() - with WaitingMessage(): + with WaitingMessage(title=title, text="Loading app description..."): app_info = store.get_app(a) - install = prompt_boolean(app_info["description"], title=a, true_text="Install", false_text="Back") + + # Try to get the 'title' key from app_info, falling back to the value of a if not present + name = app_info.get("title", a) + desc = app_info["description"].strip() + app_text = """App:\n{}\n\nDescription:\n{}""".format(name, desc) + install = prompt_boolean(app_text , title="Install App", true_text="Install", false_text="Back") if install: - with WaitingMessage(title="Installing %s" % a, text="Please wait...") as message: + app_text = "App:\n{}\n\n".format(name) + with WaitingMessage(title="Installing App...", text="%sGetting ready..." % app_text) 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) + message.text = "%s%s (%s/%s)" % (app_text + "Downloading files...\n\n", installer.path, i + 1, n) installer.download() app.uncache_apps() - notice("App %s has been successfully installed" % a, title=title, close_text="Back") + launch = prompt_boolean( + "%sSuccessfully installed.\n\nPress A to launch the app.\n\nPress B to list more \"%s\" apps." % (app_text, c), title="Install Success!", true_text="Launch", false_text="Back") + if (launch): + for app_obj in get_apps(): + if app_obj.name == a: + app_obj.boot() + else: + show_apps(c) + else: + show_apps(c) + def show_update(): clear() - update = prompt_boolean("Do you want to update all apps on this badge?", title="Update", true_text="OK", false_text="Back") + update = prompt_boolean("Do you want to update all apps on this badge?", title="Update all Apps", true_text="OK", false_text="Back") if update: clear() - with WaitingMessage(title=title, text="Please wait...") as message: - installers = store.update(_get_current_apps()) + with WaitingMessage(title=title, text="Getting updates...") as message: + update_text = "Downloading files:" + installers = store.install(_get_current_apps()) n = len(installers) for i, installer in enumerate(installers): - message.text = "%s (%s/%s)" % (installer.path, i + 1, n) + message.text = "%s\n\n%s (%s/%s)" % (update_text, installer.path, i + 1, n) installer.download() - notice("Your badge has been successfully updated", title=title, close_text="Back") + notice("Your badge has been successfully updated.", title="Update Success!", close_text="Back") def show_remove(): clear() - app_to_remove = prompt_option(_get_current_apps(), none_text="Back", text="Select App to remove") + app_to_remove = prompt_option(_get_current_apps(), title="Remove App...", none_text="Back", text="Select an App to remove.") if app_to_remove: ospath.recursive_rmdir(app_to_remove) app.uncache_apps() - notice("%s has been removed" % app_to_remove, title=title, close_text="Back") + + app_text = """App:\n{}""".format(app_to_remove) + notice("\"%s\"\n\nThe app has now been removed." % app_text, title="Remove Success!", close_text="Back") def main_menu(): while True: diff --git a/lib/dialogs.py b/lib/dialogs.py index eecebd1..9599aec 100644 --- a/lib/dialogs.py +++ b/lib/dialogs.py @@ -41,18 +41,30 @@ def prompt_boolean(text, title="TiLDA", true_text="Yes", false_text="No", font=F window = ugfx.Container(5, 5, width, height) window.show() ugfx.set_default_font(font) - window.text(5, 10, title, TILDA_COLOR) - window.line(0, 30, width, 30, ugfx.BLACK) + window.text(5, 5, title, TILDA_COLOR) + window.line(0, 25, width, 25, ugfx.BLACK) if false_text: true_text = "A: " + true_text false_text = "B: " + false_text ugfx.set_default_font(font) - label = ugfx.Label(5, 30, width - 10, height - 80, text = text, parent=window) + label = ugfx.Label(5, 30, width - 10, height - 80, text = text, parent=window, justification=4) + ugfx.set_default_font(FONT_MEDIUM_BOLD) - button_yes = ugfx.Button(5, height - 40, width // 2 - 15 if false_text else width - 15, 30 , true_text, parent=window) - button_no = ugfx.Button(width // 2 + 5, height - 40, width // 2 - 15, 30 , false_text, parent=window) if false_text else None + button_yes = ugfx.Button(5, height - 40, width // 2 - 10 if false_text else width - 15, 30 , true_text, parent=window) + button_no = ugfx.Button(width // 2, height - 40, width // 2 - 10, 30 , false_text, parent=window) if false_text else None + + # Find newlines in label text to scroll. + def find_all(a_str, sub): + start = 0 + while True: + start = a_str.find(sub, start) + if start == -1: return + yield start + 1 # Trap: \n becomes a single character, not 2. + start += len(sub) # use start += 1 to find overlapping matches + new_line_pos = [0] + list(find_all(text, '\n')) + text_scroll_offset = 0 try: #button_yes.attach_input(ugfx.BTN_A,0) # todo: re-enable once working @@ -64,6 +76,16 @@ def prompt_boolean(text, title="TiLDA", true_text="Yes", false_text="No", font=F sleep.wfi() if buttons.is_triggered(buttons.Buttons.BTN_A): return True if buttons.is_triggered(buttons.Buttons.BTN_B): return False + # Allow scrolling by new lines. + if buttons.is_triggered(buttons.Buttons.JOY_Down): + if text_scroll_offset < len(new_line_pos)-1: + text_scroll_offset = text_scroll_offset + 1 + label.text(text[new_line_pos[text_scroll_offset]:]) + + if buttons.is_triggered(buttons.Buttons.JOY_Up): + if (text_scroll_offset > 0): + text_scroll_offset=text_scroll_offset - 1 + label.text(text[new_line_pos[text_scroll_offset]:]) finally: window.hide() @@ -167,9 +189,10 @@ def prompt_option(options, index=0, text = None, title=None, select_text="OK", n window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10) window.show() + list_y = 30 if title: - window.text(5, 10, title, TILDA_COLOR) + window.text(5, 5, title, TILDA_COLOR) window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK) list_y = 30 if text: @@ -179,7 +202,7 @@ def prompt_option(options, index=0, text = None, title=None, select_text="OK", n else: window.text(5, 10, text, ugfx.BLACK) - options_list = ugfx.List(5, list_y, ugfx.width() - 25, 260 - list_y, parent = window) + options_list = ugfx.List(5, list_y, ugfx.width() - 24, 265 - list_y, parent = window) options_list.disable_draw() optnum = 1 @@ -204,7 +227,7 @@ def prompt_option(options, index=0, text = None, title=None, select_text="OK", n none_text = "B: " + none_text button_select = ugfx.Button(5, ugfx.height() - 50, 105 if none_text else 200, 30 , select_text, parent=window) - button_none = ugfx.Button(117, ugfx.height() - 50, 105, 30 , none_text, parent=window) if none_text else None + button_none = ugfx.Button(116, ugfx.height() - 50, 105, 30 , none_text, parent=window) if none_text else None try: while True: @@ -269,9 +292,9 @@ class WaitingMessage: def __init__(self, text="Please Wait...", title="TiLDA"): self.window = ugfx.Container(30, 30, ugfx.width() - 60, ugfx.height() - 60) self.window.show() - self.window.text(5, 10, title, TILDA_COLOR) - self.window.line(0, 30, ugfx.width() - 60, 30, ugfx.BLACK) - self.label = ugfx.Label(5, 40, self.window.width() - 10, ugfx.height() - 40, text = text, parent=self.window) + self.window.text(5, 5, title, TILDA_COLOR) + self.window.line(0, 25, ugfx.width() - 60, 25, ugfx.BLACK) + self.label = ugfx.Label(5, 40, self.window.width() - 15, ugfx.height() - 40, text = text, parent=self.window) # Indicator to show something is going on #self.indicator = ugfx.Label(ugfx.width() - 100, 0, 20, 20, text = "...", parent=self.window)