示例#1
0
文件: nomore.py 项目: mjms3/emf2018
def actions(state):
    if buttons.is_triggered(Buttons.BTN_B) or buttons.is_triggered(
            Buttons.JOY_Right):
        state['next'] = "NEXT_PERSON"
    if buttons.is_triggered(Buttons.BTN_A) or buttons.is_triggered(
            Buttons.JOY_Left):
        state['next'] = "PROFILE"
示例#2
0
文件: main.py 项目: Kimbsy/EMF_20016
def viewmsg():
	msgid = db.get('msgseq')
	msg = inbox.get(msgid)
	if msg == None:
		ugfx.set_default_font(ugfx.FONT_SMALL)	
		ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
		ugfx.text(40,100,"NO MESSAGES",ugfx.BLUE)
		pyb.delay(1000)
		return
	else:
		data = json.loads(msg)
		printmsg(data['sender'], data['payload'], data['ts'])
	while True:
		if buttons.is_triggered("JOY_UP"):
			print(msgid)
			msgid -= 1
			msg = inbox.get(msgid)
			if msg != None:
				data = json.loads(msg)
				printmsg(data['sender'], data['payload'], data['ts'])
			else:
				msgid += 1
		if buttons.is_triggered("JOY_DOWN"):
			print(msgid)
			msgid += 1
			msg = inbox.get(msgid)
			if msg != None:
				data = json.loads(msg)
				printmsg(data['sender'], data['payload'], data['ts'])
			else:
				msgid -= 1
		if buttons.is_triggered("BTN_B"):
			display()
			return
