Exemple #1
0
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()
Exemple #2
0
def show_questions():
    answer_items = []
    answers = None

    questions = get_questions()

    if questions:
        for i, question in enumerate(questions):
            # add 3rd option "skip" to all questions
            question["options"].append({"title": "Skip", "value": "0"})

            title = "TiNDA - Question %i/%i" % (i + 1, len(questions))
            option = dialogs.prompt_option(question["options"],
                                           text=question["text"],
                                           select_text="OK",
                                           none_text="Skip",
                                           title=title)

            if option:
                answer_items.append(option["value"])
            else:
                answer_items.append("0")

        answers = "".join(answer_items)

        database.set(DB_KEY_ANSWERS, answers)

        if get_image_urls(answers):
            show_card()
Exemple #3
0
def store_category(category):
    clear()
    app = dialogs.prompt_option(get_public_apps(category), text="Please select an app", select_text="Details / Install", none_text="Back")
    if app:
        store_details(category, app)
    else:
        store()
def main_menu():
    while True:
        clear()

        print()

        menu_items = [{
            "title": "Install Apps",
            "function": store
        }, {
            "title": "Update",
            "function": update
        }, {
            "title": "Manage Apps",
            "function": remove
        }, {
            "title": "Settings",
            "function": settings
        }]

        option = dialogs.prompt_option(menu_items,
                                       none_text="Exit",
                                       text="What do you want to do?",
                                       title="TiLDA App Library")

        if option:
            option["function"]()
        else:
            return
Exemple #5
0
def store_category(category):
    clear()
    app = dialogs.prompt_option(get_public_apps(category), text="Please select an app", select_text="Details / Install", none_text="Back")
    if app:
        store_details(category, app)
    else:
        store()
Exemple #6
0
def selection(items, title="Settings", none_text="Back"):
    items = [{"title": t, "function": fn} for (t, fn) in items.items()]
    selection = dialogs.prompt_option(items, none_text=none_text, title=title)
    if selection:
        return selection["function"]
    else:
        return None
Exemple #7
0
def store_category(category):
    while True:
        clear()
        app = dialogs.prompt_option(get_public_apps(category), text="Please select an app", select_text="Details / Install", none_text="Back")
        if app:
            store_details(category, app)
            empty_local_app_cache()
        else:
            return
Exemple #8
0
def remove():
    clear()

    app = dialogs.prompt_option(get_local_apps(), title="TiLDA App Library", text="Please select an app to remove", select_text="Remove", none_text="Back")

    if app:
        clear()
        with dialogs.WaitingMessage(text="Removing %s\nPlease wait..." % app, title="TiLDA App Library"):
            for file in os.listdir(app.folder_path):
                os.remove(app.folder_path + "/" + file)
            os.remove(app.folder_path)
        remove()
Exemple #9
0
def main_menu():
    clear()

    menu_items = [
        {"title": "Browse app library", "function": store},
        {"title": "Update apps and libs", "function": update},
        {"title": "Remove app", "function": remove}
    ]

    option = dialogs.prompt_option(menu_items, none_text="Exit", text="What do you want to do?", title="TiLDA App Library")

    if option:
        option["function"]()
Exemple #10
0
def main_menu():
    clear()

    menu_items = [
        {"title": "Browse app library", "function": store},
        {"title": "Update apps and libs", "function": update},
        {"title": "Remove app", "function": remove}
    ]

    option = dialogs.prompt_option(menu_items, none_text="Exit", text="What do you want to do?", title="TiLDA App Library")

    if option:
        option["function"]()
Exemple #11
0
def store():
    global apps_by_category

    clear()
    connect()

    with dialogs.WaitingMessage(text="Fetching app library...", title="TiLDA App Library") as message:
        categories = get_public_app_categories()

    category = dialogs.prompt_option(categories, text="Please select a category", select_text="Browse", none_text="Back")
    if category:
        store_category(category)
    else:
        main_menu()
