def test_set_get_pixel(): a = App() w = Waffle(a) w.set_pixel(0,0, "red") assert w.get_pixel(0,0) == "red" a.destroy()
def test(): button.destroy() welcome_message.destroy() free.destroy() free2.destroy() instruction = Text(app, text="Push the red circle as soon as he appears") instruction.text_color = "white" board = Waffle(app, height=5, width=5, visible=True) board.pixel_size = 75 board.set_all("white") app.update() waitingTime = (random.randint(0, 10)) time.sleep(waitingTime) starttime = time.perf_counter() def ende(x, y): if board[x, y].dotty == True: board[x, y].dotty = False board.set_pixel(x, y, "white") end = time.perf_counter() timeused = round((end - starttime) * 1000) / 1000 timedisplay = Text(app, text="Your reaction-time: " + str(timeused) + "s") timedisplay.text_color = "white" timedisplay.font = "Impact" board.update_command(ende) x, y = random.randint(0, 4), random.randint(0, 4) board[x, y].dotty = True board.set_pixel(x, y, "red")
def append_wb(self, number): last_waffle = len(self.waffle_list) for i in range(0, 2* number, 2): w = Waffle(self.bottom_box, height=self.no_bits, width=1, grid=[last_waffle + i, 0]) w.hide() w.when_clicked = self.process_waffle self.waffle_list.append(w) b = Box(self.bottom_box, grid=[i + 1, 0]) b.hide() self.box_list.append(b)
def test_grid_layout(): a = App(layout="grid") w = Waffle(a, grid=[1,2]) grid_layout_test(w, 1, 2, 1, 1, None) ws = Waffle(a, grid=[1,2,3,4]) grid_layout_test(ws, 1, 2, 3, 4, None) wa = Waffle(a, grid=[1,2], align="top") grid_layout_test(wa, 1, 2, 1, 1, "top") a.destroy()
def test_update_command_with_parameters(): a = App() callback_event = Event() def callback(x, y): assert x == 0 assert y == 1 callback_event.set() w = Waffle(a) w.update_command(callback) mock_waffle_clicked(w) assert callback_event.is_set()
def test_alt_values(): a = App(layout = "grid") w = Waffle( a, height = 10, width = 11, dim = 12, pad = 13, color = "red", grid = [0,1], align = "top", dotty = True, bg = "green" ) assert w.master == a assert w.grid[0] == 0 assert w.grid[1] == 1 assert w.align == "top" assert w.height == 10 assert w.width == 11 assert w.pixel_size == 12 assert w.pad == 13 assert w.color == "red" assert w.dotty == True assert w.bg == "green" a.destroy()
def test_set_get_all(): from itertools import chain a = App() w = Waffle(a) w.set_all("red") # turn 2d list into 1d list pixels = chain.from_iterable(zip(*w.get_all())) count = 0 for pixel in pixels: assert pixel == "red" count += 1 assert count == w.width * w.height a.destroy()
def test_default_values(): a = App() w = Waffle(a) assert w.master == a assert w.grid == None assert w.align == None assert w.width == 3 assert w.height == 3 assert w.pixel_size == 20 assert w.pad == 5 assert w.color == "white" assert w.dotty == False a.destroy()
def test_command(): a = App() callback_event = Event() def callback(): callback_event.set() w = Waffle(a, command = callback) assert not callback_event.is_set() mock_waffle_clicked(w) assert callback_event.is_set() a.destroy()
def test_getters_setters(): a = App() w = Waffle(a) w.width = 10 assert w.width == 10 w.height = 11 assert w.height == 11 w.pixel_size = 12 assert w.pixel_size == 12 w.pad = 13 assert w.pad == 13 w.color = "red" assert w.color == "red" w.dotty = True assert w.dotty == True a.destroy()
def test_command_with_parameters(): a = App() callback_event = Event() def callback(x, y): assert x == 0 assert y == 1 callback_event.set() w = Waffle(a, command = callback) assert not callback_event.is_set() mock_waffle_clicked(w) assert callback_event.is_set() a.destroy()
def test_pixel_getters_setters(): a = App() w = Waffle(a) pixel = w[0,1] assert pixel.x == 0 assert pixel.y == 1 assert pixel.size == w.pixel_size assert pixel.color == w.color assert pixel.dotty == w.dotty pixel.color = "red" assert pixel.color == "red" pixel.dotty = True assert pixel.dotty a.destroy()
def test_reset(): from itertools import chain a = App() w = Waffle(a) w.set_pixel(0, 1, "red") w.reset() pixels = chain.from_iterable(zip(*w.get_all())) count = 0 for pixel in pixels: assert pixel == w.color count += 1 assert count == w.width * w.height a.destroy()
def test_update_command(): a = App() callback_event = Event() def callback(): callback_event.set() w = Waffle(a) mock_waffle_clicked(w) assert not callback_event.is_set() w.update_command(callback) mock_waffle_clicked(w) assert callback_event.is_set() callback_event.clear() w.update_command(None) mock_waffle_clicked(w) assert not callback_event.is_set() a.destroy()
def test_cascaded_properties(): a = App() w = Waffle(a) cascaded_properties_test(a, w, False) a.destroy()
def test_events(): a = App() w = Waffle(a) events_test(w) a.destroy()
def test_color(): a = App() w = Waffle(a) color_test(w) a.destroy()
def test_display(): a = App() w = Waffle(a) display_test(w) a.destroy()
def test_enable(): a = App() w = Waffle(a) enable_test(w) a.destroy()
def test_destroy(): a = App() w = Waffle(a) destroy_test(w) a.destroy()
def right_pressed(): waffle.set_pixel(0, 0, "green") def right_released(): waffle.set_pixel(0, 0, "grey") app = App() text = Text(app, text="events") slider = Slider(app) text_box = TextBox(app) check = CheckBox(app, "check") waffle = Waffle(app) # when clicked text.when_clicked = intro # when key pressed text_box.when_key_pressed = key_pressed # highlight widget when move over check.when_mouse_enters = mouse_enters check.when_mouse_leaves = mouse_leaves slider.when_mouse_enters = mouse_enters slider.when_mouse_leaves = mouse_leaves text_box.when_mouse_enters = mouse_enters text_box.when_mouse_leaves = mouse_leaves waffle.when_mouse_enters = mouse_enters
def test_inherited_properties(): a = App() inherited_properties_test(a, lambda: Waffle(a), False) a.destroy()
from guizero import App, Waffle import random #Action where a pixel on waffle is clicked def clicked(x, y): print(x, y) if xTarget == x and yTarget == y: print("Hit") def pickPixel(): global xTarget, yTarget xTarget = random.randint(0, 19) yTarget = random.randint(0, 19) myWaffle.set_pixel(xTarget, yTarget, "red") print("Target is ", xTarget, yTarget) #Make a window window1 = App(title="Waffle", width=600, height=800) #Make a waffle and set properties myWaffle = Waffle(window1, 20, 20, 20, 3, "white", command=clicked) #Carry out action after 3 seconds myWaffle.after(3000, pickPixel) #display the window window1.display()
def start_flood(x, y): flood_colour = palette.get_pixel(x, y) target = board.get_pixel(0, 0) flood(0, 0, target, flood_colour) win_check() move_text.value = moves_taken #Main app = App("Flood it!") board = Waffle(app, width=board_size, height=board_size, pad=0) palette = Waffle(app, width=6, height=1, dotty=True, command=start_flood) win_text = Text(app) move_text = Text(app) warn("Flood it!", "You only have 25 moves! ") fill_board() init_palette() app.display()
def launch_simulator(): global led_waffle global light_toggle global climate_dials button = [] if DEBUG: print("In launch_simulator function...") simulator = App(title='Physical Programming Simulator v2.0', layout='auto', bg='tan', height=600, width=420) # Setup LEDs - Only incoming from student program upper_box = Box(simulator, border=1, height=240, width=410) led_box = Box(upper_box, border=1, height=240, width=200, align='left') Text(led_box, text='Lights', width='fill') led_left_box = Box(led_box, height=240, width=100, align='left') Text(led_left_box, text='rled', align='top', size=27, color='red') Text(led_left_box, text='yled', align='top', size=27, color='yellow') Text(led_left_box, text='gled', align='top', size=27, color='green') Text(led_left_box, text='bled', align='top', size=27, color='blue') led_right_box = Box(led_box, height=240, width=100, align='right') led_waffle = Waffle(led_right_box, height=4, width=1, dim=40, color='black', dotty='True') # Setup Buttons - Only outgoing to student program and needs timeout value / function button_box = Box(upper_box, border=1, height=240, width=200, align='right') Text(button_box, text='Push Buttons', width='fill') for i in range(4): button.append( PushButton(button_box, height=1, width=6, padx=13, pady=11, text='Button_' + str(i + 1))) button[i].bg = 'gray' button[i].update_command(button_toggle, args=['Button_' + str(i + 1)]) Box(button_box, width=10, height=4) # Setup sliders for temperature in °F, humidity, and barometric pressure - Only outgoing to student program # Converted slider creation to use zip for parallel iteration in an effort to reduce code lower_box = Box(simulator, border=1, height=350, width=410) climate_box = Box(lower_box, border=1, height=350, width=200, align='left') Text(climate_box, text='Climate Statistics') Text(climate_box, text=' Temp °F Humidity Pressure', size=10) Text(climate_box, text=' temp humid press', size=10) # The following code creates three sliders for temperature, humidity and pressure using zip for parallel iteration for st, en, cmd in zip([150, 100, 31], [-50, 0, 29], [temperature_set, humidity_set, pressure_set]): Text(climate_box, width=1, align='left') climate_dials.append( Slider(climate_box, start=st, end=en, height=275, width=20, horizontal=False, align='left', command=cmd)) misc_box = Box(lower_box, border=1, height=350, width=200, align='right') misc_upper_box = Box(misc_box, border=1, height=170, width=200) Text(misc_upper_box, text='Light Sensor (light)') light_toggle = PushButton(misc_upper_box, image=night_image, height=130, width=175) misc_lower_box = Box(misc_box, border=1, height=170, width=200) Text(misc_lower_box, text='Obnoxious Buzzer (buzz)') Picture(misc_lower_box, image=here + 'Ouch.png', height=130, width=175) light_toggle.update_command(day_night_toggle, args=['light', light_toggle]) simulator.display()
aiSearchLocations = [] # Locations ai will search mHistory = "" #Stores ai missile attempts #Windows and Boxes battleBoard = App(title="Ship Shooter",width=700,height=700,layout="grid") playerBoard = Box(battleBoard,layout="grid",grid=[0,0]) compBoard = Box(battleBoard,layout="grid",grid=[1,0]) textBoxes = Box(battleBoard,layout="grid",grid=[0,1],align='left') missileBox = Box(battleBoard,layout="grid",grid=[0,2],align='right') menubar = MenuBar(battleBoard, toplevel=["Game"], options=[ [ ["Easy", reInitialise], ["Normal", reInitialise], ["Hard", reInitialise] ] ]) #Game boards for ships playerWaffle = Waffle(playerBoard,height=10,width=10,dim=29,grid=[0,0],color="blue",command=pClicked) computerWaffle = Waffle(compBoard,height=10,width=10,dim=29,grid=[0,0],color="aqua",command=cClicked) #Text information Text(textBoxes,text="Missiles remaining: ",size=18,color="blue",grid=[0,0],align='left') playerText = Text(textBoxes,text="Players ship is at: ",size=18,color="blue",grid=[0,1],align='left') missilesText = Text(textBoxes,text=missiles,size=18,grid=[1,0],color="blue") compText = Text(textBoxes,text=compShip,size=18,color="green",grid=[0,2]) missileHistory = Text(textBoxes,text=mHistory,size=12,color="red",grid=[0,3]) #starting settings computerWaffle.hide() #Show game battleBoard.display()
# coding: utf-8 from guizero import App, Waffle app = App() my_waffle = Waffle(app) my_waffle[2, 1].color = "red" my_waffle[1, 1].dotty = True app.display()
def test_after_schedule(): a = App() w = Waffle(a) schedule_after_test(a, w) a.destroy()
def setup_gui(): """ Create the GUI for controlling the STS-Pi Rover. """ global app, statusWaffle, roverChoice, connectButton, exitButton global forwardButton, stopButton, backwardButton, spdSlider, durationSlider global spinRightButton, spinLeftButton, photoButton, videoButton global buttonWaffle # Declare the GUI application app = App("STS Controller", layout="grid") # Bluetooth connection status waffle. Single cell, blue=connected, red=not. statusWaffle = Waffle(app, 1, 4, 10, 10, grid=[0, 0]) if connected: statusWaffle.set_pixel(0, 0, "blue") statusWaffle.set_pixel(1, 0, "white") statusWaffle.set_pixel(2, 0, "white") statusWaffle.set_pixel(3, 0, "white") # Choice of STS-PI Rover roverChoice = ButtonGroup(app, options=["STS-Pi 2", "STS-Pi 3"], selected="STS-Pi 2", grid=[1, 0]) # Reconnect button for when the Bluetooth connection has been lost or reset connectButton = PushButton(app, connect, text="Connect", grid=[2, 0]) #Create forwards and backwards buttons forwardButton = PushButton(app, forwards, text="Forwards", grid=[1, 1]) #Create spin left and right buttons spinLeftButton = PushButton(app, spinAntiClockwise, text="Spin Left", grid=[0, 2]) #Button to stop the STS-PI in an emergency stopButton = PushButton(app, stop, text="STOP", grid=[1, 2]) spinRightButton = PushButton(app, spinClockwise, text="Spin Right", grid=[2, 2]) backwardButton = PushButton(app, backwards, text="Backwards", grid=[1, 3]) #Create a slider to set the speed. speedTitle = Text(app, "Speed %", grid=[0, 4]) spdSlider = Slider(app, command=changeSpeed, grid=[1, 4, 3, 1]) spdSlider.value = 15 #Create a slider to set the duration of the next movement durationTitle = Text( app, "Duration (secs)", grid=[0, 5], ) durationSlider = Slider(app, command=changeDuration, start=1, end=10, grid=[1, 5, 3, 1]) durationSlider.value = 1 #Buttons to take videos and photos. photoButton = PushButton(app, takePhoto, text="Photo", grid=[0, 6]) videoButton = PushButton(app, takeVideo, text="Video", grid=[2, 6]) #Waffle to display button presses buttonWaffle = Waffle(app, 1, 8, grid=[0, 7, 3, 2]) # Ids for the buttons on the STS-PI rover buttonIds = Text(app, "1 2 3 4 5 6 7 8 ", grid=[0, 9, 3, 1]) # This spacer text increases the gap below the controls and the exit button. spacer = Text(app, "", grid=[0, 10]) # Button to quit the application exitButton = PushButton(app, closeDown, text="Exit", grid=[1, 11])
def test_repeat_schedule(): a = App() w = Waffle(a) schedule_repeat_test(a, w) a.destroy()