From 1891ef659fc0455e29a1f2e76faa07363194d258 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Tue, 4 Sep 2018 17:08:01 +0100 Subject: [PATCH 01/13] Improve installing status Also makes long app names not overflow title. --- badge_store/main.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/badge_store/main.py b/badge_store/main.py index 0fa0a47..ec30904 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -58,11 +58,19 @@ def show_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: + app_text = "App:\n" + try: + app_text += app_info["title"] + '\n' + except: + pass + finally: + app_text += a + '\n\n' + + with WaitingMessage(title="Installing App...", text="%sGetting ready..." % app_text) as message: installers = store.install(_get_current_apps() + [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() From 85cbc6cb847af2be48fa216af1b8775029224352 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Tue, 4 Sep 2018 18:28:12 +0100 Subject: [PATCH 02/13] Post install launch and back --- badge_store/main.py | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/badge_store/main.py b/badge_store/main.py index ec30904..e950134 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 ### @@ -46,11 +47,11 @@ def show_apps(c): option = prompt_option(menu_items, none_text="Back", title=title) if option: - show_app(option["app"]) + show_app(option["app"],c) else: return -def show_app(a): +def show_app(a,c): clear() with WaitingMessage(): app_info = store.get_app(a) @@ -74,7 +75,16 @@ def show_app(a): 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) + + def show_update(): clear() From 5c3188ac8b2cdc0d05b8e9a5e6bea0304be8aa5e Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Tue, 4 Sep 2018 19:25:50 +0100 Subject: [PATCH 03/13] Improve install menu dialogues. --- badge_store/main.py | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/badge_store/main.py b/badge_store/main.py index e950134..e1a8aaf 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -30,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"]) @@ -44,7 +44,7 @@ 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"],c) @@ -53,10 +53,17 @@ def show_apps(c): 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") + app_text = "App:\n" + try: + app_text += app_info["title"] + '\n' + except: + pass + finally: + app_text += a + '\n\nDescription:\n' + app_info["description"].strip() + install = prompt_boolean(app_text , title="Install App", true_text="Install", false_text="Back") if install: app_text = "App:\n" From e46aed13c2541ae4d3e604573da24f4745f9f4e1 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Tue, 4 Sep 2018 19:30:47 +0100 Subject: [PATCH 04/13] Category back to all cats. --- badge_store/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/badge_store/main.py b/badge_store/main.py index e1a8aaf..28cf469 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -49,7 +49,7 @@ def show_apps(c): if option: show_app(option["app"],c) else: - return + show_categories() def show_app(a,c): clear() From 15f63daf489887f279bb59a310df38cd41dba9fe Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Tue, 4 Sep 2018 20:10:02 +0100 Subject: [PATCH 05/13] Nicer update dialogs. --- badge_store/main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/badge_store/main.py b/badge_store/main.py index 28cf469..a4bfeca 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -95,16 +95,17 @@ def show_app(a,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: + 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() From 93897d240506104f5337ec149e8bec309a8124af Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Tue, 4 Sep 2018 21:27:30 +0100 Subject: [PATCH 06/13] Better remove app titles --- badge_store/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/badge_store/main.py b/badge_store/main.py index a4bfeca..2588cb3 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -109,11 +109,11 @@ def show_update(): 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") + notice("%s has been removed." % app_to_remove, title="Remove Success!", close_text="Back") def main_menu(): while True: From b33e075f5dbd685df8dc5e36581642704b50b47d Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Wed, 5 Sep 2018 00:38:49 +0100 Subject: [PATCH 07/13] Improve Remove App messages. --- badge_store/main.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/badge_store/main.py b/badge_store/main.py index 2588cb3..01ab64d 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -113,7 +113,12 @@ def show_remove(): if app_to_remove: ospath.recursive_rmdir(app_to_remove) app.uncache_apps() - notice("%s has been removed." % app_to_remove, title="Remove Success!", close_text="Back") + app_text = "App \"" + app_to_remove + "\"" + try: + app_text += " (" + app_info["title"] + ')' + except: + pass + notice("%s has been removed." % app_text, title="Remove Success!", close_text="Back") def main_menu(): while True: From 900c711ede7f5643adfee6e887fa5bd6f4395e09 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Wed, 5 Sep 2018 00:39:54 +0100 Subject: [PATCH 08/13] Fix alignments of dialogs. --- lib/dialogs.py | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/dialogs.py b/lib/dialogs.py index 86626b0..1d7be4e 100644 --- a/lib/dialogs.py +++ b/lib/dialogs.py @@ -41,8 +41,8 @@ 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 @@ -51,9 +51,9 @@ def prompt_boolean(text, title="TiLDA", true_text="Yes", false_text="No", font=F ugfx.set_default_font(font) label = ugfx.Label(5, 30, width - 10, height - 80, text = text, parent=window) 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 + try: #button_yes.attach_input(ugfx.BTN_A,0) # todo: re-enable once working #if button_no: button_no.attach_input(ugfx.BTN_B,0) @@ -166,10 +166,11 @@ def prompt_option(options, index=0, text = None, title=None, select_text="OK", n ugfx.set_default_font(FONT_SMALL) 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 +180,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() for option in options: @@ -195,7 +196,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: @@ -260,8 +261,8 @@ 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.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() - 10, ugfx.height() - 40, text = text, parent=self.window) # Indicator to show something is going on From 6683e2bc8d3e285e28c45df1ec13d904a95158e2 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Fri, 14 Sep 2018 23:26:48 +0100 Subject: [PATCH 09/13] Tidy up with .format() --- badge_store/main.py | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/badge_store/main.py b/badge_store/main.py index 01ab64d..48e85cb 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -56,24 +56,15 @@ def show_app(a,c): with WaitingMessage(title=title, text="Loading app description..."): app_info = store.get_app(a) - app_text = "App:\n" - try: - app_text += app_info["title"] + '\n' - except: - pass - finally: - app_text += a + '\n\nDescription:\n' + app_info["description"].strip() + + # 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: - app_text = "App:\n" - try: - app_text += app_info["title"] + '\n' - except: - pass - finally: - app_text += a + '\n\n' - + app_text = "App:\n{}\n\n".format(name) with WaitingMessage(title="Installing App...", text="%sGetting ready..." % app_text) as message: installers = store.install(_get_current_apps() + [a]) n = len(installers) @@ -113,12 +104,9 @@ def show_remove(): if app_to_remove: ospath.recursive_rmdir(app_to_remove) app.uncache_apps() - app_text = "App \"" + app_to_remove + "\"" - try: - app_text += " (" + app_info["title"] + ')' - except: - pass - notice("%s has been removed." % app_text, title="Remove Success!", 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: From 268ef625f23f10575f7503537cddc48426fcc05a Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 15 Sep 2018 15:52:59 +0100 Subject: [PATCH 10/13] Allow scrolling of labels by \n --- lib/dialogs.py | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/lib/dialogs.py b/lib/dialogs.py index c53c597..34eff86 100644 --- a/lib/dialogs.py +++ b/lib/dialogs.py @@ -49,11 +49,23 @@ def prompt_boolean(text, title="TiLDA", true_text="Yes", false_text="No", font=F 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 - 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 #if button_no: button_no.attach_input(ugfx.BTN_B,0) @@ -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() @@ -166,7 +188,7 @@ def prompt_option(options, index=0, text = None, title=None, select_text="OK", n ugfx.set_default_font(FONT_SMALL) window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10) window.show() - + list_y = 30 if title: From d5c64f4de76c7ad2b34acb2fa20f1dacbb9113d3 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 15 Sep 2018 15:59:37 +0100 Subject: [PATCH 11/13] Back from Install page to category --- badge_store/main.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/badge_store/main.py b/badge_store/main.py index fbf8d29..5708631 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -81,7 +81,8 @@ def show_app(a,c): app_obj.boot() else: show_apps(c) - + else: + show_apps(c) def show_update(): From 7316522b0eec8b2c5476f5d925efce6843d4c52d Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 15 Sep 2018 16:01:31 +0100 Subject: [PATCH 12/13] Give updating dialog a nice title --- badge_store/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/badge_store/main.py b/badge_store/main.py index 5708631..5c158c1 100644 --- a/badge_store/main.py +++ b/badge_store/main.py @@ -90,7 +90,7 @@ def show_update(): 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="Getting updates...") as message: + with WaitingMessage(title="Updating Apps...", text="Getting updates...") as message: update_text = "Downloading files:" installers = store.install(_get_current_apps()) n = len(installers) From 484f7c4063bb25edfc9fcd29ff23814eba15e1d3 Mon Sep 17 00:00:00 2001 From: Matthew Stratford Date: Sat, 15 Sep 2018 16:08:32 +0100 Subject: [PATCH 13/13] Fix right-alignment (clipping) on WaitingMessage --- lib/dialogs.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/dialogs.py b/lib/dialogs.py index 34eff86..9599aec 100644 --- a/lib/dialogs.py +++ b/lib/dialogs.py @@ -294,7 +294,7 @@ class WaitingMessage: self.window.show() 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() - 10, ugfx.height() - 40, text = text, parent=self.window) + 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)