Ejemplo n.º 1
0
def RemoteControlExample():

    layout = [[sg.Text('Robotics Remote Control')],
              [sg.T(' ' * 10), sg.RealtimeButton('Forward')],
              [
                  sg.RealtimeButton('Left'),
                  sg.T(' ' * 15),
                  sg.RealtimeButton('Right')
              ], [sg.T(' ' * 10), sg.RealtimeButton('Reverse')], [sg.T('')],
              [sg.Quit(button_color=('black', 'orange'))]]

    window = sg.Window('Robotics Remote Control',
                       auto_size_text=True).Layout(layout).Finalize()

    #
    # Some place later in your code...
    # You need to perform a ReadNonBlocking on your window every now and then or
    # else it won't refresh.
    #
    # your program's main loop
    while (True):
        # This is the code that reads and updates your window
        button, values = window.ReadNonBlocking()
        if button is not None:
            print(button)
        if button == 'Quit' or values is None:
            break
        # time.sleep(.01)

    window.CloseNonBlocking()
Ejemplo n.º 2
0
def RemoteControlExample_NoGraphics():
    # Make a form, but don't use context manager

    layout = [[sg.Text('Robotics Remote Control', justification='center')],
              [sg.T('', justification='center', size=(19, 1), key='status')],
              [sg.T(' ' * 8), sg.RealtimeButton('Forward')],
              [
                  sg.RealtimeButton('Left'),
                  sg.T('              '),
                  sg.RealtimeButton('Right')
              ], [sg.T(' ' * 8), sg.RealtimeButton('Reverse')], [sg.T('')],
              [sg.Quit(button_color=('black', 'orange'))]]
    # Display form to user
    window = sg.Window('Robotics Remote Control',
                       auto_size_text=True,
                       grab_anywhere=False).Layout(layout)

    #
    # Some place later in your code...
    # You need to perform a ReadNonBlocking on your form every now and then or
    # else it won't refresh.
    #
    # your program's main loop
    while (True):
        # This is the code that reads and updates your window
        button, values = window.ReadNonBlocking()
        if button is not None:
            window.FindElement('status').Update(button)
        else:
            window.FindElement('status').Update('')
        # if user clicked quit button OR closed the form using the X, then break out of loop
        if button == 'Quit' or values is None:
            break

    window.CloseNonBlocking()
Ejemplo n.º 3
0
def RemoteControlExample():
    # Make a form, but don't use context manager
    sg.SetOptions(element_padding=(0, 0))
    back = '#eeeeee'
    image_forward = 'ButtonGraphics/RobotForward.png'
    image_backward = 'ButtonGraphics/RobotBack.png'
    image_left = 'ButtonGraphics/RobotLeft.png'
    image_right = 'ButtonGraphics/RobotRight.png'

    sg.SetOptions(border_width=0,
                  button_color=('black', back),
                  background_color=back,
                  element_background_color=back,
                  text_element_background_color=back)

    layout = [[sg.Text('Robotics Remote Control')],
              [sg.T('', justification='center', size=(19, 1), key='status')],
              [
                  sg.RealtimeButton('Forward',
                                    image_filename=image_forward,
                                    pad=((50, 0), 0))
              ],
              [
                  sg.RealtimeButton('Left', image_filename=image_left),
                  sg.RealtimeButton('Right',
                                    image_filename=image_right,
                                    pad=((50, 0), 0))
              ],
              [
                  sg.RealtimeButton('Reverse',
                                    image_filename=image_backward,
                                    pad=((50, 0), 0))
              ], [sg.T('')], [sg.Quit(button_color=('black', 'orange'))]]

    window = sg.Window('Robotics Remote Control',
                       auto_size_text=True,
                       grab_anywhere=False).Layout(layout)

    #
    # Some place later in your code...
    # You need to perform a ReadNonBlocking on your form every now and then or
    # else it won't refresh.
    #
    # your program's main loop
    while (True):
        # This is the code that reads and updates your window
        button, values = window.ReadNonBlocking()
        if button is not None:
            window.FindElement('status').Update(button)
        else:
            window.FindElement('status').Update('')
        # if user clicked quit button OR closed the form using the X, then break out of loop
        if button == 'Quit' or values is None:
            break

    window.CloseNonBlocking()
