示例#1
0
def test_getters_setters():
    a = App()
    s = Slider(a)

    assert s.value == 0
    s.value = 10
    assert s.value == 10

    a.destroy()
示例#2
0
def GUI():
    app = App(title="Distance", width=230, height=70, layout="grid")

    Text(app, text="Rate (ms) :", grid=[0, 0], align="left")
    slider = Slider(app,
                    command=RepeatMeasure,
                    start=50,
                    end=2000,
                    grid=[1, 0],
                    align="left")
    slider.value = "100"

    Text(app, text="Distance (cm) : ", grid=[0, 1], align="left")
    global txt
    txt = Text(app, text="Dist", grid=[1, 1], align="left")
    RepeatMeasure(100)

    app.display()
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])
from guizero import App, PushButton, Slider, info

def resize():
    button.width = width.value
    button.height = height.value

app = App()
button = PushButton(app, image="guizero.gif", command=info, args=["button", "you push the button"])

width = Slider(app, start = 10, end = button.width, command = resize)
width.value = button.width

height = Slider(app, start = 10, end = button.height, command = resize)
height.value = button.height

app.display()
示例#5
0
    pantilthat.show()
    pantilthat.pan(0)    
    pantilthat.tilt(-20)
    exit()


# GUI Setings
app = App(bg ="lightgrey",  title="Pimoroni Interactive Cam V1.5", width=1050,  height=400, layout="grid")

pan_txt = Text(app, text="R           Pan             L", width=17, grid=[1,0], align="left")
pan_txt.text_color="blue"

position_txt = Text(app, text="Postition", width=10, color="blue", grid=[0,1], align="left")

pan_set = Slider(app, command=set_pan_tilt, start=-90, end=90, width=150, height=15, grid=[1,1], align="left") # sets pan value
pan_set.value = 0
pan_set.bg="yellow"

reset_position = PushButton(app, command=position_reset, text="Position Reset", width=14, grid=[2,1], align="left")
reset_position.text_color="blue"

tilt_txt = Text(app, text="U         Tilt               D", width=17, grid=[3,0], align="left")
tilt_txt.text_color="blue"

tilt_set = Slider(app, command=set_pan_tilt, start=-90, end=90, width=150, height=15, grid=[3,1], align="left") # sets tilt value
tilt_set.value = -20
tilt_set.bg="yellow"

lights_txt = Text(app, text="Lighting", width=10, color="blue", grid=[0,4], align="left")

red_txt = Text(app, text="          RED", width=10, grid=[1,3], align="left") #
示例#6
0
from guizero import App, Slider, Picture


def resize():
    picture.width = width.value
    picture.height = height.value


app = App(layout="grid", width=550, height=200)

picture = Picture(app, image="guizero.gif", grid=[0, 1])

width = Slider(app, command=resize, grid=[0, 0], start=1, end=picture.width)
width.width = picture.width
width.value = picture.width

height = Slider(app,
                command=resize,
                horizontal=False,
                grid=[1, 1],
                start=1,
                end=picture.height)
height.height = picture.height
height.value = picture.height

app.display()
示例#7
0
backwardButton = PushButton(app, backwards, text="Backwards", grid=[1, 2])

#Create spin left and right buttons
spinLeftButton = PushButton(app,
                            spinAntiClockwise,
                            text="Spin Left",
                            grid=[0, 1])
spinRightButton = PushButton(app,
                             spinClockwise,
                             text="Spin Right",
                             grid=[2, 1])

#Create a slider to set the speed.
speedTitle = Text(app, "Speed %", grid=[0, 3])
spdSlider = Slider(app, command=changeSpeed, grid=[1, 3, 3, 1])
spdSlider.value = 10

#Create a slider to set the duration of the next movement
durationTitle = Text(app, "Duration (secs)", grid=[0, 4])
durationSlider = Slider(app, command=changeDuration, grid=[1, 4, 3, 1])
durationSlider.value = 1

