def __init__(self):
        # initialize ugfx
        ugfx.init()
        ugfx.clear(ugfx.WHITE)

        # Buttons
        ugfx.input_init()
        self.init_buttons()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        ind_height = 46
        container_height = height - ind_height

        self.indicator = ugfx.Container(0,
                                        0,
                                        width,
                                        ind_height,
                                        style=styles.ibm_st)
        self.container = ugfx.Container(0,
                                        ind_height,
                                        width,
                                        container_height,
                                        style=styles.ibm_st)

        self.graph_basepos = container_height - 5

        # Sensor
        SCL = Pin(26)  # SCL
        SDA = Pin(25)  # SDA
        self.sensor = MPU6050(I2C(scl=SCL, sda=SDA))

        # Buzzer
        self.buzzer = Buzzer()
Exemplo n.º 2
0
    def __init__(self, config):

        # Get the config
        self.__debug = config.get('debug')

        # Configure the style and layout
        ugfx.set_default_font(ugfx.FONT_MEDIUM)
        ugfx.set_default_style(dialogs.default_style_badge)
        self.__sty_tb = ugfx.Style(dialogs.default_style_badge)
        self.__sty_tb.set_enabled([
            ugfx.WHITE,
            ugfx.html_color(0xA66FB0),
            ugfx.html_color(0x5e5e5e), ugfx.RED
        ])
        self.__sty_tb.set_background(ugfx.GREY)
        self.__win_bv = ugfx.Container(0, 0, 80, 25, style=self.__sty_tb)
        self.__win_wifi = ugfx.Container(82, 0, 60, 25, style=self.__sty_tb)
        self.__win_clock = ugfx.Container(250, 0, 70, 25, style=self.__sty_tb)
        self.__win_wifi.show()
        self.__win_bv.show()
        self.__win_clock.show()

        # Init var for last RSSI
        self.__last_rssi = 0

        # Schedule next status update
        self.__next_status_update = pyb.millis() + 500
Exemplo n.º 3
0
 def _get_names_container(self):
     if self._names != None:
         self._names.hide()
         self._old_names = self._names
     names = ugfx.Container(0, 25, 190, 295)
     self._names = names
     return names
Exemplo n.º 4
0
    def __init__(self, text="Please Wait...", title="SHA2017Badge"):
        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,
                                self.window.width() - 10,
                                ugfx.height() - 40,
                                text=text,
                                parent=self.window)

        # Indicator to show something is going on
        self.indicator = ugfx.Label(ugfx.width() - 100,
                                    0,
                                    20,
                                    20,
                                    text="...",
                                    parent=self.window)
        self.timer = pyb.Timer(3)
        self.timer.init(freq=3)
        self.timer.callback(
            lambda t: self.indicator.visible(not self.indicator.visible()))
Exemplo n.º 5
0
    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,
                                self.window.width() - 10,
                                ugfx.height() - 40,
                                text=text,
                                parent=self.window)

        # Indicator to show something is going on
        self.indicator = ugfx.Label(ugfx.width() - 100,
                                    0,
                                    20,
                                    20,
                                    text="...",
                                    parent=self.window)
        self.timer = machine.Timer(-1)
        self.timer.init(period=2000,
                        mode=self.timer.PERIODIC,
                        callback=lambda t: self.indicator.visible(
                            not self.indicator.visible()))
Exemplo n.º 6
0
 def create_window(self, show=True):
     ugfx.clear(ugfx.BLACK)
     self.window = ugfx.Container(0,
                                  0,
                                  ugfx.width(),
                                  ugfx.height(),
                                  style=styles.ibm_st)
     if show:
         self.window.show()
     return self.window
