Ejemplo n.º 1
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.º 2
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.º 3
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
Ejemplo n.º 4
0
#!/usr/bin/env python
import sys
if sys.version_info[0] < 3:
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg

layout = [[
    sg.Graph(canvas_size=(400, 400),
             graph_bottom_left=(0, 0),
             graph_top_right=(400, 400),
             background_color='red',
             key='graph')
],
          [
              sg.T('Change circle color to:'),
              sg.ReadButton('Red'),
              sg.ReadButton('Blue'),
              sg.ReadButton('Move')
          ]]

window = sg.Window('Graph test').Layout(layout).Finalize()

graph = window.FindElement('graph')
circle = graph.DrawCircle((75, 75), 25, fill_color='black', line_color='white')
point = graph.DrawPoint((75, 75), 10, color='green')
oval = graph.DrawOval((25, 300), (100, 280),
                      fill_color='purple',
                      line_color='purple')
rectangle = graph.DrawRectangle((25, 300), (100, 280), line_color='purple')
line = graph.DrawLine((0, 0), (100, 100))
Ejemplo n.º 5
0
        setpoint = SetpointPosition()

        rospy.loginfo("Set mode to offboard")
        modes.setMode("OFFBOARD")

        rospy.loginfo("Takeoff")
        setpoint.set(0.0, 0.0, 5.0, 0)

        _X_SIZE = 4
        _Y_SIZE = 4

        layout = [[
            sg.Graph(canvas_size=(400, 400),
                     graph_bottom_left=(-200, -200),
                     graph_top_right=(200, 200),
                     background_color='red',
                     key='graph',
                     enable_events=True,
                     drag_submits=True)
        ],
                  [
                      sg.Button("land", key="LAND"),
                      sg.Button("go up", key="UP"),
                      sg.Button("go down", key="DOWN")
                  ],
                  [
                      sg.InputText("45", key="YAW"),
                      sg.Button("SEND_YAW", key="SEND_YAW")
                  ]]
        window = sg.Window('Graph test', layout, finalize=True)
        graph = window['graph']
Ejemplo n.º 6
0
    import PySimpleGUI27 as sg
else:
    import PySimpleGUI as sg
import math

layout = [
    [
        sg.T('Example of Using Math with a Graph',
             justification='center',
             size=(40, 1),
             relief=sg.RELIEF_RAISED)
    ],
    [
        sg.Graph(canvas_size=(400, 400),
                 graph_bottom_left=(-105, -105),
                 graph_top_right=(105, 105),
                 background_color='white',
                 key='graph',
                 tooltip='This is a cool graph!')
    ],
]

window = sg.Window('Graph of Sine Function',
                   grab_anywhere=True).Layout(layout).Finalize()
graph = window.FindElement('graph')

# Draw axis
graph.DrawLine((-100, 0), (100, 0))
graph.DrawLine((0, -100), (0, 100))

for x in range(-100, 101, 20):
    graph.DrawLine((x, -3), (x, 3))