示例#3
0
def main_screen(my_profile):
    while True:
        next_person(my_profile)
        while True:
            if buttons.is_triggered(Buttons.BTN_Menu):
                return False
            if buttons.is_triggered(Buttons.BTN_B) or buttons.is_triggered(Buttons.JOY_Right):
                break
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()
示例#5
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
	"""
	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()
示例#6
0
    def welcome(self):

        exit_welcome = pyb.millis() + 30000

        if self.__debug:
            print("emf_hub_mon: Drawing the welcome display")

        self.draw_background(ugfx.WHITE)

        self.__text_centre("Shows who is transmitting on the",
                           ugfx.FONT_MEDIUM, ugfx.BLACK, 115)
        self.__text_centre("\"EMF HUB\", a hub for amateur radio!",
                           ugfx.FONT_MEDIUM, ugfx.BLACK, 135)

        self.__text_centre("Press A or B to continue", ugfx.FONT_MEDIUM,
                           ugfx.BLACK, 220)

        while pyb.millis() < exit_welcome:

            self.__status.update()

            if buttons.is_triggered('BTN_A') or buttons.is_triggered('BTN_B'):
                print("emf_hub_mon: Button pressed - exiting welcome screen")
                break

        self.draw_background(ugfx.WHITE)

        ugfx.set_default_font(ugfx.FONT_MEDIUM)
        ugfx.text(20, 115, "More Info: http://hub.emfhams.org", ugfx.BLACK)
        ugfx.text(60, 155, "Brought to you by:", ugfx.BLACK)
        ugfx.text(15, 175, "2E0SIP, MM0MRU and the EMF Hams", ugfx.BLACK)

        self.__text_centre("Press A or B to continue", ugfx.FONT_MEDIUM,
                           ugfx.BLACK, 220)

        exit_welcome = pyb.millis() + 30000

        while pyb.millis() < exit_welcome:

            self.__status.update()

            if buttons.is_triggered('BTN_A') or buttons.is_triggered('BTN_B'):
                print("emf_hub_mon: Button pressed - exiting welcome screen")
                break

        if not self.__config.get('demo'):
            print("emf_hub_mon: Setting first_boot false")
            self.__config.set('first_boot', False)
            self.__config.flush()
        else:
            print("emf_hub_mon: Demo mode, skipping setting first_boot")
示例#7
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
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
示例#9
0
def showPage():
    global current_page
    # avoid out of bounds errors
    current_page = max(1, min(current_page, total_pages))
    
    start = (current_page - 1) * APPS_PER_PAGE
    end = start + APPS_PER_PAGE
    apps_on_current_page = all_apps[start:end]

    # Refresh page
    ugfx.clear(ugfx.html_color(EMF_PURPLE))

    # Write current page number and arrows
    ugfx.Label(0, 20, ugfx.width(), 20, "Page {} of {}".format(current_page, total_pages), justification=ugfx.Label.CENTER)

    if current_page > 1:
        ugfx.fill_polygon(10, 16, [[0, 10], [15, 20], [15, 0]], ugfx.WHITE)
        
    if current_page < total_pages:
        ugfx.fill_polygon(ugfx.width() - 30, 16, [[0, 0], [15, 10], [0, 20]], ugfx.WHITE)
    
    # Write app numbers and names
    i = 0
    yOffset = 45
    xOffset = 0
    for a in apps_on_current_page:
        # xOffset = (i % 3) * 8  # offset lines to match the physical layout of the keypad
        ugfx.area(20 + xOffset, yOffset + 2, 20, 20, ugfx.WHITE)
        ugfx.text(23 + xOffset, yOffset + 3, keypadLabels[i] + " ", EMF_PURPLE)

        ugfx.Label(46 + xOffset, yOffset + 3, ugfx.width(), 20, a['title'], justification=ugfx.Label.LEFT)
        yOffset = yOffset + 22
        i = i + 1

    while True:
        for key in keypad:
            keyIndex = keypad.index(key)
            if buttons.is_pressed(key) and (keyIndex < len(apps_on_current_page)):
                apps_on_current_page[keyIndex]['app'].boot()
                break

        if buttons.is_triggered(Buttons.JOY_Right) and (current_page is not total_pages):
            current_page = current_page + 1
            return
        if buttons.is_triggered(Buttons.JOY_Left) and (current_page is not 1):
            current_page = current_page - 1
            return
示例#10
0
def do_circle_of_life():
    ugfx.init()
    buttons.init()
    buttons.disable_menu_reset()

    colour = get_colour()
    grid = Grid(ugfx.width(), ugfx.height(), colour_fore = colour, colour_back = COLOUR_BACK)
    grid.randomise()

    ugfx.clear(COLOUR_BACK)

    hash_count = 0
    hash_last = None
    hash_last_last = None
    while True:
        # display
        hash_val = grid.display_badge()

        # randomise, if needed
        if hash_val == hash_last_last:
            hash_count += 1

            if hash_count == HASH_COUNT_LIMIT:
                colour = get_colour(colour)
                grid.set_colour(colour)
                grid.randomise()
                hash_count = 0

        else:
            hash_count = 0

        hash_last_last = hash_last
        hash_last = hash_val

        # process next generation
        grid.next_generation()
        grid.swap_cell_buffers()

        # buttons
        pyb.wfi()
        if buttons.is_triggered("BTN_A") or buttons.is_triggered("BTN_B"):
            colour = get_colour(colour)
            grid.set_colour(colour)
            grid.randomise()

        if buttons.is_triggered("BTN_MENU"):
            break
示例#11
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()
示例#12
0
def a_was_pushed():
    ugfx.clear(ugfx.html_color(0x000000))
    ugfx.orientation(270)
    ugfx.text(5,5, "You pressed A", ugfx.WHITE)
    ugfx.text(5,45, "Press MENU to exit", ugfx.WHITE)
    while True:
        if buttons.is_triggered(Buttons.BTN_Menu):
            break
示例#13
0
def prompt_boolean(text, title="TiLDA", true_text="Yes", false_text="No", width = 260, height = 180, font=ugfx.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(ugfx.FONT_MEDIUM_BOLD)
	window = ugfx.Container((ugfx.width() - width) // 2, (ugfx.height() - height) // 2,  width, height, style=style)
	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(ugfx.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:
		buttons.init()

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

		window.show()

		while True:
			pyb.wfi()
			if buttons.is_triggered("BTN_A"): return True
			if buttons.is_triggered("BTN_B"): return False

	finally:
		window.hide()
		window.destroy()
		button_yes.destroy()
		if button_no: button_no.destroy()
		label.destroy()
示例#14
0
def wait_for_exit():
    global chk_upload
    buttons.init()
    while True:
        pyb.wfi()
        if buttons.is_triggered("BTN_B"):
            break

    database_set("stats_upload", chk_upload.checked())
示例#15
0
def wait_for_exit():
	global chk_upload
	buttons.init()
	while True:
		pyb.wfi()
		if buttons.is_triggered("BTN_B"):
			break;

	database_set("stats_upload", chk_upload.checked())
示例#16
0
def sleep_or_exit(interval=0.5):
    # todo: do this better - check button multiple times and sleep for only a short while
    if buttons.is_triggered(tilda.Buttons.BTN_Menu):
        clean_up()
        launcher = "launcher"
        try:
            with open("default_launcher.txt", "r") as dl:
                launcher = dl.readline()
        except OSError:
            pass
        App(launcher).boot()
    sleep.sleep(interval)
示例#17
0
def main():

    init()

    start()

    write_some_text()

    while True:
        if buttons.is_triggered(Buttons.BTN_A):
            a_was_pushed():

    app.restart_to_default()
示例#18
0
def handle_keypad(edit, numeric):
    global last_key, last_keytime
    threshold = 1000
    keymap = {
        buttons.Buttons.BTN_0: [" ", "0"],
        buttons.Buttons.BTN_1: ["1"],
        buttons.Buttons.BTN_2: ["a", "b", "c", "2"],
        buttons.Buttons.BTN_3: ["d", "e", "f", "3"],
        buttons.Buttons.BTN_4: ["g", "h", "i", "4"],
        buttons.Buttons.BTN_5: ["j", "k", "l", "5"],
        buttons.Buttons.BTN_6: ["m", "n", "o", "6"],
        buttons.Buttons.BTN_7: ["p", "q", "r", "s", "7"],
        buttons.Buttons.BTN_8: ["t", "u", "v", "8"],
        buttons.Buttons.BTN_9: ["w", "x", "y", "z", "9"],
        buttons.Buttons.BTN_Hash: ["#"],
        buttons.Buttons.BTN_Star: ["*", "+"],
    }

    for key, chars in keymap.items():
        if buttons.is_triggered(key):
            if numeric:
                edit.text(edit.text() + chars[-1])
            elif key != last_key:
                edit.text(edit.text() + chars[0])
            else:
                if last_keytime is None or (time.ticks_ms() -
                                            last_keytime) > threshold:
                    edit.text(edit.text() + chars[0])
                else:
                    last_char = edit.text()[-1]
                    try:
                        last_index = chars.index(last_char)
                    except ValueError:
                        # not sure how we get here...
                        return
                    next_index = (last_index + 1) % len(chars)
                    edit.text(edit.text()[:-1] + chars[next_index])
            last_key = key
            last_keytime = time.ticks_ms()
示例#19
0
def nownext():
	ugfx.text(50,120,"Loading... ",ugfx.YELLOW)
	data = getdata()
	venue = list()
	for i in data.keys():
	    venue.append(i)
	venue = sorted(venue)
	print(venue)
	vpos = 0
	hpos = 0
	showevent(venue[vpos], data[venue[vpos]][hpos])
	while True:
		if buttons.is_triggered("JOY_RIGHT"):
			print(vpos)
			vpos += 1
			if vpos > len(venue)-1:
				vpos -= 1
			else:
				pass
			showevent(venue[vpos], data[venue[vpos]][hpos])
		if buttons.is_triggered("JOY_LEFT"):
			print(vpos)
			vpos -= 1
			if vpos < 0:
				vpos = 0
			else:
				pass
			showevent(venue[vpos], data[venue[vpos]][hpos])
		if buttons.is_triggered("JOY_DOWN"):
			print(hpos)
			hpos = 1
			showevent(venue[vpos], data[venue[vpos]][hpos])
		if buttons.is_triggered("JOY_UP"):
			print(hpos)
			hpos = 0
			showevent(venue[vpos], data[venue[vpos]][hpos])
		if buttons.is_triggered("BTN_A"):
			# Need to Implement fetching description by ID here
			pass
		if buttons.is_triggered("BTN_B"):
			mainscreen()
			return
示例#20
0
def nownext():
    ugfx.text(50, 120, "Loading... ", ugfx.YELLOW)
    data = getdata()
    venue = list()
    for i in data.keys():
        venue.append(i)
    venue = sorted(venue)
    print(venue)
    vpos = 0
    hpos = 0
    showevent(venue[vpos], data[venue[vpos]][hpos])
    while True:
        if buttons.is_triggered("JOY_RIGHT"):
            print(vpos)
            vpos += 1
            if vpos > len(venue) - 1:
                vpos -= 1
            else:
                pass
            showevent(venue[vpos], data[venue[vpos]][hpos])
        if buttons.is_triggered("JOY_LEFT"):
            print(vpos)
            vpos -= 1
            if vpos < 0:
                vpos = 0
            else:
                pass
            showevent(venue[vpos], data[venue[vpos]][hpos])
        if buttons.is_triggered("JOY_DOWN"):
            print(hpos)
            hpos = 1
            showevent(venue[vpos], data[venue[vpos]][hpos])
        if buttons.is_triggered("JOY_UP"):
            print(hpos)
            hpos = 0
            showevent(venue[vpos], data[venue[vpos]][hpos])
        if buttons.is_triggered("BTN_A"):
            # Need to Implement fetching description by ID here
            pass
        if buttons.is_triggered("BTN_B"):
            mainscreen()
            return
示例#21
0
        except:
            pass
        item.destroy()

    state['ui'] = []


state['profile'] = get_profile()

while state['running']:

    # Move to next screen
    if state['next']:
        destroy(state)
        nxt = state['next']
        state['screen'] = nxt
        state['next'] = None

        clear()
        screens[nxt]['render'](state)

    sleep.wfi()

    s = state['screen']
    screens[s]['actions'](state)

    if buttons.is_triggered(Buttons.BTN_Menu):
        state['running'] = False

app.restart_to_default()
示例#22
0
def game_of_life():
	width = 40
	height = 30
	cell_width = 8
	cell_height = 8
	grid = [[0 for x in range(height)] for y in range(width)]
	
	def seed():
		for x in range(0, width-1):
			for y in range(0, height-1):
				if pyb.rng() % 2 == 1:
					grid[x][y] = 1
				else:
					grid[x][y] = 0
	
	def display():
		for x in range(0, width-1):
			for y in range(0, height-1):
				if grid[x][y] == 1:
					ugfx.area((x-1)*cell_width+1,(y-1)*cell_height, cell_width, cell_height, ugfx.BLACK)
				else:
					ugfx.area((x-1)*cell_width+1,(y-1)*cell_height, cell_width, cell_height, ugfx.WHITE)
		
	def step():
		changed = 0
		for x in range(1, width):
			for y in range(1, height):
				n = 0
				# 1. tl
				if x > 0 and y > 0 and grid[x-1][y-1] == 1:
					n += 1
				# 2. t
				if y > 0 and grid[x][y-1] == 1:
					n += 1
				# 3. tr
				if x < width-1 and y > 0 and grid[x+1][y-1] == 1:
					n += 1
				# 4. l
				if x > 0 and grid[x-1][y] == 1:
					n += 1
				# 5. r
				if x < width-1 and grid[x+1][y] == 1:
					n += 1
				# 6. bl
				if x > 0 and y < height-1 and grid[x-1][y+1] == 1:
					n += 1
				# 7. b
				if y < height-1 and grid[x][y-1] == 1:
					n += 1
				# 8. br
				if x < width-1 and y < height-1 and grid[x+1][y+1] == 1:
					n += 1
				
				if grid[x][y] == 1:
					changed  += 1
					if n < 2:
						grid[x][y] = 0
					elif n > 3 :
						grid[x][y] = 0
					else:
						grid[x][y] = 1
				elif n == 3:
					grid[x][y] = 1
					changed += 1
		
		if changed > 0:
			return True
		else:
			return False
					
	seed()
	g = 0
	while True:
		g += 1
		display()
		if step() is False or buttons.is_triggered("BTN_A") or g > 50:
			seed()
			g = 0
示例#23
0
    shiftX += 1
    shiftY += 1


def drawSquare(x, y, colour):
    ugfx.area(x * grid_size, y * grid_size, grid_size, grid_size, colour)


def badgeQuit():
    restart_to_default()


# Main Loop
startDisco = False
while True:
    if buttons.is_triggered(buttons.Buttons.BTN_A):
        startDisco = True
        drawDiscoFrame()
    elif buttons.is_triggered(buttons.Buttons.BTN_B):
        startDisco = False
        break
    elif buttons.is_triggered(tilda.Buttons.BTN_Menu):
        clean_up()
        App("launcher").boot()

    if startDisco:
        drawRandomSquare()
        drawRandomSquare()
        drawRandomSquare()
        drawRandomSquare()
        drawRandomSquare()
示例#24
0
    ugfx.set_default_font(ugfx.FONT_MEDIUM)

    ugfx.fill_circle(50,50, 20, ugfx.WHITE)
    ugfx.fill_circle(50, 100, 20, ugfx.WHITE)

    ugfx.text(45, 45, "A", ugfx.RED)
    ugfx.text(45, 95, "B", ugfx.RED)

    ugfx.text(95, 45, "Flash the lights", ugfx.WHITE)
    ugfx.text(95, 95, "Disco Inferno", ugfx.WHITE)

    ugfx.fill_polygon(270,50, [ [0,0], [40,0], [40, 175], [0, 175] ], ugfx.RED)#  , [230, 100], [230, 60]
    ugfx.fill_polygon(270,50, [ [0,0], [-20,10], [-20, 50], [0, 40] ], ugfx.RED)#  , [230, 100], [230, 60]

    ugfx.area(283, 61, 14, 10, ugfx.WHITE)
    ugfx.area(283, 79, 14, 10, ugfx.WHITE)
    ugfx.area(283, 97, 14, 10, ugfx.WHITE)
    ugfx.area(283, 115, 14, 10, ugfx.WHITE)
    ugfx.area(283, 133, 14, 10, ugfx.WHITE)
    ugfx.area(283, 151, 14, 10, ugfx.WHITE)
    ugfx.area(283, 169, 14, 10, ugfx.WHITE)
    ugfx.area(283, 187, 14, 10, ugfx.WHITE)


drawui()
while True:
    if buttons.is_triggered("BTN_A"):
        wiggle()
    elif buttons.is_triggered("BTN_B"):
        disco()
示例#25
0
ap = ""
pwd = ""
try:
	de = wifi.connection_details()
	ap = de["ssid"]
	pwd = de["pw"]
except:
	pass

try:

	_move_arrow(0, sty.background(), win_main)

	while True:

		if buttons.is_triggered("BTN_B"):
			break

		if buttons.is_triggered("BTN_A"):
			if cursor_loc == 0:
				new_ap = prompt_text("Enter the access point name", init_text = ap, width = 310, height = 220)
				if new_ap:
					ap = new_ap
					lname.text(ap)
			if cursor_loc == 1:
				new_pwd = prompt_text("Enter the password", init_text = pwd, width = 310, height = 220)
				if new_pwd:
					pwd = new_pwd
					lpwd.text(pwd)
			_move_arrow(0, sty.background(), win_main)
示例#26
0
    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:])
            #dialogs.notice(out, width=wi-10, height=hi-10)
    onboard.semihard_reset()

    #deinit ugfx here
    #could hard reset here too
示例#27
0
ugfx.set_default_font(ugfx.FONT_SMALL)
for p in toplot:
	ugfx.Label(x+13,0,50,25,p,parent=win_legend)
	win_legend.thickline(x,13,x+10,13,colour[ i ],3,1,)
	i += 1
	x += 75

plot(seeks[0],zoom[0],xscale)

plot_index = 0
buttons.init()
while True:
	pyb.wfi()
	ugfx.poll()
	inc = 0
	if buttons.is_triggered("JOY_RIGHT"):
		inc = -1
	if buttons.is_triggered("JOY_LEFT"):
		inc = 1
	if buttons.is_triggered("BTN_B"):
		break;

	if not inc == 0:
		inc += plot_index
		if inc < 0:
			pass
		elif inc >= len(zoom):
			pass
		elif seeks[0] == 0: ## dont allow zoom out if we dont have enough data
			pass
		else:
示例#28
0
ugfx.clear(ugfx.BLACK)
ugfx.text(80,40,"Adventure!",ugfx.WHITE)
ugfx.text(20,100,"Escape from the Castle!",ugfx.RED)
play_theme()
pyb.delay(2000)
room_1()
###start at this room


while True:
	playing=1

	while playing:
	
		if buttons.is_triggered("JOY_UP"):
			if room == 1:
				room=2
				room_2()
			elif room == 3:
				room=5
				room_5()
			elif room==9:
				room=8
				room_8()

		if buttons.is_triggered("JOY_DOWN"):
			if room == 2:
				room=1
				room_1()
			elif room==8:
示例#29
0
button B\t: run/pause
joystick\t: resets the game
menu\t: quits app
Shall we play a game professor Falken?
""", title='Conway\'s Game of Life', true_text="Play", false_text="Quit")

