예제 #1
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
예제 #2
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()
예제 #3
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()
예제 #4
0
    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,
                           130,
                           20,
                           "M: Enable uplink",
                           parent=win_header)
chk_upload.attach_input(ugfx.BTN_MENU, 0)
if database_get("stats_upload"):
    chk_upload.checked(1)

win_header.show()
예제 #5
0
### Author: Max Zangs
### Description: Computes simple Mandelbrot set
### Category: Random
### License: MIT
### Appname: Mandelbrot
### Built-in: no

import pyb
import ugfx
import buttons

ugfx.init()
buttons.init()
buttons.disable_menu_reset()

playing = 1
size = [320.0, 240.0]

def get_color(val):
	return ((val & 0x1f) << 11) | ((val & 0x1f) << 6) | (val & 0x1f)

def m(x, y):
	# Normalised coordinates
	a = 4.0 * (x/size[0] - 0.66)
	b = 3.0 * (y/size[1] - 0.50)

	z = 0
	for n in range(32):
		z = z**2 + a + b*1j
		if abs(z) > 4:
			break