Exemplo n.º 1
0
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()
Exemplo n.º 2
0
def prompt_text(description, init_text="", true_text="OK", false_text="Back", font=FONT_MEDIUM_BOLD, style=default_style_badge):
    """Shows a dialog and keyboard that allows the user to input/change a string

    Returns None if user aborts with button B
    """

    window = ugfx.Container(0, 0, ugfx.width(), ugfx.height())

    if false_text:
        true_text = "A: " + true_text
        false_text = "B: " + false_text

    ugfx.set_default_font(FONT_MEDIUM_BOLD)
    kb = ugfx.Keyboard(0, ugfx.height()//2, ugfx.width(), ugfx.height()//2, parent=window)
    edit = ugfx.Textbox(2, ugfx.height()//2-60, ugfx.width()-7, 25, text = init_text, parent=window)
    ugfx.set_default_font(FONT_SMALL)
    button_yes = ugfx.Button(2, ugfx.height()//2-30, ugfx.width()//2-6, 25 , true_text, parent=window)
    button_no = ugfx.Button(ugfx.width()//2+2, ugfx.height()//2-30, ugfx.width()//2-6, 25 , false_text, parent=window) if false_text else None
    ugfx.set_default_font(font)
    label = ugfx.Label(ugfx.width()//10, ugfx.height()//10, ugfx.width()*4//5, ugfx.height()*2//5-90, description, parent=window)

    try:
        window.show()
        # edit.set_focus() todo: do we need this?
        while True:
            sleep.wfi()
            ugfx.poll()
            if buttons.is_triggered(buttons.Buttons.BTN_A): return edit.text()
            if buttons.is_triggered(buttons.Buttons.BTN_B): return None
            if buttons.is_triggered(buttons.Buttons.BTN_Menu): return edit.text()
            if buttons.is_triggered(buttons.Buttons.BTN_0): edit.text(edit.text() + "0")
            if buttons.is_triggered(buttons.Buttons.BTN_1): edit.text(edit.text() + "1")
            if buttons.is_triggered(buttons.Buttons.BTN_2): edit.text(edit.text() + "2")
            if buttons.is_triggered(buttons.Buttons.BTN_3): edit.text(edit.text() + "3")
            if buttons.is_triggered(buttons.Buttons.BTN_4): edit.text(edit.text() + "4")
            if buttons.is_triggered(buttons.Buttons.BTN_5): edit.text(edit.text() + "5")
            if buttons.is_triggered(buttons.Buttons.BTN_6): edit.text(edit.text() + "6")
            if buttons.is_triggered(buttons.Buttons.BTN_7): edit.text(edit.text() + "7")
            if buttons.is_triggered(buttons.Buttons.BTN_8): edit.text(edit.text() + "8")
            if buttons.is_triggered(buttons.Buttons.BTN_9): edit.text(edit.text() + "9")
            if buttons.is_triggered(buttons.Buttons.BTN_Hash): edit.text(edit.text() + "#")
            if buttons.is_triggered(buttons.Buttons.BTN_Star): edit.text(edit.text() + "*")

    finally:
        window.hide()
        window.destroy()
        button_yes.destroy()
        if button_no: button_no.destroy()
        label.destroy()
        kb.destroy()
        edit.destroy();
    return
Exemplo n.º 3
0
def execute_next_command():
    while True:
        sleep.wfi()

        if buttons.is_pressed(Buttons.BTN_A):
            return answer_current_question()

        if buttons.is_pressed(Buttons.BTN_Menu) or buttons.is_pressed(Buttons.BTN_B):
            return quit_game()

        if buttons.is_pressed(Buttons.JOY_Up) or buttons.is_pressed(Buttons.JOY_Left):
            return next_question()

        if buttons.is_pressed(Buttons.JOY_Down) or buttons.is_pressed(Buttons.JOY_Right):
            return previous_question()
Exemplo n.º 4
0
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()
Exemplo n.º 5
0
def prompt_boolean(text, title="TiLDA", true_text="Yes", false_text="No", font=FONT_SMALL, style=None):
    """A simple one and two-options dialog

    if 'false_text' is set to None only one button is displayed.
    If both 'true_text' and 'false_text' are given a boolean is returned
    """
    global default_style_dialog
    if style == None:
        style = default_style_dialog
    ugfx.set_default_font(FONT_MEDIUM_BOLD)

    width = ugfx.width() - 10
    height = ugfx.height() - 10

    window = ugfx.Container(5, 5,  width, height)
    window.show()
    ugfx.set_default_font(font)
    window.text(5, 10, title, TILDA_COLOR)
    window.line(0, 30, width, 30, ugfx.BLACK)

    if false_text:
        true_text = "A: " + true_text
        false_text = "B: " + false_text

    ugfx.set_default_font(font)
    label = ugfx.Label(5, 30, width - 10, height - 80, text = text, parent=window)
    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_no = ugfx.Button(width // 2 + 5, height - 40, width // 2 - 15, 30 , false_text, parent=window) if false_text else None

    try:
        #button_yes.attach_input(ugfx.BTN_A,0) # todo: re-enable once working
        #if button_no: button_no.attach_input(ugfx.BTN_B,0)

        window.show()

        while True:
            sleep.wfi()
            if buttons.is_triggered(buttons.Buttons.BTN_A): return True
            if buttons.is_triggered(buttons.Buttons.BTN_B): return False

    finally:
        window.hide()
        window.destroy()
        button_yes.destroy()
        if button_no: button_no.destroy()
        label.destroy()
Exemplo n.º 6
0
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()
Exemplo n.º 7
0
def show_manual():
    ugfx.clear(APP_COLOUR)
    window = ugfx.Container(0, 0, ugfx.width(), ugfx.height())
    window.show()
    window.text(5, 10, "TiNDA: Dating app for TiLDA", ugfx.BLACK)
    window.text(5, 30, "Find your perfect EMF match", ugfx.BLACK)
    window.line(0, 50, ugfx.width(), 50, ugfx.BLACK)

    window.text(5, 60, "Step 1: Answer all questions", ugfx.BLACK)
    window.text(5, 80, "and receive an emoji card.", ugfx.BLACK)

    window.text(5, 110, "Step 2: Compare cards with", ugfx.BLACK)
    window.text(5, 130, "other people and count", ugfx.BLACK)
    window.text(5, 150, "matching emoji.", ugfx.BLACK)

    window.text(5, 180, "Step 3: <3", ugfx.BLACK)

    while ((not Buttons.is_pressed(Buttons.BTN_B))
           and (not Buttons.is_pressed(Buttons.BTN_Menu))):
        sleep.wfi()
Exemplo n.º 8
0
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()
Exemplo n.º 9
0
def prompt_option(options, index=0, text = None, title=None, select_text="OK", none_text=None):
    """Shows a dialog prompting for one of multiple options

    If none_text is specified the user can use the B or Menu button to skip the selection
    if title is specified a blue title will be displayed about the text
    """
    ugfx.set_default_font(FONT_SMALL)
    window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
    window.show()

    list_y = 30
    if title:
        window.text(5, 10, title, TILDA_COLOR)
        window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK)
        list_y = 30
        if text:
            list_y += 20
            window.text(5, 30, text, ugfx.BLACK)

    else:
        window.text(5, 10, text, ugfx.BLACK)

    options_list = ugfx.List(5, list_y, ugfx.width() - 25, 260 - list_y, parent = window)
    options_list.disable_draw()

    for option in options:
        if isinstance(option, dict) and option["title"]:
            options_list.add_item(option["title"])
        else:
            options_list.add_item(str(option))
    options_list.enable_draw()
    options_list.selected_index(index)

    select_text = "A: " + select_text
    if 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_none = ugfx.Button(117, ugfx.height() - 50, 105, 30 , none_text, parent=window) if none_text else None

    try:
        while True:
            sleep.wfi()
            ugfx.poll()
            # todo: temporary hack
            #if (buttons.is_triggered(buttons.Buttons.JOY_Up)):
            #    index = max(index - 1, 0)
            #    options_list.selected_index(index)
            #if (buttons.is_triggered(buttons.Buttons.JOY_Down)):
            #    index = min(index + 1, len(options) - 1)
            #    options_list.selected_index(index)

            if buttons.is_triggered(buttons.Buttons.BTN_A) or buttons.is_triggered(buttons.Buttons.JOY_Center):
                return options[options_list.selected_index()]
            if button_none and buttons.is_triggered(buttons.Buttons.BTN_B): return None
            if button_none and buttons.is_triggered(buttons.Buttons.BTN_Menu): return None

    finally:
        window.hide()
        window.destroy()
        options_list.destroy()
        button_select.destroy()
        if button_none: button_none.destroy()
        ugfx.poll()
Exemplo n.º 10
0
"""A big "thank you" to all our Sponsors who made this year's badge possible!"""

___title___ = "Sponsors"
___license___ = "MIT"
___dependencies___ = ["wifi", "http", "ugfx_helper", "sleep", "app"]
___categories___ = ["EMF"]
___bootstrapped___ = True

import ugfx_helper, os, wifi, ugfx, http, time, sleep, app
from tilda import Buttons

ugfx_helper.init()
ugfx.clear()

ugfx.text(5, 5, "Loading...", ugfx.BLACK)
try:
    image = http.get("http://s3.amazonaws.com/tilda-badge/sponsors/screen.png"
                     ).raise_for_status().content
    ugfx.display_image(0, 0, bytearray(image))
except:
    ugfx.clear()
    ugfx.text(5, 5, "Couldn't download sponsors", ugfx.BLACK)

while (not Buttons.is_pressed(Buttons.BTN_A)) and (not Buttons.is_pressed(
        Buttons.BTN_B)) and (not Buttons.is_pressed(Buttons.BTN_Menu)):
    sleep.wfi()

ugfx.clear()
app.restart_to_default()
Exemplo n.º 11
0
def prompt_option(options,
                  index=0,
                  text=None,
                  title=None,
                  select_text="OK",
                  none_text=None):
    """Shows a dialog prompting for one of multiple options

    If none_text is specified the user can use the B or Menu button to skip the selection
    if title is specified a blue title will be displayed about the text
    """
    ugfx.set_default_font(FONT_SMALL)
    window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
    window.show()

    list_y = 30
    if title:
        window.text(5, 10, title, TILDA_COLOR)
        window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK)
        list_y = 30
        if text:
            list_y += 20
            window.text(5, 30, text, ugfx.BLACK)

    else:
        window.text(5, 10, text, ugfx.BLACK)

    options_list = ugfx.List(5,
                             list_y,
                             ugfx.width() - 25,
                             260 - list_y,
                             parent=window)
    options_list.disable_draw()

    optnum = 1
    for option in options:
        if isinstance(option, dict) and option["title"]:
            title = option["title"]
        else:
            title = str(option)

        if optnum < 11:
            # mod 10 to make 10th item numbered 0
            options_list.add_item("{}: {}".format((optnum % 10), title))
        else:
            options_list.add_item("    {}".format(title))
        optnum = optnum + 1

    options_list.enable_draw()
    options_list.selected_index(index)

    select_text = "A: " + select_text
    if 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_none = ugfx.Button(
        117, ugfx.height() -
        50, 105, 30, none_text, parent=window) if none_text else None

    try:
        while True:
            sleep.wfi()
            ugfx.poll()
            # todo: temporary hack
            #if (buttons.is_triggered(buttons.Buttons.JOY_Up)):
            #    index = max(index - 1, 0)
            #    options_list.selected_index(index)
            #if (buttons.is_triggered(buttons.Buttons.JOY_Down)):
            #    index = min(index + 1, len(options) - 1)
            #    options_list.selected_index(index)

            if buttons.is_triggered(
                    buttons.Buttons.BTN_A) or buttons.is_triggered(
                        buttons.Buttons.JOY_Center):
                return options[options_list.selected_index()]
            if button_none and buttons.is_triggered(buttons.Buttons.BTN_B):
                return None
            if button_none and buttons.is_triggered(buttons.Buttons.BTN_Menu):
                return None
            # These are indexes for selected_index, 1 means "First item", ie index 0. 0 is treated as if it were 10
            button_nums = {
                Buttons.BTN_1: 0,
                Buttons.BTN_2: 1,
                Buttons.BTN_3: 2,
                Buttons.BTN_4: 3,
                Buttons.BTN_5: 4,
                Buttons.BTN_6: 5,
                Buttons.BTN_7: 6,
                Buttons.BTN_8: 7,
                Buttons.BTN_9: 8,
                Buttons.BTN_0: 9,
            }
            for key, num in button_nums.items():
                if buttons.is_triggered(key):
                    # No need to check for too large an index; gwinListSetSelected validates this.
                    options_list.selected_index(num)
                    break
            if buttons.is_triggered(Buttons.BTN_Hash):
                # Page down
                idx = options_list.selected_index() + 10
                cnt = options_list.count()
                if idx >= cnt:
                    idx = cnt - 1
                options_list.selected_index(idx)
                continue
            if buttons.is_triggered(Buttons.BTN_Star):
                # Page up
                idx = options_list.selected_index() - 10
                if idx < 0:
                    idx = 0
                options_list.selected_index(idx)
                continue

    finally:
        window.hide()
        window.destroy()
        options_list.destroy()
        button_select.destroy()
        if button_none: button_none.destroy()
        ugfx.poll()
Exemplo n.º 12
0
def prompt_boolean(text,
                   title="TiLDA",
                   true_text="Yes",
                   false_text="No",
                   font=FONT_SMALL,
                   style=None):
    """A simple one and two-options dialog

    if 'false_text' is set to None only one button is displayed.
    If both 'true_text' and 'false_text' are given a boolean is returned
    """
    global default_style_dialog
    if style == None:
        style = default_style_dialog
    ugfx.set_default_font(FONT_MEDIUM_BOLD)

    width = ugfx.width() - 10
    height = ugfx.height() - 10

    window = ugfx.Container(5, 5, width, height)
    window.show()
    ugfx.set_default_font(font)
    window.text(5, 5, title, TILDA_COLOR)
    window.line(0, 25, width, 25, ugfx.BLACK)

    if false_text:
        true_text = "A: " + true_text
        false_text = "B: " + false_text

    ugfx.set_default_font(font)
    label = ugfx.Label(5,
                       30,
                       width - 10,
                       height - 80,
                       text=text,
                       parent=window,
                       justification=4)

    ugfx.set_default_font(FONT_MEDIUM_BOLD)
    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,
                            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:
        #button_yes.attach_input(ugfx.BTN_A,0) # todo: re-enable once working
        #if button_no: button_no.attach_input(ugfx.BTN_B,0)

        window.show()

        while True:
            sleep.wfi()
            if buttons.is_triggered(buttons.Buttons.BTN_A): return True
            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:
        window.hide()
        window.destroy()
        button_yes.destroy()
        if button_no: button_no.destroy()
        label.destroy()