#Button to stop the STS-PI in an emergency
stopButton = PushButton(app, setStopTime, [0], text="STOP", grid=[1, 1])

#Buttons to take videos and photos.
photoButton = PushButton(app, takePhoto, text="Photo", grid=[0, 5])
videoButton = PushButton(app, takeVideo, text="Video", grid=[2, 5])

#Waffle to display button presses
buttonWaffle = Waffle(app, 1, 8, grid=[0, 6, 3, 2])
示例#8
0
from guizero import App, Box, Waffle, Slider, Text


def change_dim(slider):
    print("Changing size to {}x{} ".format(g_width.value, g_height.value))
    grid.width = g_width.value
    grid.height = g_height.value


app = App("Changing size")

grid = Waffle(app, width=4, height=4)

controls = Box(app, layout="grid")

# Width
width_text = Text(controls, text="Width", grid=[0, 0])
g_width = Slider(controls, start=0, end=20, command=change_dim, grid=[1, 0])
g_width.value = 4

# Height
height_text = Text(controls, text="Height", grid=[0, 1])
g_height = Slider(controls, start=0, end=20, command=change_dim, grid=[1, 1])
g_height.value = 4

app.display()
示例#9
0
#gpiozero
play_btn.when_pressed = play_track
stop_btn.when_pressed = stop_track
pause_btn.when_pressed = pause_track
next_btn.when_pressed = next_track
previous_btn.when_pressed = previous_track
shuffle_btn.when_pressed = shuffle_tracks

#pot monitoring
volume_monitor = Thread(target=monitor_volume_pot)
volume_monitor.start()
position_monitor = Thread(target=monitor_position_pot)
position_monitor.start()

#SenseHat show track
show_track = Thread(target=show_track_name)
show_track.start()

##Set the volume to 1/2 and Load a track and pause
volume.value = "50"
progress.text_size = 0

#Load up a track
play_track()

#update the text for which track is playing each second
playing.repeat(3000, check_progress)

#run the app
app.display()
PINS = ["BOARD7", "BOARD8", "BOARD12", "BOARD11"]

SERVO_CTL = []
for i, name in enumerate(NAMES):
    def func(position):
        ''' slider call function '''
        servo_control(position, i)
    SERVO_CTL.append(func)

def servo_control(position, channel):
    ''' control server position '''
    MY_SERVO[channel].angle = int(position)

APP = App(height=90*len(PINS))
MY_SERVO = []
for i, pin in enumerate(PINS):
    text = Text(APP, text=NAMES[i])
    slide = Slider(APP, start=SERVO_MIN, end=SERVO_MAX,
                   height='fill', width='fill',
                   command=SERVO_CTL[i])
    slide.value = ((SERVO_MAX-SERVO_MIN)/2)+SERVO_MIN
    MY_SERVO.append(
        AngularServo(
            pin,
            initial_angle=((SERVO_MAX-SERVO_MIN)/2)+SERVO_MIN,
            min_angle=SERVO_MIN,
            max_angle=SERVO_MAX))