random_grid()
draw_grid()


running = False

while playing:
	while True:
		# pyb.wfi() # Some low power stuff
		if buttons.is_triggered('BTN_A'):
			update()
			draw_grid()

		if buttons.is_triggered('BTN_B'):
			running = not running

		if buttons.is_triggered('JOY_CENTER'):
			running = False
			random_grid()
			draw_grid()

		if running:
			update()
			draw_grid()
			ugfx.text(15, 15, 'Runnig...', ugfx.YELLOW)
示例#30
0
    ugfx.orientation(90)  # Draw for others
    drawLogo()
    playMusic(9500)
    blankScreen()


#############
#############
#############
boot()

enableLights = False
enableScroll = True
while True:
    # Toggle lights
    if buttons.is_triggered(Buttons.BTN_B):
        enableLights = not enableLights
        neopix.display([0, 0])  # Lights off

    # Play music
    elif buttons.is_triggered(Buttons.BTN_A):
        neopix.display([0, 0])  # Lights off
        drawTutorial()
        drawLogo()
        playMusic()

    # Toggle scroll
    elif buttons.is_triggered(Buttons.JOY_Center):
        enableScroll = not enableScroll
        if not enableScroll:
            blankScreen()
ballx=width/2              # ball x position (relative to the ball center)
bally=height/4             # ball y position (relative to the ball center)
dx=.01*width               # motion in the x axis
dy=0.0                     # motion in the y axis
ballcx = 12*radius/5       # ball x diameter including the shadow
ballcy = 21*radius/10      # ball y diameter including the shadow

