Merge pull request #132 from mstratford/mstratford-dialogs
Badge Store UI/UX improvements & dialog alignmentsmaster
commit
47958ff566
|
@ -13,6 +13,7 @@ ___bootstrapped___ = True
|
||||||
import ugfx_helper, os, database, wifi, app, ospath
|
import ugfx_helper, os, database, wifi, app, ospath
|
||||||
from dialogs import *
|
from dialogs import *
|
||||||
from lib.badge_store import BadgeStore
|
from lib.badge_store import BadgeStore
|
||||||
|
from app import *
|
||||||
|
|
||||||
### VIEWS ###
|
### VIEWS ###
|
||||||
|
|
||||||
|
@ -29,10 +30,10 @@ def clear():
|
||||||
|
|
||||||
def show_categories():
|
def show_categories():
|
||||||
clear()
|
clear()
|
||||||
with WaitingMessage():
|
with WaitingMessage(title=title, text="Loading categories..."):
|
||||||
menu_items = [{"title": c, "category": c} for c in store.get_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:
|
if option:
|
||||||
show_apps(option["category"])
|
show_apps(option["category"])
|
||||||
|
@ -43,51 +44,70 @@ def show_apps(c):
|
||||||
clear()
|
clear()
|
||||||
menu_items = [{"title": a, "app": a} for a in store.get_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)
|
option = prompt_option(menu_items, none_text="Back", title="Install: " + c)
|
||||||
|
|
||||||
if option:
|
if option:
|
||||||
show_app(option["app"])
|
show_app(option["app"],c)
|
||||||
else:
|
else:
|
||||||
return
|
show_categories()
|
||||||
|
|
||||||
def show_app(a):
|
def show_app(a,c):
|
||||||
clear()
|
clear()
|
||||||
with WaitingMessage():
|
with WaitingMessage(title=title, text="Loading app description..."):
|
||||||
app_info = store.get_app(a)
|
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:
|
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])
|
installers = store.install([a])
|
||||||
n = len(installers)
|
n = len(installers)
|
||||||
for i, installer in enumerate(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()
|
installer.download()
|
||||||
app.uncache_apps()
|
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():
|
def show_update():
|
||||||
clear()
|
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:
|
if update:
|
||||||
clear()
|
clear()
|
||||||
with WaitingMessage(title=title, text="Please wait...") as message:
|
with WaitingMessage(title=title, text="Getting updates...") as message:
|
||||||
installers = store.update(_get_current_apps())
|
update_text = "Downloading files:"
|
||||||
|
installers = store.install(_get_current_apps())
|
||||||
n = len(installers)
|
n = len(installers)
|
||||||
for i, installer in enumerate(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()
|
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():
|
def show_remove():
|
||||||
clear()
|
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:
|
if app_to_remove:
|
||||||
ospath.recursive_rmdir(app_to_remove)
|
ospath.recursive_rmdir(app_to_remove)
|
||||||
app.uncache_apps()
|
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():
|
def main_menu():
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -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 = ugfx.Container(5, 5, width, height)
|
||||||
window.show()
|
window.show()
|
||||||
ugfx.set_default_font(font)
|
ugfx.set_default_font(font)
|
||||||
window.text(5, 10, title, TILDA_COLOR)
|
window.text(5, 5, title, TILDA_COLOR)
|
||||||
window.line(0, 30, width, 30, ugfx.BLACK)
|
window.line(0, 25, width, 25, ugfx.BLACK)
|
||||||
|
|
||||||
if false_text:
|
if false_text:
|
||||||
true_text = "A: " + true_text
|
true_text = "A: " + true_text
|
||||||
false_text = "B: " + false_text
|
false_text = "B: " + false_text
|
||||||
|
|
||||||
ugfx.set_default_font(font)
|
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)
|
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_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 + 5, height - 40, width // 2 - 15, 30 , false_text, parent=window) if false_text else None
|
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:
|
try:
|
||||||
#button_yes.attach_input(ugfx.BTN_A,0) # todo: re-enable once working
|
#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()
|
sleep.wfi()
|
||||||
if buttons.is_triggered(buttons.Buttons.BTN_A): return True
|
if buttons.is_triggered(buttons.Buttons.BTN_A): return True
|
||||||
if buttons.is_triggered(buttons.Buttons.BTN_B): return False
|
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:
|
finally:
|
||||||
window.hide()
|
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 = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
|
||||||
window.show()
|
window.show()
|
||||||
|
|
||||||
|
|
||||||
list_y = 30
|
list_y = 30
|
||||||
if title:
|
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)
|
window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK)
|
||||||
list_y = 30
|
list_y = 30
|
||||||
if text:
|
if text:
|
||||||
|
@ -179,7 +202,7 @@ def prompt_option(options, index=0, text = None, title=None, select_text="OK", n
|
||||||
else:
|
else:
|
||||||
window.text(5, 10, text, ugfx.BLACK)
|
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()
|
options_list.disable_draw()
|
||||||
|
|
||||||
optnum = 1
|
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
|
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_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:
|
try:
|
||||||
while True:
|
while True:
|
||||||
|
@ -269,9 +292,9 @@ class WaitingMessage:
|
||||||
def __init__(self, text="Please Wait...", title="TiLDA"):
|
def __init__(self, text="Please Wait...", title="TiLDA"):
|
||||||
self.window = ugfx.Container(30, 30, ugfx.width() - 60, ugfx.height() - 60)
|
self.window = ugfx.Container(30, 30, ugfx.width() - 60, ugfx.height() - 60)
|
||||||
self.window.show()
|
self.window.show()
|
||||||
self.window.text(5, 10, title, TILDA_COLOR)
|
self.window.text(5, 5, title, TILDA_COLOR)
|
||||||
self.window.line(0, 30, ugfx.width() - 60, 30, ugfx.BLACK)
|
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
|
# Indicator to show something is going on
|
||||||
#self.indicator = ugfx.Label(ugfx.width() - 100, 0, 20, 20, text = "...", parent=self.window)
|
#self.indicator = ugfx.Label(ugfx.width() - 100, 0, 20, 20, text = "...", parent=self.window)
|
||||||
|
|
Loading…
Reference in New Issue