Exemplo n.º 7
0
def prompt_option(options, index=0, text = "Please select one of the following:", 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
	"""
	global wait_for_interrupt, button_pushed

	ugfx.set_default_font("Roboto_Regular12")
	window = ugfx.Container(5, 5, ugfx.width() - 10, ugfx.height() - 10)
	window.show()

	list_y = 30
	if title:
		window.text(5, 10, title, ugfxBLACK)
		window.line(0, 25, ugfx.width() - 10, 25, ugfx.BLACK)
		window.text(5, 30, text, ugfx.BLACK)
		list_y = 50
	else:
		window.text(5, 10, text, ugfx.BLACK)

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

	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.selected_index(index)

	select_text = "A: " + select_text
	if none_text:
		none_text = "B: " + none_text

	button_select = ugfx.Button(5, ugfx.height() - 50, 140 if none_text else ugfx.width() - 25, 30 , select_text, parent=window)
	button_none = ugfx.Button(ugfx.width() - 160, ugfx.height() - 50, 140, 30 , none_text, parent=window) if none_text else None

	try:
		ugfx.input_init()

		wait_for_interrupt = True
		while wait_for_interrupt:
			if button_pushed == "A": return options[options_list.selected_index()]
			if button_pushed == "B": return None
			if button_none and button_pushed == "START": return None
			time.sleep(0.2)

	finally:
		window.hide()
		window.destroy()
		options_list.destroy()
		button_select.destroy()
		if button_none: button_none.destroy()
		ugfx.poll()
Exemplo n.º 8
0
def screen(state):
    window = ugfx.Container(0, 0, 240, 320)
    window.show()

    top_left_logo()

    ugfx.set_default_font(ugfx.FONT_TITLE)
    l1 = ugfx.Label(5,
                    90,
                    230,
                    50,
                    "You've swiped everybody!",
                    parent=window,
                    justification=ugfx.Label.CENTERTOP)
    ugfx.set_default_font(ugfx.FONT_SMALL)
    l2 = ugfx.Label(5,
                    160,
                    230,
                    20,
                    "Soz " + state["profile"]["username"],
                    parent=window,
                    justification=ugfx.Label.CENTERTOP)
    l3 = ugfx.Label(5,
                    180,
                    230,
                    20,
                    "Come back later ;)",
                    parent=window,
                    justification=ugfx.Label.CENTERTOP)

    b2 = ugfx.Button(0,
                     280,
                     120,
                     40,
                     "< Edit profile",
                     parent=window,
                     shape=ugfx.Button.RECT,
                     style=None)
    b1 = ugfx.Button(120,
                     280,
                     120,
                     40,
                     "Try again >",
                     parent=window,
                     shape=ugfx.Button.RECT,
                     style=None)

    state['ui'].append(window)
    state['ui'].append(l1)
    state['ui'].append(l2)
    state['ui'].append(l3)
    state['ui'].append(b1)
    state['ui'].append(b2)
def prompt_option(options, index=0, text = "Please select one of the following:", 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(ugfx.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)
        window.text(5, 30, text, ugfx.BLACK)
        list_y = 50
    else:
        window.text(5, 10, text, ugfx.BLACK)

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

    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.selected_index(index)

    select_text = "A: " + select_text
    if none_text:
        none_text = "B: " + none_text

    button_select = ugfx.Button(5, ugfx.height() - 50, 140 if none_text else ugfx.width() - 25, 30 , select_text, parent=window)
    button_none = ugfx.Button(ugfx.width() - 160, ugfx.height() - 50, 140, 30 , none_text, parent=window) if none_text else None

    try:
        buttons.init()

        while True:
            pyb.wfi()
            ugfx.poll()
            if buttons.is_triggered("BTN_A"): return options[options_list.selected_index()]
            if button_none and buttons.is_triggered("BTN_B"): return None
            if button_none and buttons.is_triggered("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
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.º 11
0
 def __init__(self, text="Please Wait...", title="TiLDA"):
     self.window = ugfx.Container(30, 30,
                                  ugfx.width() - 60,
                                  ugfx.height() - 60)
     self.window.show()
     self.window.text(5, 10, title, TILDA_COLOR)
     self.window.line(0, 30, ugfx.width() - 60, 30, ugfx.BLACK)
     self.label = ugfx.Label(5,
                             40,
                             self.window.width() - 10,
                             ugfx.height() - 40,
                             text=text,
                             parent=self.window)
Exemplo n.º 12
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()
        ugfx.clear(ugfx.WHITE)

        # Buttons
        ugfx.input_init()
        self.init_buttons()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        ind_height = 46
        container_height = height - ind_height

        self.indicator = ugfx.Container(0,
                                        0,
                                        width,
                                        ind_height,
                                        style=styles.ibm_st)
        self.container = ugfx.Container(0,
                                        ind_height,
                                        width,
                                        container_height,
                                        style=styles.ibm_st)

        self.graph_basepos = container_height - 5

        # Sensor
        self.gas_sensor = ADC(Pin(34))
        self.gas_sensor.atten(ADC.ATTN_11DB)
        self.gas_sensor.width(ADC.WIDTH_12BIT)

        # Smooth
        self.Vos = 0

        # Buzzer
        self.buzzer = Buzzer()
Exemplo n.º 13
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()
        ugfx.clear(ugfx.WHITE)
        ugfx.input_init()

        # Buttons
        self.init_buttons()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        ind_height = 40
        ind_pos = height - ind_height

        self.indicator = ugfx.Container(0,
                                        ind_pos,
                                        width,
                                        ind_height,
                                        style=styles.ibm_st)
        self.container = ugfx.Container(0,
                                        0,
                                        width,
                                        ind_pos,
                                        style=styles.ibm_st)

        self.y_offset = ind_pos - 10

        # Sensor
        #self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32, vo=36, K=0.5, Voc=0.6)
        self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32,
                                                 vo=36,
                                                 K=0.5,
                                                 Voc=0.0)

        # Smooth
        self.Vos = 0.1  # 0.8
Exemplo n.º 14
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()
        ugfx.clear(ugfx.WHITE)

        # Buttons
        ugfx.input_init()
        self.init_buttons()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        ind_height = 66
        container_height = height - ind_height

        self.indicator = ugfx.Container(0,
                                        0,
                                        width,
                                        ind_height,
                                        style=styles.ibm_st)
        self.container = ugfx.Container(0,
                                        ind_height,
                                        width,
                                        container_height,
                                        style=styles.ibm_st)

        self.graph_basepos = container_height - 5

        # Sensor
        self.dust_sensor = gp2y1014au.GP2Y1014AU(iled=32,
                                                 vo=36,
                                                 K=0.5,
                                                 Voc=0.6)

        # Smooth
        self.Vos = 0
Exemplo n.º 15
0
def prompt_text(description, init_text = "", true_text="OK", false_text="Back", width = 300, height = 200, font=ugfx.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(int((ugfx.width()-width)/2), int((ugfx.height()-height)/2), width, height, style=style)

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

    if buttons.has_interrupt("BTN_MENU"):
        buttons.disable_interrupt("BTN_MENU")

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

    try:
        buttons.init()

        button_yes.attach_input(ugfx.BTN_MENU,0)
        if button_no: button_no.attach_input(ugfx.BTN_B,0)

        window.show()
        edit.set_focus()
        while True:
            pyb.wfi()
            ugfx.poll()
            #if buttons.is_triggered("BTN_A"): return edit.text()
            if buttons.is_triggered("BTN_B"): return None
            if buttons.is_triggered("BTN_MENU"): return 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.º 16
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.º 17
0
def screen(state):
    window = ugfx.Container(0, 0, 240, 320)
    window.show()

    try:
        # logo = http.get("https://i.imgur.com/0TjxEPs.png").raise_for_status().content
        ugfx.display_image(
            int((ugfx.width() - 164)/2),
            20,
            "tildr/biglogo.png")
    except:
        pass

    window.text(160, 100, "TILDR", ugfx.WHITE)
    window.text(0, 270, "Find your match @emfcamp ;)", ugfx.WHITE)
    window.text(45, 300, "Press A to begin", ugfx.WHITE)

    state['ui'].append(window)
Exemplo n.º 18
0
    def __init__(self):
        # initialize ugfx
        ugfx.init()

        # Container
        width = ugfx.width()
        height = ugfx.height()
        self.container = ugfx.Container(0,
                                        0,
                                        width,
                                        height,
                                        style=styles.ibm_st)

        # Status box
        self.create_status_box()

        # Nametag Image
        self.filename = '/nametag.gif'
Exemplo n.º 19
0
    def __init__(self, width=ugfx.width(), height=ugfx.height()):
        # Default font
        ugfx.set_default_font(self.default_font)

        # Container
        self.container = ugfx.Container(0,
                                        0,
                                        width,
                                        height,
                                        style=styles.ibm_st)

        # Title Label
        self.title_label = ugfx.Label(5,
                                      5,
                                      310,
                                      40,
                                      text='',
                                      parent=self.container)
Exemplo n.º 20
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.º 21
0
    def _init_container(self, x, y, title, path_to_icon):
        self.container = ugfx.Container(
            x - _half_icon_size - _padding, y - _half_icon_size - _padding,
            _padded_size, _padded_size + _text_height,
            style=_icon_container_style
        )

        #This doesn't work reliably at the moment
        #ugfx.Imagebox(
        #    _padding - 2, _padding - 2,
        #    _icon_size, _icon_size,
        #    parent=self.container, text=path_to_icon
        #)

        self.label = ugfx.Label(
            0, _padded_size,
            _padded_size, _text_height,
            title, parent=self.container, justification=ugfx.Label.CENTERTOP
        )

        self.container.enabled(self._selected)
def run_app(path):
	import buttons
	import ugfx
	import sys

	buttons.init()
	ugfx.init()
	ugfx.clear()

	if not buttons.has_interrupt("BTN_MENU"):
		buttons.enable_menu_reset()

	try:
		# Make libraries shipped by the app importable
		app_path = '/flash/' + '/'.join(path.split('/')[:-1])
		sys.path.append(app_path)

		mod = __import__(path)
		if "main" in dir(mod):
			mod.main()
	except Exception as e:
		import sys
		import uio
		import ugfx
		s = uio.StringIO()
		sys.print_exception(e, s)
		ugfx.clear()
		ugfx.set_default_font(ugfx.FONT_SMALL)
		w=ugfx.Container(0,0,ugfx.width(),ugfx.height())
		ugfx.Label(0,0,ugfx.width(),ugfx.height(),s.getvalue(),parent=w)
		w.show()
		raise(e)
	import stm
	stm.mem8[0x40002850] = 0x9C
	import pyb
	pyb.hard_reset()
Exemplo n.º 23
0
def prompt_boolean(text,
                   title="SHA2017",
                   true_text="Yes",
                   false_text="No",
                   width=296,
                   height=128,
                   font="Roboto_Regular12"):
    """A simple one and two-options dialog

	if 'false_text' is set to None only one button is displayed.
	If both 'false_text' and 'true_text' are given a boolean is returned, press B for false, A for true.

	The caller is responsible for flushing the display after processing the response.
	"""
    global wait_for_interrupt, button_pushed

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

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

    label = ugfx.Label(5,
                       30,
                       width - 10,
                       height - 80,
                       text=text,
                       parent=window)
    button_no = ugfx.Button(
        5, height - 40, width // 2 -
        15, 30, false_text, parent=window) if false_text else None
    button_yes = ugfx.Button(width // 2 + 5 if true_text else 5,
                             height - 40,
                             width // 2 - 15 if false_text else width - 10,
                             30,
                             true_text,
                             parent=window)
    button_yes.set_focus()

    ugfx.input_init()

    window.show()
    ugfx.set_lut(ugfx.LUT_NORMAL)
    ugfx.flush()

    def done(value):
        window.hide()
        window.destroy()
        button_yes.destroy()
        if button_no: button_no.destroy()
        label.destroy()
        return value

    if button_no: ugfx.input_attach(ugfx.BTN_B, pressed_b)
    ugfx.input_attach(ugfx.BTN_A, pressed_a)

    wait_for_interrupt = True
    while wait_for_interrupt:
        time.sleep(0.2)

    if button_pushed == "B": return done(False)
    if button_pushed == "A": return done(True)
Exemplo n.º 24
0
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())
Exemplo n.º 25
0
def home_main():
    global orientation, next_tick, tick

    ugfx.area(0, 0, 320, 240, sty_tb.background())

    ugfx.set_default_font(ugfx.FONT_MEDIUM)
    win_bv = ugfx.Container(0, 0, 80, 25, style=sty_tb)
    win_wifi = ugfx.Container(82, 0, 60, 25, style=sty_tb)
    win_name = ugfx.Container(0,
                              25,
                              320,
                              240 - 25 - 60,
                              style=dialogs.default_style_badge)
    win_text = ugfx.Container(0, 240 - 60, 320, 60, style=sty_tb)

    windows = [win_bv, win_wifi, win_text]

    obj_name = apps.home.draw_name.draw(0, 25, win_name)

    buttons.init()

    gc.collect()
    ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
    hook_feeback = ugfx.List(0,
                             0,
                             win_text.width(),
                             win_text.height(),
                             parent=win_text)

    win_bv.show()
    win_text.show()
    win_wifi.show()

    min_ctr = 28

    # Create external hooks so other apps can run code in the context of
    # the home screen.
    # To do so an app needs to have an external.py with a tick() function.
    # The tick period will default to 60 sec, unless you define something
    # else via a "period" variable in the module context (use milliseconds)
    # If you set a variable "needs_wifi" in the module context tick() will
    # only be called if wifi is available
    # If you set a variable "needs_wifi" in the module context tick() will
    # be called with a reference to a 25x25 pixel ugfx container that you
    # can modify
    external_hooks = []
    icon_x = 150
    for path in get_external_hook_paths():
        try:
            module = __import__(path)
            if not hasattr(module, "tick"):
                raise Exception("%s must have a tick function" % path)

            hook = {
                "name": path[5:-9],
                "tick": module.tick,
                "needs_wifi": hasattr(module, "needs_wifi"),
                "period":
                module.period if hasattr(module, "period") else 60 * 1000,
                "next_tick_at": 0
            }

            if hasattr(module, "needs_icon"):
                hook["icon"] = ugfx.Container(icon_x, 0, 25, 25)
                icon_x += 27

            external_hooks.append(hook)
        except Exception as e:  # Since we dont know what exception we're looking for, we cant do much
            print(
                "%s while parsing background task %s.  This task will not run! "
                % (type(e).__name__, path[5:-9]))
            sys.print_exception(e)
            continue  # If the module fails to load or dies during the setup, skip it

    backlight_adjust()

    inactivity = 0
    last_rssi = 0

    ## start connecting to wifi in the background
    wifi_timeout = 30  #seconds
    wifi_reconnect_timeout = 0
    try:
        wifi.connect(wait=False)
    except OSError:
        print("Creating default wifi settings file")
        wifi.create_default_config()

    while True:
        pyb.wfi()
        ugfx.poll()

        if (next_tick <= pyb.millis()):
            tick = True
            next_tick = pyb.millis() + 1000

        #if wifi still needs poking
        if (wifi_timeout > 0):
            if wifi.nic().is_connected():
                wifi_timeout = -1
                #wifi is connected, but if becomes disconnected, reconnect after 5 sec
                wifi_reconnect_timeout = 5
            else:
                wifi.nic().update()

        if tick:
            tick = False

            ledg.on()

            if (wifi_timeout > 0):
                wifi_timeout -= 1

            # change screen orientation
            ival = imu.get_acceleration()
            if ival['y'] < -0.5:
                if orientation != 0:
                    ugfx.orientation(0)
            elif ival['y'] > 0.5:
                if orientation != 180:
                    ugfx.orientation(180)
            if orientation != ugfx.orientation():
                inactivity = 0
                ugfx.area(0, 0, 320, 240, sty_tb.background())
                orientation = ugfx.orientation()
                for w in windows:
                    w.hide()
                    w.show()
                apps.home.draw_name.draw(0, 25, win_name)

            #if wifi timeout has occured and wifi isnt connected in time
            if (wifi_timeout == 0) and not (wifi.nic().is_connected()):
                print("Giving up on Wifi connect")
                wifi_timeout = -1
                wifi.nic().disconnect()  #give up
                wifi_reconnect_timeout = 30  #try again in 30sec

            wifi_connect = wifi.nic().is_connected()

            #if not connected, see if we should try again
            if not wifi_connect:
                if wifi_reconnect_timeout > 0:
                    wifi_reconnect_timeout -= 1
                    if wifi_reconnect_timeout == 0:
                        wifi_timeout = 60  #seconds
                        wifi.connect(wait=False)

            ledg.on()

            # display the wifi logo
            rssi = wifi.nic().get_rssi()
            if rssi == 0:
                rssi = last_rssi
            else:
                last_rssi = rssi

            draw_wifi(sty_tb.background(), rssi, wifi_connect,
                      wifi_timeout > 0, win_wifi)

            battery_percent = onboard.get_battery_percentage()
            draw_battery(sty_tb.background(), battery_percent, win_bv)

            inactivity += 1

            # turn off after some period
            # takes longer to turn off in the 'used' position
            if ugfx.orientation() == 180:
                inactivity_limit = 120
            else:
                inactivity_limit = 30
            if battery_percent > 120:  #if charger plugged in
                if ugfx.backlight() == 0:
                    ugfx.power_mode(ugfx.POWER_ON)
                ugfx.backlight(100)
            elif inactivity > inactivity_limit:
                low_power()
            else:
                backlight_adjust()

            ledg.off()

        for hook in external_hooks:
            try:
                if hook["needs_wifi"] and not wifi.nic().is_connected():
                    continue

                if hook["next_tick_at"] < pyb.millis():
                    text = None
                    if "icon" in hook:
                        text = hook["tick"](hook["icon"])
                    else:
                        text = hook["tick"]()
                    hook["next_tick_at"] = pyb.millis() + hook["period"]
                    if text:
                        if hook_feeback.count() > 10:
                            hook_feeback.remove_item(0)
                        hook_feeback.add_item(text)
                        if hook_feeback.selected_index() >= (
                                hook_feeback.count() - 2):
                            hook_feeback.selected_index(hook_feeback.count() -
                                                        1)
            except Exception as e:  # if anything in the hook fails to work, we need to skip it
                print(
                    "%s in %s background task. Not running again until next reboot! "
                    % (type(e).__name__, hook['name']))
                sys.print_exception(e)
                external_hooks.remove(hook)
                continue

        if buttons.is_pressed("BTN_MENU"):
            pyb.delay(20)
            break
        if buttons.is_pressed("BTN_A"):
            inactivity = 0
            tick = True
        if buttons.is_pressed("BTN_B"):
            inactivity = 0
            tick = True

    for hook in external_hooks:
        if "icon" in hook:
            hook["icon"].destroy()
    for w in windows:
        w.destroy()
    apps.home.draw_name.draw_destroy(obj_name)
    win_name.destroy()
    hook_feeback.destroy()
    if ugfx.backlight() == 0:
        ugfx.power_mode(ugfx.POWER_ON)
    ugfx.backlight(100)
    ugfx.orientation(180)

    #if we havnt connected yet then give up since the periodic function wont be poked
    if wifi_timeout >= 0:  # not (wifi.nic().is_connected()):
        wifi.nic().disconnect()
Exemplo n.º 26
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.º 27
0
def file_loader():
    width = ugfx.width()
    height = ugfx.height()
    buttons.disable_menu_reset()

    # Create visual elements
    win_header = ugfx.Container(0, 0, width, 30)
    win_files = ugfx.Container(0, 33, int(width / 2), height - 33)
    win_preview = ugfx.Container(
        int(width / 2) + 2, 33,
        int(width / 2) - 2, height - 33)
    components = [win_header, win_files, win_preview]
    ugfx.set_default_font(ugfx.FONT_TITLE)
    components.append(
        ugfx.Label(3, 3, width - 10, 29, "Choose App", parent=win_header))
    ugfx.set_default_font(ugfx.FONT_MEDIUM)
    options = ugfx.List(0,
                        30,
                        win_files.width(),
                        win_files.height() - 30,
                        parent=win_files)
    btnl = ugfx.Button(5, 3, 20, 20, "<", parent=win_files)
    btnr = ugfx.Button(win_files.width() - 7 - 20,
                       3,
                       20,
                       20,
                       ">",
                       parent=win_files)
    btnr.attach_input(ugfx.JOY_RIGHT, 0)
    btnl.attach_input(ugfx.JOY_LEFT, 0)
    components.append(options)
    components.append(btnr)
    components.append(btnl)
    ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)
    l_cat = ugfx.Label(30, 3, 100, 20, "Built-in", parent=win_files)
    components.append(l_cat)
    components.append(
        ugfx.Button(10,
                    win_preview.height() - 25,
                    20,
                    20,
                    "A",
                    parent=win_preview))
    components.append(
        ugfx.Label(35,
                   win_preview.height() - 25,
                   50,
                   20,
                   "Run",
                   parent=win_preview))
    components.append(
        ugfx.Button(80,
                    win_preview.height() - 25,
                    20,
                    20,
                    "B",
                    parent=win_preview))
    components.append(
        ugfx.Label(105,
                   win_preview.height() - 25,
                   100,
                   20,
                   "Back",
                   parent=win_preview))
    components.append(
        ugfx.Button(10,
                    win_preview.height() - 50,
                    20,
                    20,
                    "M",
                    parent=win_preview))
    components.append(
        ugfx.Label(35,
                   win_preview.height() - 50,
                   100,
                   20,
                   "Pin/Unpin",
                   parent=win_preview))
    ugfx.set_default_font(ugfx.FONT_SMALL)
    author = ugfx.Label(1,
                        win_preview.height() - 78,
                        win_preview.width() - 3,
                        20,
                        "by: ",
                        parent=win_preview)
    desc = ugfx.Label(3,
                      1,
                      win_preview.width() - 10,
                      win_preview.height() - 83,
                      "",
                      parent=win_preview,
                      justification=ugfx.Label.LEFTTOP)
    components.append(author)
    components.append(desc)

    app_to_load = None

    pinned = database_get("pinned_apps", [])
    catergories = get_local_app_categories()
    c_ptr = 0

    try:
        win_header.show()
        win_files.show()
        win_preview.show()

        pinned = database_get("pinned_apps", [])
        #	apps = []
        apps_path = []

        if is_dir("apps"):
            for app in os.listdir("apps"):
                path = "apps/" + app
                if is_dir(path) and is_file(path + "/main.py"):
                    apps_path.append(path + "/main.py")
        if is_dir("examples"):
            for app in os.listdir("examples"):
                path = "examples/" + app
                if is_file(path) and path.endswith(".py"):
                    apps_path.append(path)

        displayed_apps = update_options(options, catergories[c_ptr], pinned)

        index_prev = -1

        while True:
            pyb.wfi()
            ugfx.poll()

            if index_prev != options.selected_index():
                if options.selected_index() < len(displayed_apps):
                    author.text("by: %s" %
                                displayed_apps[options.selected_index()].user)
                    desc.text(
                        displayed_apps[options.selected_index()].description)
                index_prev = options.selected_index()

            if buttons.is_triggered("JOY_LEFT"):
                if c_ptr > 0:
                    c_ptr -= 1
                    btnl.set_focus()
                    l_cat.text(catergories[c_ptr])
                    displayed_apps = update_options(options,
                                                    catergories[c_ptr], pinned)
                    index_prev = -1

            if buttons.is_triggered("JOY_RIGHT"):
                if c_ptr < len(catergories) - 1:
                    c_ptr += 1
                    btnr.set_focus()
                    l_cat.text(catergories[c_ptr])
                    displayed_apps = update_options(options,
                                                    catergories[c_ptr], pinned)
                    index_prev = -1

            if buttons.is_triggered("BTN_MENU"):
                app = displayed_apps[options.selected_index()]
                if app.folder_name in pinned:
                    pinned.remove(app.folder_name)
                else:
                    pinned.append(app.folder_name)
                update_options(options, catergories[c_ptr], pinned)
                database_set("pinned_apps", pinned)

            if buttons.is_triggered("BTN_B"):
                return None

            if buttons.is_triggered("BTN_A"):
                return displayed_apps[options.selected_index()]

    finally:
        for component in components:
            component.destroy()
Exemplo n.º 28
0
     gc.collect()
     pyb.info()
     print("Loading: %s" % app_to_load)
     mod = __import__(app_to_load.main_path[:-3])
     if "main" in dir(mod):
         mod.main()
 except Exception as e:
     s = uio.StringIO()
     sys.print_exception(e, s)
     u = pyb.USB_VCP()
     if u.isconnected():
         raise (e)
     else:
         ugfx.clear()
         ugfx.set_default_font(ugfx.FONT_SMALL)
         w = ugfx.Container(0, 0, ugfx.width(), ugfx.height())
         l = ugfx.Label(0,
                        0,
                        ugfx.width(),
                        ugfx.height(),
                        s.getvalue(),
                        parent=w)
         w.show()
         while True:
             pyb.wfi()
             if (buttons.is_triggered("BTN_B")) or (buttons.is_triggered(
                     "BTN_B")) or (buttons.is_triggered("BTN_MENU")):
                 break
         #str=s.getvalue().split("\n")
         #if len(str)>=4:
         #out = "\n".join(str[4:])
Exemplo n.º 29
0
def prompt_text(description,
                init_text="",
                true_text="OK",
                false_text="Back",
                width=300,
                height=200,
                font="Roboto_BlackItalic24"):
    """Shows a dialog and keyboard that allows the user to input/change a string

	Returns None if user aborts with button B

	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 okay(evt):
        # We'd like promises here, but for now this should do
        global wait_for_interrupt
        button_pushed = "A"
        wait_for_interrupt = False

    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=okay)
    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(
                    ugfx.BTN_B, lambda pressed: vkey_backspace()
                    if pressed else 0)
                ugfx.input_attach(
                    ugfx.BTN_A, 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(ugfx.BTN_A, pressed_a)
                ugfx.input_attach(ugfx.BTN_B, pressed_b)
                focus = (2 if button_no else 0)
            else:
                button_no.set_focus()
                kb.enabled(0)
                ugfx.input_attach(ugfx.BTN_A, pressed_a)
                ugfx.input_attach(ugfx.BTN_B, pressed_b)
                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
    while wait_for_interrupt:
        time.sleep(0.2)

    def done(value):
        window.hide()
        window.destroy()
        button_yes.destroy()
        if button_no: button_no.destroy()
        label.destroy()
        kb.destroy()
        edit.destroy()
        return value

    if (focus == 0 and no_button) or button_pushed == "B": return done(False)
    return done(edit.text())
Exemplo n.º 30
0
hi = ugfx.height()

ugfx.clear()

s = ugfx.Style()

s.set_enabled([
    ugfx.BLACK,
    ugfx.html_color(0xA66FB0),
    ugfx.html_color(0x5e5e5e), ugfx.RED
])
s.set_background(ugfx.html_color(0xFFFFFF))

ugfx.set_default_style(s)

win_header = ugfx.Container(0, 0, wi, 33, style=s)
win_legend = ugfx.Container(0, hi - 30, wi, 30, style=s)

toplot = ['vbat', 'vunreg', 'light', 'rssi']
# scale  to fit on the y scale (range 0->150)
scale_m = [75, 75, 0.4, 1]
scale_c = [-255, -255, 0, 100]
colour = [ugfx.RED, ugfx.ORANGE, ugfx.YELLOW, ugfx.BLUE]

buttons.disable_menu_reset()

ugfx.set_default_font(ugfx.FONT_TITLE)
title = ugfx.Label(3, 3, wi - 10, 45, "Log Viewer", parent=win_header)
ugfx.set_default_font(ugfx.FONT_SMALL)
chk_upload = ugfx.Checkbox(190,
                           3,