Ejemplo n.º 1
0
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")
Ejemplo n.º 2
0
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()
Ejemplo n.º 3
0
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()
Ejemplo n.º 4
0
gpio = pi.headers['J8'].pins

app = App("GPIO Zero", layout="grid", width=200, height=710)

for n, pin in gpio.items():
    col_1 = n % 2
    x = 0 if col_1 else 3
    y = ceil(n / 2) - 1
    align = 'right' if col_1 else 'left'
    Text(app, str(pin.function), grid=[x, y], align=align)
    x = 1 if col_1 else 2
    color = {
        '5V': 'red',
        '3V3': 'orange',
        'GND': 'black',
    }.get(pin.function, 'white')
    waffle = Waffle(app,
                    height=1,
                    width=1,
                    grid=[x, y],
                    color=color,
                    dotty=True)

    if 'GPIO' in pin.function:
        bcm = int(pin.function[4:])
        mock_pin = Device.pin_factory.pin(bcm)
        waffle.repeat(10, create_update(mock_pin, waffle))
        if mock_pin.function == 'input':
            waffle.update_command(create_callback(mock_pin))

app.display()