APP.display()
#End
示例#11
0
    def __init__(self, app):
        Window.__init__(self, app, title="Scanner", layout="grid")
        self.tk.attributes("-fullscreen", True)
        self.hide()

        # Components
        Text(self, text="Scanner", grid=[0, 0, 3, 1])

        Text(self, text="Empty", grid=[0, 1])
        p1 = Picture(self, image="data/empty.jpg", grid=[0, 2])
        p1.height = 194
        p1.width = 259

        def update_empty():
            database.save_empty()
            p1.value = "data/empty.jpg"

        PushButton(self,
                   command=update_empty,
                   text="Retake Empty",
                   grid=[0, 7])

        Text(self, text="Scan", grid=[1, 1, 2, 1])
        p2 = Picture(self, image="data/testpic.jpg", grid=[1, 2])
        p2.height = 194
        p2.width = 259
        p3 = Picture(self, image="data/testscan.jpg", grid=[2, 2])
        p3.height = 135
        p3.width = 184
        m1 = Text(self, text="Card:", grid=[1, 6])

        def update_scan():
            global last_scan
            out = scanner.scan_card(img=last_scan)
            last_scan = out[0]
            if out[1] is not None:
                if len(out[1]) > 0:
                    cv2.drawContours(last_scan, out[1], -1, (0, 255, 0), 2)
            if out[2] is not None:
                cv2.drawContours(last_scan, [out[2]], -1, (255, 0, 0), 2)
            cv2.imwrite("data/testpic.jpg", last_scan)
            p2.value = "data/testpic.jpg"
            if out[3] is not None:
                cv2.imwrite("data/testscan.jpg", out[3])
                p3.value = "data/testscan.jpg"
                card = database.get_card(out[3])
                if card is None:
                    m1.value = "Card: Not Found"
                else:
                    m1.value = "Card: " + card.name

        def update_lower():
            scanner.lower = s1.value
            update_scan()

        s1 = Slider(self, command=update_lower, start=0, end=255, grid=[1, 3])
        s1.value = scanner.lower
        s1.width = 259

        def update_upper():
            scanner.upper = s2.value
            update_scan()

        s2 = Slider(self, command=update_upper, start=0, end=255, grid=[2, 3])
        s2.value = scanner.upper
        s2.width = 259

        def update_width_min():
            scanner.width_min = s3.value
            update_scan()

        s3 = Slider(self,
                    command=update_width_min,
                    start=0,
                    end=1500,
                    grid=[1, 4])
        s3.value = scanner.width_min
        s3.width = 259

        def update_width_max():
            scanner.width_max = s4.value
            update_scan()

        s4 = Slider(self,
                    command=update_width_max,
                    start=0,
                    end=1500,
                    grid=[2, 4])
        s4.value = scanner.width_max
        s4.width = 259

        def update_height_min():
            scanner.height_min = s5.value
            update_scan()

        s5 = Slider(self,
                    command=update_height_min,
                    start=0,
                    end=1500,
                    grid=[1, 5])
        s5.value = scanner.height_min
        s5.width = 259

        def test_scanner():
            out = scanner.scan_card()
            global last_scan
            last_scan = out[0]
            if out[1] is not None:
                if len(out[1]) > 0:
                    cv2.drawContours(last_scan, out[1], -1, (0, 255, 0), 2)
            if out[2] is not None:
                cv2.drawContours(last_scan, [out[2]], -1, (255, 0, 0), 2)
            cv2.imwrite("data/testpic.jpg", last_scan)
            p2.value = "data/testpic.jpg"
            if out[3] is not None:
                cv2.imwrite("data/testscan.jpg", out[3])
                p3.value = "data/testscan.jpg"
                card = database.get_card(out[3])
                if card is None:
                    m1.value = "Card: Not Found"
                else:
                    m1.value = "Card: " + card.name

        PushButton(self, command=test_scanner, text="Scan", grid=[1, 7])

        def close_scanner():
            self.hide()

        PushButton(self, command=close_scanner, text="Exit", grid=[0, 8, 2, 1])
    x = randint(0, 7)
    y = randint(0, 7)
    r = randint(0, rs.value)
    g = randint(0, gs.value)
    b = randint(0, bs.value)
    return x, y, r, g, b


def update_display():
    while True:
        sense.set_pixel(*values())


low = 1
high = 255

Text(app, "R", grid=[0, 0])
rs = Slider(app, start=low, end=high, grid=[0, 1], horizontal=False)
rs.value = high
Text(app, "G", grid=[1, 0])
gs = Slider(app, start=low, end=high, grid=[1, 1], horizontal=False)
gs.value = high
Text(app, "B", grid=[2, 0])
bs = Slider(app, start=low, end=high, grid=[2, 1], horizontal=False)
bs.value = high

t = Thread(target=update_display)
t.start()