# The clipping window for this frame.
minx = miny = 0
maxx = width
maxy = height

def invsqrt(x):
    return x**-1/2

while not buttons.is_triggered("BTN_MENU"):
    # Draw one frame
    ugfx.stream_start(minx, miny, maxx-minx, maxy-miny)
    for x in range(minx, maxx):
        g = (ballx-x)*ii
        for y in range(miny, maxy):
            h = (bally-y)*ii
            f=-.3*g+.954*h
            if g*g < 1-h*h:
                # The inside of the ball
                if ((int((9-spin+(.954*g+.3*h)*invsqrt(1-f*f)))+int((2+f*2))&1)):
                    colour = BALLCOLOR1
                else:
                    colour = BALLCOLOR2
            else:
                # The background (walls and floor)
示例#32
0
def quit_loop():
    while True:
        if buttons.is_triggered(Buttons.BTN_Menu):
            return False
示例#33
0
文件: main.py 项目: core-dd/cw_flash
    if character_buffer is '': # fill new character
        pyb.delay(SIGN_SCALING*PAUSE_CHARACTER)
        character_buffer = CODEBOOK[MSG[msg_pointer]]
        msg_pointer = (msg_pointer + 1) % len(MSG)

    # send character

    if character_buffer[0] is '-':
        dash()
    elif character_buffer[0] is '.':
        dot()
    else:
        pyb.delay(SIGN_SCALING*PAUSE_WORD)

    if len(character_buffer) > 1:
        character_buffer = character_buffer[1:]
    else:
        character_buffer = ''

    pyb.wfi()
    if buttons.is_triggered("BTN_MENU") or buttons.is_triggered("BTN_B") or buttons.is_triggered("JOY_CENTER"):
        break;
    if buttons.is_triggered("BTN_A"):
        AF = not AF
    if buttons.is_triggered("JOY_DOWN"):
        SIGN_SCALING += 20
    if buttons.is_triggered("JOY_UP"):
        SIGN_SCALING -= 20

