def connectClick(pushed): if pushed: selected = options.selected_text().encode() print('selected') options.destroy() ssidType = scanResults[ssidList.index(selected)][4] print(ssidType) print(ssidList.index(selected)) ugfx.clear(ugfx.WHITE) ugfx.string(100, 50, selected, 'Roboto_Regular18', ugfx.BLACK) ugfx.flush() if ssidType == 5: clearGhosting() ugfx.clear(ugfx.WHITE) ugfx.string(20, 50, 'WPA Enterprise unsupported...', 'Roboto_Regular18', ugfx.BLACK) ugfx.set_lut(ugfx.LUT_FULL) ugfx.flush() badge.eink_busy_wait() system.reboot() badge.nvs_set_str("system", "wifi.ssid", selected) if ssidType == 0: badge.nvs_set_str("system", "wifi.password", '') system.reboot() else: clearGhosting() dialogs.prompt_text("WiFi password", cb=passInputDone)
def show_weight(): ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") sleep.sleep_ms(1000) while True: input = dialogs.prompt_text("Please enter your weight.", false_text="Cancel") if is_int(input): break sleep.wfi() ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") sleep.sleep_ms(1000) while True: input = dialogs.prompt_text("Please enter your correct weight.", false_text="Cancel") if is_int(input): break sleep.wfi() ugfx.display_image(0, 0, LOCAL_FOLDER % "main.gif") with dialogs.WaitingMessage("Please wait.", title="Processing..."): sleep.sleep_ms(2000) show_next_step()
def attempt_unlock(pressed): global ransom_secret, ransom_paid if not pressed: write_lock() else: dialogs.prompt_text("Ransom secret: ", cb=attempt_unlock_secret_entered)
def choose_wifi(dialog_title='TiLDA'): with dialogs.WaitingMessage(text='Scanning for networks...', title=dialog_title): visible_aps = nic().list_aps() visible_aps.sort(key=lambda x:x['rssi'], reverse=True) visible_ap_names = [] # We'll get one result for each AP, so filter dupes for ap in visible_aps: if ap['ssid'] not in visible_ap_names: visible_ap_names.append(ap['ssid']) visible_aps = None ssid = dialogs.prompt_option( visible_ap_names, text='Choose wifi network', title=dialog_title ) key = dialogs.prompt_text("Enter wifi key (blank if none)", width = 310, height = 220) if ssid: with open("wifi.json", "wt") as file: if key: conn_details = {"ssid": ssid, "pw": key} else: conn_details = {"ssid": ssid} file.write(json.dumps(conn_details)) os.sync() # We can't connect after scanning for some bizarre reason, so we reset instead pyb.hard_reset()
def inner(state): value = getter_setter_function() value = dialogs.prompt_text(title, init_text=value, true_text="Change", false_text="Back") if value: getter_setter_function(value)
def inner(state): value = database.get(key, default) value = dialogs.prompt_text(title, init_text=value, true_text="Change", false_text="Back") if value: database.set(key, value)
def post_post(pushed): if (pushed): nick = dialogs.prompt_text("Please enter name") if nick: print(nick) response = urequests.post("http://127.0.0.1:3000/posts", data="some dummy content") print(response)
def create_profile(my_profile): ugfx.clear(ugfx.html_color(0x000000)) name, age = "", "" while name == "": name = dialogs.prompt_text("What's your name?") while age == "": age = dialogs.prompt_text("What's your age?") tag_line = dialogs.prompt_text("Tell us your tagline:") looking_for = dialogs.prompt_text("And what you're looking for:") contact = dialogs.prompt_text("And your twitter username?") imei = sim800.imei() top_left_logo() ugfx.text(5, 100, "Working...", ugfx.BLACK) profile = { 'unique_identifier': imei, 'username': name, 'age': age, 'tag_line': tag_line, 'looking_for': looking_for, 'contact': contact } profile_json = ujson.dumps(profile) try: http.post(api_url+'/create_user', json=profile).raise_for_status().close() except: ugfx.clear() ugfx.text(5, 100, "Error. Try again later. :(", ugfx.BLACK) return False database.set("tildr_profile", profile_json) return True
def create_comment(thread): title = dialogs.prompt_text("Whats your comment?:") request = { "who": sim800.imei(), "comment": title, } request_json = ujson.dumps(request) try: http.post(api_url + "/threads/" + thread.threadID, json=request_json).raise_for_status().close() except: ugfx.clear() ugfx.text(5, 100, "Error. Try again later. :(", ugfx.BLACK) return False
def create_thread(): title = dialogs.prompt_text("Whats the title of the new thread?:") request = { "who": sim800.imei(), "title": title, } request_json = ujson.dumps(request) try: http.post(api_url + '/threads', json=request_json).raise_for_status().close() except: ugfx.clear() ugfx.text(5, 100, "Error. Try again later. :(", ugfx.BLACK) return False
def choose_wifi(dialog_title='TiLDA'): filtered_aps = [] with dialogs.WaitingMessage(text='Scanning for networks...', title=dialog_title): visible_aps = nic().list_aps() visible_aps.sort(key=lambda x:x['rssi'], reverse=True) # We'll get one result for each AP, so filter dupes for ap in visible_aps: title = ap['ssid'] security = get_security_level(ap) if security: title = title + ' (%s)' % security ap = { 'title': title, 'ssid': ap['ssid'], 'security': security, } if ap['ssid'] not in [ a['ssid'] for a in filtered_aps ]: filtered_aps.append(ap) del visible_aps ap = dialogs.prompt_option( filtered_aps, text='Choose wifi network', title=dialog_title ) if ap: key = None if ap['security'] != 0: # Backward compat if ap['security'] == None: ap['security'] = 'wifi' key = dialogs.prompt_text( "Enter %s key" % ap['security'], width = 310, height = 220 ) with open("wifi.json", "wt") as file: if key: conn_details = {"ssid": ap['ssid'], "pw": key} else: conn_details = {"ssid": ap['ssid']} file.write(json.dumps(conn_details)) os.sync() # We can't connect after scanning for some bizarre reason, so we reset instead pyb.hard_reset()
def choose_wifi(dialog_title='TiLDA'): filtered_aps = [] with dialogs.WaitingMessage(text='Scanning for networks...', title=dialog_title): visible_aps = None while not visible_aps: visible_aps = nic().scan() print(visible_aps) sleep.sleep_ms(300) #todo: timeout visible_aps.sort(key=lambda x: x[3], reverse=True) # We'll get one result for each AP, so filter dupes for ap in visible_aps: title = ap[0] security = "?" # todo: re-add get_security_level(ap) if security: title = title + ' (%s)' % security ap = { 'title': title, 'ssid': ap[0], 'security': ap[4], } if ap['ssid'] not in [a['ssid'] for a in filtered_aps]: filtered_aps.append(ap) del visible_aps ap = dialogs.prompt_option(filtered_aps, text='Choose wifi network', title=dialog_title) if ap: key = None if ap['security'] != 0: # Backward compat if ap['security'] == None: ap['security'] = 'wifi' key = dialogs.prompt_text("Enter %s key" % ap['security']) with open("wifi.json", "wt") as file: if key: conn_details = {"ssid": ap['ssid'], "pw": key} else: conn_details = {"ssid": ap['ssid']} file.write(json.dumps(conn_details)) os.sync()
def choose_wifi(dialog_title='TiLDA'): filtered_aps = [] with dialogs.WaitingMessage(text='Scanning for networks...', title=dialog_title): visible_aps = nic().list_aps() visible_aps.sort(key=lambda x: x['rssi'], reverse=True) # We'll get one result for each AP, so filter dupes for ap in visible_aps: title = ap['ssid'] security = get_security_level(ap) if security: title = title + ' (%s)' % security ap = { 'title': title, 'ssid': ap['ssid'], 'security': security, } if ap['ssid'] not in [a['ssid'] for a in filtered_aps]: filtered_aps.append(ap) del visible_aps ap = dialogs.prompt_option(filtered_aps, text='Choose wifi network', title=dialog_title) if ap: key = None if ap['security'] != 0: # Backward compat if ap['security'] == None: ap['security'] = 'wifi' key = dialogs.prompt_text("Enter %s key" % ap['security'], width=310, height=220) with open("wifi.json", "wt") as file: if key: conn_details = {"ssid": ap['ssid'], "pw": key} else: conn_details = {"ssid": ap['ssid']} file.write(json.dumps(conn_details)) os.sync() # We can't connect after scanning for some bizarre reason, so we reset instead pyb.hard_reset()
def screen(state): if state['profile'] is None: state['profile'] = { 'unique_identifier': "", 'username': "", 'age': "", 'tag_line': "", 'looking_for': "", 'contact': "" } ds = [ ["username", "What's your name?"], ["age", "What's your age?"], ["tag_line", "Tell us your tagline"], ["looking_for", "And what you're looking for"], ["contact", "And your twitter username"], ] i = 0 while i < len(ds): res = dialogs.prompt_text(ds[i][1], init_text=state['profile'][ds[i][0]]) if res is None: i -= 1 if i < 0: state['next'] = "SPLASH" return elif res != "": state['profile'][ds[i][0]] = res i += 1 state['profile']['unique_identifier'] = sim800.imei() if not create_profile(state): state['next'] = "ERROR" return state['next'] = "NEXT_PERSON"
def prompt_answer_and_make_lowercase(key): answer = dialogs.prompt_text("Enter answer for " + questions[key], init_text="") return answer.lower()
def prompt_api_key(): global api_key api_key = dialogs.prompt_text("Your engelsystem api key") badge.nvs_set_str("engel", "key", api_key)
import system, badge, dialogs def callback(value): if value: badge.nvs_set_str("owner", "name", value) system.home() nickname = badge.nvs_get_str("owner", "name", "") dialogs.prompt_text("Nickname", nickname, cb=callback)
# License: MIT # Authors: Renze Nicolai <*****@*****.**> # Thomas Roos <?> import ugfx, badge, appglue, dialogs, easydraw, time def asked_nickname(value): if value: badge.nvs_set_str("owner", "name", value) # Do the firstboot magic newState = 1 if badge.nvs_get_u8('badge', 'setup.state', 0) == 0 else 3 badge.nvs_set_u8('badge', 'setup.state', newState) # Show the user that we are done easydraw.msg("Hi " + value + "!", 'Your nick has been stored to flash!') time.sleep(0.5) else: badge.nvs_set_u8('badge', 'setup.state', 2) # Skip the sponsors badge.nvs_set_u8('sponsors', 'shown', 1) appglue.home() ugfx.init() nickname = badge.nvs_get_str("owner", "name", "") dialogs.prompt_text("Nickname", nickname, cb=asked_nickname)
import dialogs import ugfx import badge ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() name = badge.nvs_get_str("owner", "name", "") nick = dialogs.prompt_text("Please enter name", name) if nick: badge.nvs_set_str("owner", "name", nick) #Nice clean screen ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() ugfx.string_box(0, 10, 296, 26, "STILL", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(0, 45, 296, 38, nick, "PermanentMarker36", ugfx.BLACK, ugfx.justifyCenter) ugfx.string_box(0, 94, 296, 26, "Anyway", "Roboto_BlackItalic24", ugfx.BLACK, ugfx.justifyCenter) #the line under the text str_len = ugfx.get_string_width(nick, "PermanentMarker36") line_begin = int((296 - str_len) / 2) line_end = str_len + line_begin ugfx.line(line_begin, 83, line_end, 83, ugfx.BLACK)
def tick(self): with database.Database() as db: crs = prompt_text('Enter your station\'s CRS code', db.get('trains.station_code', '')) db.set('trains.station_code', crs) return self.next_state
### Author: EMF Badge team ### Description: Change your name ### Category: Settings ### License: MIT ### Appname : Change name import dialogs from database import Database import buttons import ugfx ugfx.init() buttons.init() with Database() as db: name = db.get("display-name", "") name_new = dialogs.prompt_text("Enter your name", init_text=name, width = 310, height = 220) if name_new: db.set("display-name", name_new)
"""Change your name""" ___categories___ = ["settings"] ___license___ = "MIT" ___dependencies___ = ["dialogs", "buttons"] import dialogs from database import Database import buttons import ugfx ugfx.init() buttons.init() with Database() as db: name = db.get("display-name", "") name_new = dialogs.prompt_text("Enter your name", init_text=name, width = 310, height = 220) if name_new: db.set("display-name", name_new)
# Only convert alphanumeric characters. if letter in morse_map: morse = morse_map[letter] for char in morse: if char == ".": dot() else: dash() # Output a string in Morse code. def convert_string(string): words = string.split() for word in words: for letter in word: convert_letter(letter) letter_space() word_space() # Get string input from user. string = dialogs.prompt_text("Enter string to convert", init_text="", width=310, height=220) if string: ugfx.area(0, 0, ugfx.width(), ugfx.height(), 0) ugfx.text(30, 60, "Morse Code...", 0xFFFF) convert_string(string.upper())
pyb.delay(400) # Output a single letter in Morse code. def convert_letter(letter): # Only convert alphanumeric characters. if letter in morse_map: morse = morse_map[letter] for char in morse: if char == ".": dot() else: dash() # Output a string in Morse code. def convert_string(string): words = string.split() for word in words: for letter in word: convert_letter(letter) letter_space() word_space() # Get string input from user. string = dialogs.prompt_text("Enter string to convert", init_text="", width = 310, height = 220) if string: ugfx.area(0, 0, ugfx.width(), ugfx.height(), 0) ugfx.text(30, 60, "Morse Code...", 0xFFFF) convert_string(string.upper())
] led_seq_name = database_get("led-seq-name", "rainbow") option = dialogs.prompt_option(menu_items, text="What sequence do you want?", title="Wearables Controller") if option: database_set("led-seq-name", option['value']) led_count = database_get("led-count", "1") count = None ugfx.clear(ugfx.html_color(0x7c1143)) while True: count = dialogs.prompt_text("How many LEDs? (Numeric)", init_text=str(led_count), false_text=str(led_count)) if count and count.isdigit(): count = int(count) break database_set("led-count", count) if option['value'] == "rainbow": rainbow_speeds = [ {"title": "Normal", "value":100}, {"title": "Fast", "value":20}, {"title": "Slow", "value":500} ] led_seq_name = database_get("led-period", "rainbow") speed = dialogs.prompt_option(rainbow_speeds, text="How fast?", title="Rainboooooowwwww")
if option: database_set("led-seq-name", option['value']) timer = pyb.Timer(3) timer.init(freq=60) timer.callback(tick_inc) led_count = database_get("led-count", "1") count = None ugfx.clear(ugfx.html_color(0x7c1143)) while True: count = dialogs.prompt_text("How many LEDs? (Numeric)", init_text=str(led_count), false_text=str(led_count)) if count.isdigit(): count = int(count) break database_set("led-count", count) if option['value'] == "rainbow": timer.deinit() rainbow_speeds = [{ "title": "Normal", "value": 100 }, { "title": "Fast", "value": 20
ugfx.clear(ugfx.WHITE); ugfx.string(10,10,"Waiting for wifi...","Roboto_Regular12", 0) ugfx.flush() # Wait for WiFi connection while not wifi.sta_if.isconnected(): time.sleep(0.1) pass ugfx.clear(ugfx.BLACK) ugfx.flush() ugfx.clear(ugfx.WHITE) ugfx.flush() input_string = badge.nvs_get_str("Hashtag", "hashtag", "") hashtag = dialogs.prompt_text("What hashtag should we display?", input_string) if hashtag: badge.nvs_set_str("Hashtag", "hashtag", hashtag) tweets = [] def get_tweets(hashtag): gc.collect() try: data = requests.get("http://server/html/twitter/get.php?hashtag="+hashtag) except: print("Could not download JSON!") time.sleep(1) return try: global tweets tweets = data.json()