def main(): ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, action_exit) show_names() sys.stdin.read(1) #Wait for any key action_exit(True)
def __init__(self): self.window = None self.widgets = [] ugfx.input_init() ugfx.set_default_font(self.default_font) ugfx.input_attach(ugfx.BTN_B, self.reload)
def main(): strobonator = Strobonator() ugfx.input_attach(ugfx.BTN_START, strobonator.press_start) ugfx.input_attach(ugfx.JOY_UP, strobonator.press_up) ugfx.input_attach(ugfx.JOY_DOWN, strobonator.press_down) ugfx.input_attach(ugfx.JOY_LEFT, strobonator.press_left) ugfx.input_attach(ugfx.JOY_RIGHT, strobonator.press_right)
def show_shift_detail(): global shifts global shift_list shift_list.visible(False) ugfx.clear(ugfx.WHITE) ugfx.flush() i = shift_list.selected_index() title = shifts[i]["name"] title_height = 20 if ugfx.get_string_width( title, "PermanentMarker22") <= ugfx.width() else 60 title = ugfx.string_box(0, 0, ugfx.width(), title_height, title, "PermanentMarker22", ugfx.BLACK, ugfx.justifyCenter) location = ugfx.string(0, title_height + 5, "Location: " + shifts[i]["Name"], "Roboto_Regular18", ugfx.BLACK) description = ugfx.string_box(0, title_height + 25, ugfx.width(), 40, "Description: " + shifts[i]["title"], "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) time = ugfx.string( 0, ugfx.height() - 20, "Time: " + generate_timedelta_text( int(shifts[i]["start"]), int(shifts[i]["end"])), "Roboto_Regular18", ugfx.BLACK) ugfx.flush() ugfx.input_attach(ugfx.BTN_B, lambda pressed: show_shift_list() if pressed else None)
def __init__(self, parent): super().__init__() self.parent = parent self.views = {} self.current_view = None self.previous_view = None # Initialize Input ugfx.input_init() # A/B Button Handler ugfx.input_attach(ugfx.BTN_A, self.select_a_cb) ugfx.input_attach(ugfx.BTN_B, self.select_b_cb) # Title self.set_title('RPS Game') # Message Box self.message_box = ugfx.Label(0, self.container.height() - 88, self.container.width(), 88, '', parent=self.container, style=styles.wb, justification=ugfx.Label.LEFT) # Status box self.create_status_box() # Message Popup self.message_popup_view = MessagePopupView(manager=self)
def splash_main(): # Battery status cstate = badge.battery_charge_status() vbatt = badge.battery_volt_sense() percent = battery_percent(3800, 4300, vbatt) # Init graphics and show homescreen ugfx.init() # Depending on battery status... if (cstate) or (percent > 9): draw_home(percent, cstate, "Press START!") # Accept input ugfx.input_init() ugfx.input_attach(ugfx.BTN_START, start_launcher) # Start timer global splashTimer splashTimer.init(period=5000, mode=Timer.PERIODIC, callback=splashTimer_callback) else: draw_batterylow(percent) gotosleep()
def main(): #ugfx.init() ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, action_exit) ugfx.input_attach(ugfx.BTN_START, action_exit) fill_screen_with_crap(ugfx.BLACK) show_names()
def attach_input(self): ugfx.input_attach(self.next_key, self.next) ugfx.input_attach(self.prev_key, self.prev) if len(self.pages) > 1: ugfx.input_attach(self.next_page_key, self.next_page) ugfx.input_attach(self.prev_page_key, self.prev_page) ugfx.input_attach(ugfx.BTN_A, self.select)
def list_categories(): global options global text global categories try: categories except: ugfx.input_init() draw_msg('Getting categories') try: f = urequests.get("https://badge.team/eggs/categories/json", timeout=30) categories = f.json() except: draw_msg('Failed!') draw_msg('Returning to launcher :(') appglue.start_app('launcher', False) f.close() draw_msg('Done!') options = ugfx.List(0, 0, int(ugfx.width() / 2), ugfx.height()) text = ugfx.Textbox(int(ugfx.width() / 2), 0, int(ugfx.width() / 2), ugfx.height()) ugfx.input_attach(ugfx.JOY_UP, lambda pushed: ugfx.flush() if pushed else False) ugfx.input_attach(ugfx.JOY_DOWN, lambda pushed: ugfx.flush() if pushed else False) ugfx.input_attach(ugfx.BTN_A, select_category) ugfx.input_attach( ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else False) ugfx.input_attach( ugfx.BTN_START, lambda pushed: appglue.start_app("") if pushed else False) ugfx.clear(ugfx.WHITE) ugfx.flush() while options.count() > 0: options.remove_item(0) for category in categories: options.add_item("%s (%d) >" % (category["name"], category["eggs"])) options.selected_index(0) text.text("Install or update eggs from the hatchery here\n\n\n\n") ugfx.string_box(148, 0, 148, 26, "Hatchery", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.line(148, 78, 296, 78, ugfx.BLACK) ugfx.string_box(148, 78, 148, 18, " A: Open category", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.string_box(148, 92, 148, 18, " B: Return to home", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.line(148, 110, 296, 110, ugfx.BLACK) ugfx.string_box(148, 110, 148, 18, " badge.team", "Roboto_Regular12", ugfx.BLACK, ugfx.justifyLeft) ugfx.flush(ugfx.LUT_FULL) gc.collect()
def program_main(): ugfx.init() ugfx.clear(ugfx.WHITE) badge.leds_init() try: badge.eink_png(0, 0, logo_path) except: log('+ Failed to load graphics') # Name tag ugfx.string(ugfx.width() - ugfx.get_string_width(name, fonts[1]), ugfx.height() - 36, name, fonts[1], ugfx.BLACK) # Button info ugfx.string(0, ugfx.height() - 13, '[FLASH to update] [B to exit]', fonts[2], ugfx.BLACK) ugfx.flush() ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, lambda pressed: exit_app()) ugfx.input_attach(ugfx.BTN_FLASH, lambda pressed: start_self_update()) HOST = "chat.freenode.net" PORT = 6667 NICK = name + "[luv]" REALNAME = name + ' @ SHA2017' log('+ waiting for network...') wifi.init() while not wifi.sta_if.isconnected(): time.sleep(0.1) s = socket.socket() s.connect((HOST, PORT)) s.send(bytes("NICK %s\r\n" % NICK, "UTF-8")) s.send(bytes("USER %s 0 * :%s\r\n" % (NICK, REALNAME), "UTF-8")) s.send(bytes("JOIN #sha2017\r\n", "UTF-8")) # IRC Client while True: line = s.readline().rstrip() parts = line.split() if parts: if (parts[0] == b"PING"): s.send(bytes("PONG %s\r\n" % line[1], "UTF-8")) blink_led(green) if (parts[1] == b"PRIVMSG"): blink_led(red) msg = b' '.join(parts[3:]) rnick = line.split(b'!')[0] log(b'%s: %s' % (rnick, msg))
def network_selected(self, pressed): if not pressed: return scan_config = self.scan_configs[self.scan_list.selected_index()] self.saved_config = scan_config ugfx.input_attach(ugfx.BTN_A, None) self.scan_list.destroy() if scan_config[4] == 0: self.connect_network(scan_config[0].decode('utf-8')) else: self.get_password()
def app_main(): ugfx.init() clear() ugfx.set_lut(ugfx.LUT_FASTEST) badge.vibrator_init() ugfx.input_attach(ugfx.BTN_A, lambda pressed: badge.vibrator_activate(0xd)) ugfx.input_attach(ugfx.BTN_START, lambda pressed: appglue.home()) loop()
def Status(self, data=None): self.destroy() self.create_window() w = self.window y = 10 gap = 5 height = 35 ugfx.Label(10, y, w.width() - 20, height, 'Platform: {}'.format(util.get_version()), parent=w) y += gap + height ugfx.Label(10, y, w.width() - 20, height, 'Release: {}'.format(uos.uname()[2]), parent=w) y += gap + height ugfx.Label(10, y, w.width() - 20, height, 'firmware:', parent=w) ugfx.set_default_font('IBMPlexMono_Bold18') y += height ugfx.Label(10, y, w.width() - 20, height + 10, '{}'.format(uos.uname()[3]), parent=w) ugfx.set_default_font(self.default_font) ugfx.set_default_font('IBMPlexSans_Regular18') self.create_status_box() ugfx.set_default_font(self.default_font) ugfx.input_attach(ugfx.BTN_A, self.__close_status_box) try: ota_data = ota.check_version() except ota.OtaException as e: self.set_status('Error: {}'.format(e)) else: if ota_data: self.status_box.destroy() ugfx.Label(10, 180, 200, 40, text='New: {}'.format(ota_data['version']), parent=w) self.btngroup = ButtonGroup(self.window, 190, 180, 110, 40, 10) self.btngroup.add('Upgrade', self.install_ota, ota_data) self.btngroup.end() else: self.set_status('Up to date')
def write_lock(): global ransom_id badge.nvs_set_str('boot', 'splash', 'ascii_porn') #Now you are the homescreen :P ugfx.clear(ugfx.WHITE) ugfx.string(15, 10, "SHA2017 - Ransomware", "Roboto_BlackItalic24", ugfx.BLACK) write(40, "Oh noes, your badge is being held hostage!") write(52, "Deliver a club mate to the Snowden field.") write(64, "We're in the first big tent to the left.") write(76, "Be sure to show us this ID: " + ransom_id) ugfx.input_attach(ugfx.BTN_START, attempt_unlock) ugfx.string(20, 100, "[PRESS START TO UNLOCK]", "Roboto_Regular18", ugfx.BLACK) ugfx.flush()
def main_loop(self): ugfx.input_attach(ugfx.JOY_LEFT, self.take) ugfx.input_attach(ugfx.JOY_RIGHT, self.add) ugfx.input_attach(ugfx.BTN_START, self.exit) ugfx.input_attach(ugfx.BTN_A, self.exit) ugfx.input_attach(ugfx.BTN_B, self.exit) while True: self.x += SPEED*cos(self.r) self.y += SPEED*sin(self.r) self.x,self.y,self.r = self.wrapper.wrap(self.x,self.y,self.r) self.draw_ship() time.sleep(FRAMERATE)
def get_input(self, label, callback): ugfx.input_attach(ugfx.BTN_B, util.reboot) w = self.create_window() edit_size = 40 ugfx.Textbox(5, 0, w.width() - 12, edit_size, text=label, parent=w).enabled(False) self.kb_input = ugfx.Textbox(5, 7 + edit_size, w.width() - 12, edit_size, parent=w) self.kb = ugfx.Keyboard(5, edit_size * 2 + 12, w.width() - 12, w.height() - edit_size * 2 - 20, parent=w) self.kb_callback = callback self.kb.set_keyboard_callback(self.kb_handler)
def list_network(self): w = self.create_window() self.scan() self.scan_list = ugfx.List(10, 10, w.width() - 20, w.height() - 20, parent=w) self.scan_list.visible(False) for scan_config in self.scan_configs: ap_name = '{} {}'.format('@' if scan_config[4] else ' ', scan_config[0].decode('utf-8')) self.scan_list.add_item(ap_name) print(scan_config) self.scan_list.visible(True) ugfx.input_attach(ugfx.BTN_A, self.network_selected) ugfx.input_attach(ugfx.BTN_B, util.reboot)
def run_game(): badge.eink_init() ugfx.init() ugfx.clear(ugfx.WHITE) ugfx.flush() badge.init() ugfx.clear(ugfx.WHITE) ugfx.input_init() ugfx.input_attach(ugfx.JOY_UP, lambda pressed: up(pressed, this_game)) ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: down(pressed, this_game)) ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: left(pressed, this_game)) ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: right(pressed, this_game)) ugfx.input_attach(ugfx.BTN_SELECT, lambda pressed: exit_game(pressed, this_game)) ugfx.string(50, 50, "Snake Game", "PermanentMarker22", ugfx.BLACK) ugfx.string(50, 72, "press SELECT to exit", "Roboto_Regular18", ugfx.BLACK) ugfx.flush() time.sleep(5) ugfx.clear(ugfx.WHITE) ugfx.flush() snake = Snake(True, Renderer()) this_game = Game(snake, Border(), [Food.create_random_food(snake)]) ugfx.flush() print("Start Log") while True: if (this_game.game_state == "FAIL"): FailGame(this_game) Step(this_game, 5)
def install_app(pressed=True): global category if pressed: slug = category[myList.selected_index()]["slug"] #Input handling ugfx.input_attach(ugfx.BTN_A, btn_unhandled) ugfx.input_attach(ugfx.BTN_B, btn_unhandled) ugfx.input_attach(ugfx.BTN_C, btn_unhandled) ugfx.input_attach(ugfx.BTN_BOOT, btn_unhandled) category = [] myList.clear() showMessage("Installing " + slug + "...") with open("/cache/installList", "w") as f: f.write(slug) system.start("dashboard._installer_exec")
def main(): print("> Main") global api_key ugfx.init() ugfx.input_init() ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.input_attach(ugfx.BTN_B, appglue.home) ugfx.input_attach(ugfx.BTN_SELECT, prompt_api_key) wifi.init() while not wifi.sta_if.isconnected(): time.sleep(0.1) pass api_key = badge.nvs_get_str("engel", "key", "") if not api_key: prompt_api_key() show_shift_list()
def list_apps(self): self.create_status_box() self.set_status('Waiting for network') if not util.wait_network(): self.set_status('Cannot connect WiFi') raise Exception('Cannot connect WiFi') self.set_status('Downloading app list') apps = ota.download_json(self.LIST_URL) self.close_status_box() w = self.window ugfx.set_default_font('IBMPlexSans_Regular18') self.app_list = ugfx.List(5, 50, 150, w.height() - 60, parent = w) self.app_list.visible(False) self.apps = [] for slug, app in apps.items(): app['installed'] = False app['slug'] = slug app['upgrade'] = False app['ver_string'] = '{}'.format(app['version']) try: with open('/apps/{}/app.json'.format(slug)) as fp: data = json.load(fp) app['installed'] = data['version'] if app['version'] != app['installed']: app['upgrade'] = True app['ver_string'] = '{} -> {}'.format( app['installed'], app['version']) except Exception as e: print(e) self.apps.append(app) self.app_list.add_item(app['name'] if 'name' in app else slug) self.app_list.visible(True) #ugfx.input_attach(ugfx.BTN_A, self.network_selected) ugfx.input_attach(ugfx.BTN_B, util.reboot) self.widgets.append(self.app_list)
def list_categories(): global options global categories try: categories except: ugfx.input_init() easydraw.msg('Getting categories', "Loading...", True) try: f = urequests.get("https://badge.disobey.fi/eggs/categories/json", timeout=30) categories = f.json() except: easydraw.msg('Failed :(') appglue.start_app('launcher', False) f.close() easydraw.msg('Success :)') options = ugfx.List(0, 0, int(ugfx.width()), ugfx.height()) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, select_category) ugfx.input_attach( ugfx.BTN_B, lambda pushed: appglue.start_app("launcher", False) if pushed else False) ugfx.clear(ugfx.WHITE) ugfx.flush() while options.count() > 0: options.remove_item(0) for category in categories: options.add_item("%s (%d) >" % (category["name"], category["eggs"])) options.selected_index(0) ugfx.flush(ugfx.LUT_FULL) gc.collect()
def done(result): ugfx.input_attach(ugfx.JOY_LEFT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_RIGHT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_B, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, dummy_button_cb) if cb: cb(result) return result
def prompt_boolean(text, title=version.dialog_title, true_text="Yes", false_text="No", width=ugfx.width(), height=ugfx.height(), font="Roboto_Regular12", cb=None): global wait_for_interrupt, button_pushed easydraw.msg(text, title, True) easydraw.msg_nosplit("[" + false_text + "/" + true_text + "]") def done(result): ugfx.input_attach(ugfx.JOY_LEFT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_RIGHT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_B, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, dummy_button_cb) if cb: cb(result) return result def syncSuccess(evt): if evt: # We'd like promises here, but for now this should do global wait_for_interrupt, button_pushed button_pushed = "A" wait_for_interrupt = False def syncCancel(evt): if evt: # We'd like promises here, but for now this should do global wait_for_interrupt, button_pushed button_pushed = "B" wait_for_interrupt = False def asyncSuccess(evt): if evt: done(True) def asyncCancel(evt): if evt: done(False) ugfx.input_init() ugfx.set_lut(ugfx.LUT_NORMAL) ugfx.flush() ugfx.input_attach(ugfx.JOY_LEFT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_RIGHT, dummy_button_cb) ugfx.input_attach(ugfx.JOY_UP, dummy_button_cb) ugfx.input_attach(ugfx.JOY_DOWN, dummy_button_cb) ugfx.input_attach(ugfx.BTN_B, dummy_button_cb) ugfx.input_attach(ugfx.BTN_START, dummy_button_cb) if false_text != None: ugfx.input_attach(version.btn_cancel, asyncCancel if cb else syncCancel) ugfx.input_attach(version.btn_ok, asyncSuccess if cb else syncSuccess) if cb: return else: wait_for_interrupt = True while wait_for_interrupt: time.sleep(0.2) if button_pushed == "B": return done(False) return done(True)
def toggle_focus(pressed): if pressed: if focus == 0: edit.set_focus() kb.enabled(1) ugfx.input_attach( version.btn_cancel, lambda pressed: vkey_backspace() if pressed else 0) ugfx.input_attach( version.btn_ok, lambda pressed: 0 if pressed else ugfx.flush()) focus = 1 elif focus == 1 or not button_no: button_yes.set_focus() kb.enabled(0) ugfx.input_attach(version.btn_ok, asyncSuccess if cb else syncSuccess) ugfx.input_attach(version.btn_cancel, asyncCancel if cb else syncCancel) focus = (2 if button_no else 0) else: button_no.set_focus() kb.enabled(0) ugfx.input_attach(version.btn_ok, asyncCancel if cb else syncCancel) ugfx.input_attach(version.btn_cancel, asyncCancel if cb else syncCancel) focus = 0 ugfx.flush()
def prompt_text(description, init_text="", true_text="OK", false_text="Back", width=ugfx.width(), height=ugfx.height(), font="Roboto_BlackItalic24", cb=None): """Shows a dialog and keyboard that allows the user to input/change a string Calls the 'cb' callback or return None if user aborts with button B. Using a callback is highly recommended as it's not possible to process events inside an event callback. The caller is responsible for flushing the display after processing the response. """ global wait_for_interrupt, button_pushed window = ugfx.Container(int((ugfx.width() - width) / 2), int((ugfx.height() - height) / 2), width, height) window.show() ugfx.set_default_font("Roboto_Regular12") kb_height = int(height / 2) + 30 kb = ugfx.Keyboard(0, height - kb_height, width, kb_height, parent=window) ugfx.set_default_font("Roboto_Regular18") edit_height = 25 edit = ugfx.Textbox(5, height - kb_height - 5 - edit_height, int(width * 4 / 5) - 10, edit_height, text=init_text, parent=window) ugfx.set_default_font("Roboto_Regular12") button_height = 25 def done(result): window.destroy() if cb: cb(result) return result def syncSuccess(evt): if evt: # We'd like promises here, but for now this should do global wait_for_interrupt, button_pushed button_pushed = "A" wait_for_interrupt = False def syncCancel(evt): if evt: # We'd like promises here, but for now this should do global wait_for_interrupt, button_pushed button_pushed = "B" wait_for_interrupt = False def asyncSuccess(evt): if evt: done(edit.text()) def asyncCancel(evt): if evt: done(None) button_yes = ugfx.Button(int(width * 4 / 5), height - kb_height - button_height, int(width * 1 / 5) - 3, button_height, true_text, parent=window, cb=asyncSuccess if cb else syncSuccess) button_no = ugfx.Button(int(width * 4 / 5), height - kb_height - button_height - button_height, int(width / 5) - 3, button_height, false_text, parent=window) if false_text else None ugfx.set_default_font(font) label = ugfx.Label(5, 1, int(width * 4 / 5), height - kb_height - 5 - edit_height - 5, description, parent=window) def vkey_backspace(): edit.backspace() ugfx.flush() focus = 0 def toggle_focus(pressed): if pressed: if focus == 0: edit.set_focus() kb.enabled(1) ugfx.input_attach( version.btn_cancel, lambda pressed: vkey_backspace() if pressed else 0) ugfx.input_attach( version.btn_ok, lambda pressed: 0 if pressed else ugfx.flush()) focus = 1 elif focus == 1 or not button_no: button_yes.set_focus() kb.enabled(0) ugfx.input_attach(version.btn_ok, asyncSuccess if cb else syncSuccess) ugfx.input_attach(version.btn_cancel, asyncCancel if cb else syncCancel) focus = (2 if button_no else 0) else: button_no.set_focus() kb.enabled(0) ugfx.input_attach(version.btn_ok, asyncCancel if cb else syncCancel) ugfx.input_attach(version.btn_cancel, asyncCancel if cb else syncCancel) focus = 0 ugfx.flush() ugfx.input_init() ugfx.input_attach(ugfx.BTN_SELECT, toggle_focus) ugfx.input_attach(ugfx.JOY_LEFT, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_RIGHT, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_UP, lambda pressed: ugfx.flush() if pressed else 0) ugfx.input_attach(ugfx.JOY_DOWN, lambda pressed: ugfx.flush() if pressed else 0) toggle_focus(True) ugfx.set_lut(ugfx.LUT_NORMAL) ugfx.flush() wait_for_interrupt = True if cb: return else: while wait_for_interrupt: time.sleep(0.2) if (focus == 0 and no_button) or button_pushed == "B": return done(False) return done(edit.text())
button_pushed = 'A' def pressed_b(pushed): global wait_for_interrupt, button_pushed wait_for_interrupt = False button_pushed = 'B' def pressed_start(pushed): global wait_for_interrupt, button_pushed wait_for_interrupt = False button_pushed = 'START' ugfx.input_attach(version.btn_ok, pressed_a) ugfx.input_attach(version.btn_cancel, pressed_b) ugfx.input_attach(ugfx.BTN_START, pressed_start) class WaitingMessage: """Shows a dialog with a certain message that can not be dismissed by the user""" def __init__(self, text="Please Wait...", title=version.dialog_title): self.window = ugfx.Container(30, 30, ugfx.width() - 60, ugfx.height() - 60) self.window.show() self.window.text(5, 10, title, ugfx.BLACK) self.window.line(0, 30, ugfx.width() - 60, 30, ugfx.BLACK) self.label = ugfx.Label(5, 40,
else: print("You are up-to-date!") easydraw.msg("Up-to-date!") easydraw.msg_nosplit(str(version.build) + ") " + version.name) easydraw.msg("Update anyway?") title = "Up-to-date" message = "You are up-to-date.\n" message += "Currently installed: " + version.name + " (Build " + str( version.build) + ")\n" message += "Available : " + info[ "name"] + " (Build " + str(info["build"]) + ")" else: print("An error occured!") easydraw.msg("Check failed.") easydraw.msg_nosplit(str(version.build) + ") " + version.name) easydraw.msg("Update anyway?") title = "Update check" message = "An error occured while fetching information. You can still choose to start the OTA procedure." else: easydraw.msg("No WiFi!") easydraw.msg_nosplit(str(version.build) + ") " + version.name) easydraw.msg("Update anyway?") title = "Update check" message = "Could not connect to the WiFi network. You can still choose to start the OTA procedure." ugfx.input_attach(ugfx.BTN_START, start) items = ["Cancel", "Start OTA update"] callbacks = [appglue.home, appglue.start_ota] callbacks[term.menu(title, items, 0, message)]()
if self.delay > 10 and button_pressed: self.delay -= 10 def press_up(self, button_pressed): if self.delay < 1000 and button_pressed: self.delay += 10 def press_left(self, button_pressed): if button_pressed: self.change_color(False) def press_right(self, button_pressed): if button_pressed: self.change_color(True) def main(): strobonator = Strobonator() ugfx.input_attach(ugfx.BTN_START, strobonator.press_start) ugfx.input_attach(ugfx.JOY_UP, strobonator.press_up) ugfx.input_attach(ugfx.JOY_DOWN, strobonator.press_down) ugfx.input_attach(ugfx.JOY_LEFT, strobonator.press_left) ugfx.input_attach(ugfx.JOY_RIGHT, strobonator.press_right) ugfx.input_init() ugfx.input_attach(ugfx.BTN_B, lambda pushed: appglue.home() if pushed else False) _thread.start_new_thread(main, ())
def show_shift_list(): ugfx.clear(ugfx.WHITE) ugfx.flush() global shift_list global shifts shift_list = ugfx.List(0, 0, ugfx.width(), ugfx.height()) if not shifts: shifts = get_shifts(api_key) for shift in shifts: shift_list.add_item("{} - {}, {}".format( generate_timedelta_text(int(shift['start']), int(shift['end'])), shift['name'], shift["Name"])) ugfx.flush(ugfx.LUT_NORMAL) ugfx.input_attach(ugfx.JOY_UP, nothing) ugfx.input_attach(ugfx.JOY_DOWN, nothing) ugfx.input_attach(ugfx.JOY_LEFT, nothing) ugfx.input_attach(ugfx.JOY_RIGHT, nothing) ugfx.input_attach(ugfx.BTN_A, lambda pressed: show_shift_detail() if pressed else None) ugfx.input_attach(ugfx.BTN_B, lambda pressed: appglue.home() if pressed else None)