ugfx.clear()
示例#34
0
文件: splash.py 项目: mjms3/emf2018
def actions(state):
    if buttons.is_triggered(Buttons.BTN_A):
        if state['profile'] is None:
            state['next'] = "PROFILE"
        else:
            state['next'] = "NEXT_PERSON"
示例#35
0
def error_actions(state):
    if buttons.is_triggered(Buttons.BTN_A):
        state['next'] = "SPLASH"
示例#36
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:])
			#dialogs.notice(out, width=wi-10, height=hi-10)
	onboard.semihard_reset()

	#deinit ugfx here
	#could hard reset here too
示例#37
0
ballx=width/2              # ball x position (relative to the ball center)
bally=height/4             # ball y position (relative to the ball center)
dx=.01*width               # motion in the x axis
dy=0.0                     # motion in the y axis
ballcx = 12*radius/5       # ball x diameter including the shadow
ballcy = 21*radius/10      # ball y diameter including the shadow

# The clipping window for this frame.
minx = miny = 0
maxx = width
maxy = height

def invsqrt(x):
    return x**-1/2

while not buttons.is_triggered("BTN_MENU"):
    # Draw one frame
    ugfx.stream_start(minx, miny, maxx-minx, maxy-miny)
    for x in range(minx, maxx):
        g = (ballx-x)*ii
        for y in range(miny, maxy):
            h = (bally-y)*ii
            f=-.3*g+.954*h
            if g*g < 1-h*h:
                # The inside of the ball
                if ((int((9-spin+(.954*g+.3*h)*invsqrt(1-f*f)))+int((2+f*2))&1)):
                    colour = BALLCOLOR1
                else:
                    colour = BALLCOLOR2
            else:
                # The background (walls and floor)
