def update(): clear() connect() with dialogs.WaitingMessage(text="Downloading full list of library files", title="TiLDA App Library") as message: message.text="Downloading full list of library files" master = http_client.get("http://api.badge.emfcamp.org/firmware/master-lib.json").raise_for_status().json() libs_to_update = [] for lib, expected_hash in master.items(): if expected_hash != filesystem.calculate_hash("lib/" + lib): libs_to_update.append({ "url": "http://api.badge.emfcamp.org/firmware/master/lib/" + lib, "target": "lib/" + lib, "expected_hash": expected_hash, "title": lib }) download_list(libs_to_update, message) apps = get_local_apps() for i, app in enumerate(apps): message.text = "Updating app %s" % app if app.fetch_api_information(): download_app(app, message) dialogs.notice("Everything is up-to-date")
def uninstall(): global options selected = options.selected_index() options.destroy() global currentListTitles global currentListTargets if currentListTargets[selected]["category"] == "system": #print("System apps can not be removed.") dialogs.notice("Can not uninstall '"+currentListTitles[selected]+"'!\nSystem apps can not be removed!","UNINSTALL") #easydraw.msg("System apps can not be removed!","Error",True) #time.sleep(2) #print("Returning to menu.") start() return def perform_uninstall(ok): global install_path if ok: easydraw.msg("Removing "+currentListTitles[selected]+"...", "Uninstalling...",True) install_path = "/lib" #FIXME for rm_file in os.listdir("%s/%s" % (install_path, currentListTargets[selected]["file"])): easydraw.msg("Deleting '"+rm_file+"'...") os.remove("%s/%s/%s" % (install_path, currentListTargets[selected]["file"], rm_file)) easydraw.msg("Deleting folder...") os.rmdir("%s/%s" % (install_path, currentListTargets[selected]["file"])) easydraw.msg("Uninstall completed!") start() uninstall = dialogs.prompt_boolean('Are you sure you want to remove %s?' % currentListTitles[selected], cb=perform_uninstall, title="UNINSTALL")
def update(): clear() connect() with dialogs.WaitingMessage(text="Downloading full list of library files", title="TiLDA App Library") as message: message.text="Downloading full list of library files" master = http_client.get("http://api.badge.emfcamp.org/firmware/master-lib.json").raise_for_status().json() libs_to_update = [] for lib, expected_hash in master.items(): if expected_hash != filesystem.calculate_hash("lib/" + lib): libs_to_update.append({ "url": "http://api.badge.emfcamp.org/firmware/master/lib/" + lib, "target": "lib/" + lib, "expected_hash": expected_hash, "title": lib }) download_list(libs_to_update, message) apps = get_local_apps() for i, app in enumerate(apps): message.text = "Updating app %s" % app if app.fetch_api_information(): download_app(app, message) dialogs.notice("Everything is up-to-date") main_menu()
def show_repeat(): dialogs.notice("Please repeat your personal lucky melody.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif") sleep.sleep_ms(3000) dialogs.notice("PLEASE REPEAT YOUR PERSONAL LUCKY MELODY.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif") sleep.sleep_ms(4000) dialogs.notice("Please repeat your personal lucky melody a bit louder.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif") sleep.sleep_ms(4000) dialogs.notice( "Unfortunately, this tone\nwas wrong. Please repeat\nyour personal lucky melody\nonce again.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "rec.gif") sleep.sleep_ms(6000) dialogs.notice( "This lucky melody will help you in every situation.\nMany thanks.", title=APP_TITLE) show_next_step()
def show_melody(): ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") sleep.sleep_ms(1000) dialogs.notice("You will now hear your personal lucky melody.", title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") play_melody() show_next_step()
def store_details(category, app): clear() empty_local_app_cache() with dialogs.WaitingMessage(text="Fetching app information...", title="TiLDA App Library"): app.fetch_api_information() clear() if dialogs.prompt_boolean(app.description, title = str(app), true_text = "Install", false_text="Back"): install(app) dialogs.notice("%s has been successfully installed" % app)
def loop_notice(text, image, is_numpad=False, interval=4000): next_tick = 0 while True: if time.ticks_ms() > next_tick: dialogs.notice(text, title=APP_TITLE) ugfx.display_image(0, 0, LOCAL_FOLDER % image) next_tick = time.ticks_ms() + interval if is_numpad: if is_pressed(Buttons.BTN_1) or is_pressed(Buttons.BTN_2) or is_pressed(Buttons.BTN_3) or is_pressed(Buttons.BTN_4) or is_pressed(Buttons.BTN_5) or is_pressed(Buttons.BTN_6) or is_pressed(Buttons.BTN_7) or is_pressed(Buttons.BTN_8) or is_pressed(Buttons.BTN_9): break else: if is_pressed(Buttons.BTN_A): break sleep.wfi()
def get_image_urls(answers): try: with dialogs.WaitingMessage("Sending data...", title=APP_TITLE): response = http.post(CARD_API_ENDPOINT, json={ "answers": answers }).raise_for_status() data = response.json() url = json.loads(data["body"])["url"] database.set(DB_KEY_CARD, url) database.set(DB_KEY_QR, QR_API_ENDPOINT % url) return True except Exception as ex: dialogs.notice(repr(ex), title="%s - Download failed" % APP_TITLE)
def show_card(): url = database.get(DB_KEY_CARD) if url: try: with dialogs.WaitingMessage("Loading data...", title=APP_TITLE): image = http.get(url).raise_for_status().content ugfx.display_image(0, 0, bytearray(image)) while ((not Buttons.is_pressed(Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu))): sleep.wfi() except Exception as ex: dialogs.notice(repr(ex), title="%s - Download failed" % APP_TITLE) else: dialogs.notice("Please answer the questions first", title=APP_TITLE) show_menu()
def show_share(): ugfx.clear(APP_COLOUR) url = database.get(DB_KEY_QR) if url: dialogs.notice( "Scan the QR code with your phone and share your emoji card online.", title=APP_TITLE) try: with dialogs.WaitingMessage("Loading data...", title=APP_TITLE): image = http.get(url).raise_for_status().content ugfx.clear(APP_COLOUR) ugfx.display_image(5, 45, bytearray(image)) while (not is_pressed(Buttons.BTN_B)) and (not is_pressed( Buttons.BTN_Menu)): sleep.wfi() except Exception as ex: dialogs.notice(repr(ex), title="%s - Download failed" % APP_TITLE) else: dialogs.notice("Please answer the questions first", title=APP_TITLE) show_menu()
def quick_launch_screen(): wi = ugfx.width() hi = ugfx.height() win_header = ugfx.Container(0,0,wi,30) win_quick = ugfx.Container(0,33,wi,hi-33-33) win_help = ugfx.Container(0,hi-30,wi,30) DEFAULT_APPS = ["app_library", "sponsors", "changename"] with Database() as db: pinned = [App(a) for a in db.get("pinned_apps", DEFAULT_APPS)] pinned = [app for app in pinned if app.loadable] # Filter out deleted apps pinned = pinned[:7] # Limit to 7 db.set("pinned_apps", [app.folder_name for app in pinned]) ugfx.set_default_font(ugfx.FONT_TITLE) title = ugfx.Label(3,3,wi-10,45,"EMF Camp 2016",parent=win_header) ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) pinned_buttons = [] for i in range(0, 8): x = i % 2 y = i // 2 button_title = "View all" if i == 7 else "" if i < len(pinned): button_title = pinned[i].title pinned_buttons.append(ugfx.Button(35 + 155 * x, 5 + 40 * y, 120, 35, button_title, parent=win_quick)) btn_ok = ugfx.Button(10,5,20,20,"A",parent=win_help,shape=ugfx.Button.ELLIPSE) l_ok = ugfx.Label(40,5,100,20,"Run",parent=win_help) btn_back = ugfx.Button(100,5,20,20,"B",parent=win_help,shape=ugfx.Button.ELLIPSE) l_back = ugfx.Label(130,5,100,20,"Back",parent=win_help) btn_menu = ugfx.Button(200,5,20,20,"M",parent=win_help,shape=ugfx.Button.ROUNDED) l_back = ugfx.Label(230,5,100,20,"Menu",parent=win_help) sty = dialogs.default_style_badge win_header.show() win_quick.show() win_help.show() buttons.init() cursor = {"x": 0, "y": 0} last_cursor = cursor.copy() _draw_cursor(0, 0, ugfx.RED, win_quick) app_to_load = "sponsors" if not database_get("quicklaunch_firstrun"): dialogs.notice("""This screen displays the most commonly used apps. Apps pinned here can also interact with the name screen. To view all apps, pin and un-pin, select 'View All' """, title="TiLDA - Quick Launch", close_text="Close") database_set("quicklaunch_firstrun", True) try: while True: pyb.wfi() if buttons.is_triggered("JOY_UP"): cursor["y"] = max(0, cursor["y"] - 1) if buttons.is_triggered("JOY_DOWN"): cursor["y"] = min(3, cursor["y"] + 1) if buttons.is_triggered("JOY_RIGHT"): cursor["x"] = 1 if buttons.is_triggered("JOY_LEFT"): cursor["x"] = 0 if cursor["x"] != last_cursor["x"] or cursor["y"] != last_cursor["y"]: # Has the cursor moved? _draw_cursor(last_cursor["x"], last_cursor["y"], dialogs.default_style_badge.background(), win_quick) _draw_cursor(cursor["x"], cursor["y"], ugfx.RED, win_quick) last_cursor = cursor.copy() if buttons.is_triggered("BTN_B"): return None #if buttons.is_triggered("BTN_MENU"): # open unpin dialog # break; if buttons.is_triggered("BTN_A"): index = cursor["x"] + cursor["y"] * 2 if index == 7: return "file_loader" if index < len(pinned): return pinned[index] finally: buttons.disable_all_interrupt() win_header.hide() win_quick.hide() win_help.hide() for b in pinned_buttons: b.destroy() btn_ok.destroy() l_ok.destroy() btn_back.destroy() l_back.destroy() btn_menu.destroy() l_back.destroy() win_header.destroy() win_quick.destroy() win_help.destroy() title.destroy()
def display_notice(text): dialogs.notice(text, style=dialogs.default_style_badge)
ugfx.box(colourI * boxWidth, maxHeight + ((colourJ - scroll) * boxHeight), boxWidth, boxHeight, (int(31 * r) << 11) + (int(63 * g) << 5) + int(31 * b)) return (int(31 * r) << 11) + (int(63 * g) << 5) + int(31 * b) ugfx_helper.init() maxHeight = int(ugfx.height() * 0.9) i = 0 j = 0 ugfx.clear() dialogs.notice( "Draw with joystick arrows\nHold joystick centre for circle\nA to clear\nMENU to choose colour\nB to exit", title="Sketchy-Etch") ugfx.area(0, 0, ugfx.width(), maxHeight, ugfx.BLACK) showColourChangeMenu() circleSize = 3 reset() colour = ugfx.WHITE while not Buttons.is_pressed(Buttons.BTN_B): changed = False oldI = i oldJ = j if Buttons.is_pressed(Buttons.JOY_Right) and (i < (ugfx.width() - 1)): i += 1
def quick_launch_screen(): wi = ugfx.width() hi = ugfx.height() win_header = ugfx.Container(0,0,wi,30) win_quick = ugfx.Container(0,33,wi,hi-33-33) win_help = ugfx.Container(0,hi-30,wi,30) DEFAULT_APPS = ["app_library", "changename", "alistair~selectwifi", "snake"] with Database() as db: pinned = [App(a) for a in db.get("pinned_apps", DEFAULT_APPS)] pinned = [app for app in pinned if app.loadable] # Filter out deleted apps pinned = pinned[:7] # Limit to 7 db.set("pinned_apps", [app.folder_name for app in pinned]) ugfx.set_default_font(ugfx.FONT_TITLE) title = ugfx.Label(3,3,wi-10,45,"EMF Camp 2016",parent=win_header) ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD) pinned_buttons = [] for i in range(0, 8): x = i % 2 y = i // 2 button_title = "Installed Apps" if i == 7 else "" if i < len(pinned): button_title = pinned[i].title pinned_buttons.append(ugfx.Button(35 + 155 * x, 5 + 40 * y, 120, 35, button_title, parent=win_quick)) btn_ok = ugfx.Button(10,5,20,20,"A",parent=win_help,shape=ugfx.Button.ELLIPSE) l_ok = ugfx.Label(40,5,100,20,"Run",parent=win_help) btn_back = ugfx.Button(100,5,20,20,"B",parent=win_help,shape=ugfx.Button.ELLIPSE) l_back = ugfx.Label(130,5,100,20,"Back",parent=win_help) btn_menu = ugfx.Button(200,5,20,20,"M",parent=win_help,shape=ugfx.Button.ROUNDED) l_menu = ugfx.Label(230,5,100,20,"Menu",parent=win_help) win_header.show() win_quick.show() win_help.show() buttons.init() cursor = {"x": 0, "y": 0} last_cursor = cursor.copy() _draw_cursor(0, 0, ugfx.RED, win_quick) if not database_get("quicklaunch_firstrun"): dialogs.notice("""This screen displays the most commonly used apps. Apps pinned here can also interact with the name screen. To view all apps, pin and un-pin, select 'Installed Apps' """, title="TiLDA - Quick Launch", close_text="Close") database_set("quicklaunch_firstrun", True) try: while True: pyb.wfi() if buttons.is_triggered("JOY_UP"): cursor["y"] = max(0, cursor["y"] - 1) if buttons.is_triggered("JOY_DOWN"): cursor["y"] = min(3, cursor["y"] + 1) if buttons.is_triggered("JOY_RIGHT"): cursor["x"] = 1 if buttons.is_triggered("JOY_LEFT"): cursor["x"] = 0 if cursor["x"] != last_cursor["x"] or cursor["y"] != last_cursor["y"]: # Has the cursor moved? _draw_cursor(last_cursor["x"], last_cursor["y"], dialogs.default_style_badge.background(), win_quick) _draw_cursor(cursor["x"], cursor["y"], ugfx.RED, win_quick) last_cursor = cursor.copy() if buttons.is_triggered("BTN_B"): return None #if buttons.is_triggered("BTN_MENU"): # open unpin dialog # break; if buttons.is_triggered("BTN_A"): index = cursor["x"] + cursor["y"] * 2 if index == 7: return "file_loader" if index < len(pinned): return pinned[index] finally: buttons.disable_all_interrupt() win_header.hide() win_quick.hide() win_help.hide() for b in pinned_buttons: b.destroy() btn_ok.destroy() l_ok.destroy() btn_back.destroy() l_back.destroy() btn_menu.destroy() l_menu.destroy() win_header.destroy() win_quick.destroy() win_help.destroy() title.destroy()
def dialog(message): notice(message, title=DIALOG_TITLE) drawui()
def display_error(message): dialogs.notice(message, title='Error')