Ejemplo n.º 4
0
def main():
    global g_exit, g_response_time
    # start ping measurement thread

    sg.ChangeLookAndFeel('Black')
    sg.SetOptions(element_padding=(0, 0))

    layout = [
        [
            sg.Quit(button_color=('white', 'black')),
            sg.T('', pad=((100, 0), 0), font='Any 15', key='output')
        ],
        [
            sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, SAMPLE_MAX),
                     background_color='black',
                     key='graph')
        ],
    ]

    window = sg.Window('CPU Graph',
                       grab_anywhere=True,
                       keep_on_top=True,
                       background_color='black',
                       no_titlebar=True,
                       use_default_focus=False).Layout(layout)

    graph = window.FindElement('graph')
    output = window.FindElement('output')
    # start cpu measurement thread
    thread = Thread(target=CPU_thread, args=(None, ))
    thread.start()

    last_cpu = i = 0
    prev_x, prev_y = 0, 0
    while True:  # the Event Loop
        time.sleep(.5)
        button, values = window.ReadNonBlocking()
        if button == 'Quit' or values is None:  # always give ths user a way out
            break
        # do CPU measurement and graph it
        current_cpu = int(g_cpu_percent * 10)
        if current_cpu == last_cpu:
            continue
        output.Update(current_cpu / 10)  # show current cpu usage at top
        if current_cpu > SAMPLE_MAX:
            current_cpu = SAMPLE_MAX
        new_x, new_y = i, current_cpu
        if i >= SAMPLES:
            graph.Move(-STEP_SIZE, 0)  # shift graph over if full of data
            prev_x = prev_x - STEP_SIZE
        graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white')
        prev_x, prev_y = new_x, new_y
        i += STEP_SIZE if i < SAMPLES else 0
        last_cpu = current_cpu
Ejemplo n.º 5
0
def main():
    global g_exit, g_response_time

    # start ping measurement thread
    thread = Thread(target=ping_thread, args=(None, ))
    thread.start()

    sg.ChangeLookAndFeel('Black')
    sg.SetOptions(element_padding=(0, 0))

    layout = [
        [
            sg.T('Ping times to Google.com', font='Any 12'),
            sg.Quit(pad=((100, 0), 0), button_color=('white', 'black'))
        ],
        [
            sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, 500),
                     background_color='black',
                     key='graph')
        ],
    ]

    window = sg.Window('Canvas test',
                       grab_anywhere=True,
                       background_color='black',
                       no_titlebar=False,
                       use_default_focus=False).Layout(layout)

    graph = window.FindElement('graph')

    prev_response_time = None
    i = 0
    prev_x, prev_y = 0, 0
    while True:
        time.sleep(.2)

        button, values = window.ReadNonBlocking()
        if button == 'Quit' or values is None:
            break
        if g_response_time is None or prev_response_time == g_response_time:
            continue
        new_x, new_y = i, g_response_time[0]
        prev_response_time = g_response_time
        if i >= SAMPLES:
            graph.Move(-STEP_SIZE, 0)
            prev_x = prev_x - STEP_SIZE
        graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white')
        # window.FindElement('graph').DrawPoint((new_x, new_y), color='red')
        prev_x, prev_y = new_x, new_y
        i += STEP_SIZE if i < SAMPLES else 0

    # tell thread we're done. wait for thread to exit
    g_exit = True
    thread.join()
Ejemplo n.º 6
0
def main():
    global g_exit, g_response_time

    layout = [[sg.T('Enter width, height of graph')],
              [sg.In(size=(6, 1)), sg.In(size=(6, 1))],
              [sg.Ok(), sg.Cancel()]]

    window = sg.Window('Enter graph size').Layout(layout)
    b,v = window.Read()
    if b is None or b == 'Cancel':
        sys.exit(69)
    w, h = int(v[0]), int(v[1])
    CANVAS_SIZE = (w,h)

    # start ping measurement thread

    sg.ChangeLookAndFeel('Black')
    sg.SetOptions(element_padding=(0,0))

    layout = [  [sg.Quit( button_color=('white','black'))],
               [sg.Graph(CANVAS_SIZE, (0,0), (SAMPLES,SAMPLE_MAX),background_color='black', key='graph')],]

    window = sg.Window('Canvas test', grab_anywhere=True, background_color='black', no_titlebar=False, use_default_focus=False).Layout(layout).Finalize()
    graph = window.FindElement('graph')

    prev_response_time = None
    i=0
    prev_x, prev_y = 0, 0
    graph_value = 250
    while True:
        # time.sleep(.2)
        button, values = window.ReadNonBlocking()
        if button == 'Quit' or values is None:
            break
        graph_offset = random.randint(-10, 10)
        graph_value = graph_value + graph_offset
        if graph_value > SAMPLE_MAX:
            graph_value = SAMPLE_MAX
        if graph_value < 0:
            graph_value = 0
        new_x, new_y = i, graph_value
        prev_value = graph_value
        if i >= SAMPLES:
            graph.Move(-STEP_SIZE,0)
            prev_x = prev_x - STEP_SIZE
        graph.DrawLine((prev_x, prev_y), (new_x, new_y), color='white')
        # window.FindElement('graph').DrawPoint((new_x, new_y), color='red')
        prev_x, prev_y = new_x, new_y
        i += STEP_SIZE if i < SAMPLES else 0