示例#38
0
ival = imu.get_acceleration()
if ival['y'] < 0:
	ugfx.orientation(0)
else:
	ugfx.orientation(180)


buttons.init()
if not onboard.is_splash_hidden():
	splashes = ["splash1.bmp"]
	for s in splashes:
		ugfx.display_image(0,0,s)
		delay = 2000
		while delay:
			delay -= 1
			if buttons.is_triggered("BTN_MENU"):
				break;
			if buttons.is_triggered("BTN_A"):
				break;
			if buttons.is_triggered("BTN_B"):
				break;
			if buttons.is_triggered("JOY_CENTER"):
				break;
			pyb.delay(1)


onboard.hide_splash_on_next_boot(False)

ugfx.set_default_style(dialogs.default_style_badge)

sty_tb = ugfx.Style(dialogs.default_style_badge)
示例#39
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()
示例#40
0
            disp_eaten_food(food[0], food[1], body_colour)
            food = randn_square()
            disp_square(food[0], food[1], food_colour)
            score = score + 1

        disp_body_straight(body_x[-1], body_y[-1], orient, body_colour)

        if ((body_x[-1] >= edge_x) or (body_x[-1] < 0)
                or (body_y[-1] >= edge_y) or (body_y[-1] < 0)):
            break

        pyb.delay(100)
    return score