Exemple #12
0
def store():
    global apps_by_category

    clear()
    connect()

    with dialogs.WaitingMessage(text="Fetching app library...", title="TiLDA App Library") as message:
        categories = get_public_app_categories()

    category = dialogs.prompt_option(categories, text="Please select a category", select_text="Browse", none_text="Back")
    if category:
        store_category(category)
    else:
        main_menu()
Exemple #13
0
def store():
    global apps_by_category

    while True:
        empty_local_app_cache()
        clear()
        connect()

        with dialogs.WaitingMessage(text="Fetching app library...", title="TiLDA App Library"):
            categories = get_public_app_categories()

        category = dialogs.prompt_option(categories, text="Please select a category", select_text="Browse", none_text="Back")
        if category:
            store_category(category)
        else:
            return
Exemple #14
0
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()
Exemple #15
0
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()
Exemple #16
0
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()
Exemple #17
0
def show_menu():
    menu_items = [{
        "title": "Answer questions",
        "function": show_questions
    }, {
        "title": "View emoji card",
        "function": show_card
    }, {
        "title": "Share emoji card",
        "function": show_share
    }, {
        "title": "Manual",
        "function": show_manual
    }]

    option = dialogs.prompt_option(menu_items,
                                   none_text="Exit",
                                   text="Menu",
                                   title=APP_TITLE)

    if option:
        option["function"]()
Exemple #18
0
	Timezone("UTC+02:00", +0200),
	Timezone("UTC+03:00", +0300),
	Timezone("UTC+03:30", +0330),
	Timezone("UTC+04:00", +0400),
	Timezone("UTC+04:30", +0430),
	Timezone("UTC+05:00", +0500),
	Timezone("UTC+05:30", +0530),
	Timezone("UTC+05:45", +0545),
	Timezone("UTC+06:00", +0600),
	Timezone("UTC+06:30", +0630),
	Timezone("UTC+07:00", +0700),
	Timezone("UTC+08:00", +0800),
	Timezone("UTC+08:30", +0830),
	Timezone("UTC+08:45", +0845),
	Timezone("UTC+09:00", +0900),
	Timezone("UTC+09:30", +0930),
	Timezone("UTC+10:00", +1000),
	Timezone("UTC+10:30", +1030),
	Timezone("UTC+11:00", +1100),
	Timezone("UTC+12:00", +1200),
	Timezone("UTC+12:45", +1245),
	Timezone("UTC+13:00", +1300),
	Timezone("UTC+14:00", +1400)
]

ugfx.init()

tz = dialogs.prompt_option(timezone_list, text="Select your timezone:", index=14)
with database.Database() as db:
	db.set("timezone", int(tz.value))
Exemple #19
0
import dialogs
import buttons

buttons.init()
buttons.disable_menu_reset()

ugfx.init()
ugfx.clear(ugfx.html_color(0x7c1143))

pin_options = [
	{"title": "Onboard NeoPixel", "value":"PB13"},
	{"title": "Servo Header 2", "value":"X2"},
]

led_pin_name = database_get("led-port", "PB13")
pinnm = dialogs.prompt_option(pin_options, text="What connector are your neopixels on?", title="Wearables Controller")
if pinnm:
	database_set("led-port", pinnm['value'])

menu_items = [
	{"title": "Rainbow", "value":"rainbow"},
	{"title": "Matrix", "value":"matrix"},
	{"title": "Colour", "value":"colour"},
        {"title": "Off", "value":"off"}
]

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:
Exemple #20
0

pin_options = [
    {
        "title": "Onboard NeoPixel",
        "value": "PB13"
    },
    {
        "title": "Servo Header 2",
        "value": "X2"
    },
]

led_pin_name = database_get("led-port", "PB13")
pinnm = dialogs.prompt_option(pin_options,
                              text="What connector are your neopixels on?",
                              title="Wearables Controller")
if pinnm:
    database_set("led-port", pinnm['value'])

menu_items = [{
    "title": "Rainbow",
    "value": "rainbow"
}, {
    "title": "Matrix",
    "value": "matrix"
}, {
    "title": "Colour",
    "value": "colour"
}]