app.display()
示例#13
0
    def __init__(self, app, cd):
        Window.__init__(self, app, title="Scanner", layout="grid")
        CD = cd
        self.tk.attributes("-fullscreen", True)
        self.hide()

        # Scanner page title
        Text(self, text="Scanner", grid=[0, 0, 3, 1])

        # Empty column 0
        Text(self, text="Empty", grid=[0, 1])
        p1 = Picture(self, image="data/empty.jpg", grid=[0, 2])
        p1.height = 194
        p1.width = 259

        def update_empty():
            cd.save_empty()
            p1.value = "data/empty.jpg"

        PushButton(self,
                   command=update_empty,
                   text="Retake Empty",
                   grid=[0, 7])

        # Scan columns 1 & 2
        Text(self, text="Scan", grid=[1, 1, 2, 1])
        p2 = Picture(self, image="data/testpic.jpg", grid=[1, 2])
        p2.height = 194
        p2.width = 259
        p3 = Picture(self, image="data/testscan.jpg", grid=[2, 2])
        p3.height = 135
        p3.width = 184
        m1 = Text(self, text="Card: Tragic Arrogance", grid=[1, 3, 2, 1])

        # Scan parameter sliders
        def update_width_min():
            scanner.width_min = s1.value

        s1 = Slider(self,
                    command=update_width_min,
                    start=0,
                    end=1500,
                    grid=[1, 4, 2, 1])
        s1.value = scanner.width_min

        def update_width_max():
            scanner.width_max = s2.value

        s2 = Slider(self,
                    command=update_width_max,
                    start=0,
                    end=1500,
                    grid=[1, 5, 2, 1])
        s2.value = scanner.width_max

        def update_height_min():
            scanner.height_min = s3.value

        s3 = Slider(self,
                    command=update_height_min,
                    start=0,
                    end=1500,
                    grid=[1, 6, 2, 1])
        s3.value = scanner.height_min

        # Scan button
        def test_scanner():
            # use scanner to scan card and set last_scan as image taken
            out = scanner.scan_card()
            global last_scan
            last_scan = out[0]

            # draw contours of left boundary and min-max width x min height box
            # in red within image dimensions 2592 x 1944
            lb = scanner.left_boundary

            hb = (1944 - scanner.height_min) / 2
            ht = 1944 - hb
            wnb = (2592 - scanner.width_min) / 2
            wnt = 2592 - wnb
            wxb = (2592 - scanner.width_max) / 2
            wxt = 2592 - wxb

            red = [
                np.array([[[lb, 0]], [[lb, 0]], [[lb, 1943]], [[lb, 1943]]],
                         dtype=np.int32),
                np.array([[[wnb, hb]], [[wnt, hb]], [[wnt, ht]], [[wnb, ht]]],
                         dtype=np.int32),
                np.array([[[wxb, hb]], [[wxt, hb]], [[wxt, ht]], [[wxb, ht]]],
                         dtype=np.int32)
            ]

            cv2.drawContours(last_scan, red, -1, (0, 0, 255), 2)

            # if any contours were detected, draw them in green
            if out[1] is not None:
                if len(out[1]) > 0:
                    cv2.drawContours(last_scan, out[1], -1, (0, 255, 0), 3)

            # if artwork contour was detected, draw it in blue
            if out[2] is not None:
                cv2.drawContours(last_scan, [out[2]], -1, (255, 0, 0), 4)

            # save last_scan
            cv2.imwrite("data/testpic.jpg", last_scan)
            p2.value = "data/testpic.jpg"

            # if artwork image was detected, save it and display the
            # corresponding card name if one is found
            if out[3] is not None:
                cv2.imwrite("data/testscan.jpg", out[3])
                p3.value = "data/testscan.jpg"
                card = CD.get_card(out[3])
                if card is None:
                    m1.value = "Card: Not Found"
                else:
                    m1.value = "Card: " + card.name

        PushButton(self, command=test_scanner, text="Scan", grid=[1, 7, 2, 1])

        # Exit button
        def close_scanner():
            self.hide()

        PushButton(self, command=close_scanner, text="Exit", grid=[0, 8, 3, 1])