playing = 1
while playing:
    score = one_round()
    ugfx.area(0, 0, ugfx.width(), ugfx.height(), 0)
    ugfx.text(30, 30, "GAME OVER Score: %d" % (score), 0xFFFF)
    ugfx.text(30, 60, "Press A to play again", 0xFFFF)
    ugfx.text(30, 90, "Press MENU to quit", 0xFFFF)
    while True:
        pyb.wfi()
        if buttons.is_triggered("BTN_A"):
            break

        if buttons.is_triggered("BTN_MENU"):
            playing = 0  #pyb.hard_reset()
            break
示例#41
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()
示例#42
0
def sleep_or_exit(interval=0.5):
    # todo: do this better - check button multiple times and sleep for only a short while
    if buttons.is_triggered(tilda.Buttons.BTN_Menu):
        clean_up()
        App("launcher").boot()
    sleep.sleep(interval)
示例#43
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()
示例#44
0
def quick_launch_screen():
	wi = ugfx.width()
	hi = ugfx.height()

	win_header = ugfx.Container(0,0,wi,30)
	win_quick = ugfx.Container(0,33,wi,hi-33-33)
	win_help = ugfx.Container(0,hi-30,wi,30)

	DEFAULT_APPS = ["app_library", "sponsors", "changename"]
	with Database() as db:
		pinned = [App(a) for a in db.get("pinned_apps", DEFAULT_APPS)]
		pinned = [app for app in pinned if app.loadable] # Filter out deleted apps
		pinned = pinned[:7] # Limit to 7
		db.set("pinned_apps", [app.folder_name for app in pinned])

	ugfx.set_default_font(ugfx.FONT_TITLE)
	title = ugfx.Label(3,3,wi-10,45,"EMF Camp 2016",parent=win_header)

	ugfx.set_default_font(ugfx.FONT_MEDIUM_BOLD)

	pinned_buttons = []
	for i in range(0, 8):
		x = i % 2
		y = i // 2
		button_title = "View all" if i == 7 else ""
		if i < len(pinned):
			button_title = pinned[i].title
		pinned_buttons.append(ugfx.Button(35 + 155 * x, 5 + 40 * y, 120, 35, button_title, parent=win_quick))

	btn_ok = ugfx.Button(10,5,20,20,"A",parent=win_help,shape=ugfx.Button.ELLIPSE)
	l_ok = ugfx.Label(40,5,100,20,"Run",parent=win_help)

	btn_back = ugfx.Button(100,5,20,20,"B",parent=win_help,shape=ugfx.Button.ELLIPSE)
	l_back = ugfx.Label(130,5,100,20,"Back",parent=win_help)

	btn_menu = ugfx.Button(200,5,20,20,"M",parent=win_help,shape=ugfx.Button.ROUNDED)
	l_back = ugfx.Label(230,5,100,20,"Menu",parent=win_help)

	sty = dialogs.default_style_badge

	win_header.show()
	win_quick.show()
	win_help.show()

	buttons.init()
	cursor = {"x": 0, "y": 0}
	last_cursor = cursor.copy()
	_draw_cursor(0, 0, ugfx.RED, win_quick)

	app_to_load = "sponsors"

	if not database_get("quicklaunch_firstrun"):
		dialogs.notice("""This screen displays the most commonly used apps.
Apps pinned here can also interact with the name screen.
To view all apps, pin and un-pin, select 'View All'
		""", title="TiLDA - Quick Launch", close_text="Close")
		database_set("quicklaunch_firstrun", True)

	try:
		while True:
			pyb.wfi()

			if buttons.is_triggered("JOY_UP"):
				cursor["y"] = max(0, cursor["y"] - 1)
			if buttons.is_triggered("JOY_DOWN"):
				cursor["y"] = min(3, cursor["y"] + 1)
			if buttons.is_triggered("JOY_RIGHT"):
				cursor["x"] = 1
			if buttons.is_triggered("JOY_LEFT"):
				cursor["x"] = 0

			if cursor["x"] != last_cursor["x"] or cursor["y"] != last_cursor["y"]: # Has the cursor moved?
				_draw_cursor(last_cursor["x"], last_cursor["y"], dialogs.default_style_badge.background(), win_quick)
				_draw_cursor(cursor["x"], cursor["y"], ugfx.RED, win_quick)
				last_cursor = cursor.copy()

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

			#if buttons.is_triggered("BTN_MENU"):
			#	open unpin dialog
			#	break;

			if buttons.is_triggered("BTN_A"):
				index = cursor["x"] + cursor["y"] * 2
				if index == 7:
					return "file_loader"
				if index < len(pinned):
					return pinned[index]
	finally:
		buttons.disable_all_interrupt()

		win_header.hide()
		win_quick.hide()
		win_help.hide()
		for b in pinned_buttons:
			b.destroy()
		btn_ok.destroy()
		l_ok.destroy()
		btn_back.destroy()
		l_back.destroy()
		btn_menu.destroy()
		l_back.destroy()
		win_header.destroy()
		win_quick.destroy()
		win_help.destroy()
		title.destroy()
示例#45
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
示例#46
0
            hpos = 0
            showevent(venue[vpos], data[venue[vpos]][hpos])
        if buttons.is_triggered("BTN_A"):
            # Need to Implement fetching description by ID here
            pass
        if buttons.is_triggered("BTN_B"):
            mainscreen()
            return


#Check and Connect to WiFi
if wifi.is_connected():
    pass
else:
    wifi.connect()

#Init GFX and Buttons
ugfx.init()
buttons.init()

#Server Address
server = 'badge.emf.camp'

#Main Screen
mainscreen()
while True:
    if buttons.is_triggered('BTN_A'):
        nownext()
    if buttons.is_triggered('BTN_B'):
        mainscreen()
示例#47
0
        colour[i],
        3,
        1,
    )
    i += 1
    x += 75

plot(seeks[0], zoom[0], xscale)

plot_index = 0
buttons.init()
while True:
    pyb.wfi()
    ugfx.poll()
    inc = 0
    if buttons.is_triggered("JOY_RIGHT"):
        inc = -1
    if buttons.is_triggered("JOY_LEFT"):
        inc = 1
    if buttons.is_triggered("BTN_B"):
        break

    if not inc == 0:
        inc += plot_index
        if inc < 0:
            pass
        elif inc >= len(zoom):
            pass
        elif seeks[0] == 0:  ## dont allow zoom out if we dont have enough data
            pass
        else:
	#url = 'http://'+server+':9002/schedule'
	#url = 'http://hackspace-leaderboard-scollins.c9users.io/schedule'
	url = 'http://api.ipify.org/'
	resp = get(url).text
	ugfx.area(0,0,ugfx.width(),ugfx.height(),0x0000)
	while True:
		ugfx.text(30,30,resp,ugfx.WHITE)
	return json.loads(resp)

#Check and Connect to WiFi
if wifi.is_connected():
	pass
else:
	wifi.connect()

#Init GFX and Buttons
ugfx.init()
buttons.init()

#Main Screen
mainscreen()
while True:
	if buttons.is_triggered('BTN_A'):
		getdata()
	if buttons.is_triggered('BTN_B'):
		mainscreen()
		
		
	
 
示例#49
0
文件: main.py 项目: Kimbsy/EMF_20016
ledg = pyb.LED(2)
ival = imu.get_acceleration()
if ival['y'] < 0:
    ugfx.orientation(0)
else:
    ugfx.orientation(180)

buttons.init()
if not onboard.is_splash_hidden():
    splashes = ["splash1.bmp"]
    for s in splashes:
        ugfx.display_image(0, 0, s)
        delay = 2000
        while delay:
            delay -= 1
            if buttons.is_triggered("BTN_MENU"):
                break
            if buttons.is_triggered("BTN_A"):
                break
            if buttons.is_triggered("BTN_B"):
                break
            if buttons.is_triggered("JOY_CENTER"):
                break
            pyb.delay(1)

onboard.hide_splash_on_next_boot(False)

ugfx.set_default_style(dialogs.default_style_badge)

sty_tb = ugfx.Style(dialogs.default_style_badge)
sty_tb.set_enabled([
示例#50
0
	z = 0
	for n in range(32):
		z = z**2 + a + b*1j
		if abs(z) > 4:
			break
	return 31-n

ugfx.clear(ugfx.GREY)
ugfx.text(30, int(size[1])-30, 'Computing...', ugfx.BLACK)

for y in range(size[1]):
	for x in range(size[0]):
		c = m(x, y)
		ugfx.area(x, y, 1, 1, get_color(c))

	if buttons.is_triggered("BTN_B"):
		break

while playing:
	ugfx.text(30, int(size[1])-30, 'Mandelbrot done :)', ugfx.WHITE)

	while True:
		# pyb.wfi() # Some low power stuff
		if buttons.is_triggered("BTN_A"):
			break

		if buttons.is_triggered("BTN_MENU"):
			playing = 0 #pyb.hard_reset()
			break