New element! Frame - A frame with a label, Demo program from Frame, Graph elements

This commit is contained in:
MikeTheWatchGuy 2018-09-17 21:59:11 -04:00
parent 306abd0807
commit 2414e90e1e
4 changed files with 215 additions and 44 deletions

View file

@ -3,6 +3,10 @@ from threading import Thread
import time
import PySimpleGUI as sg
STEP_SIZE=1
SAMPLES = 6000
# globale used to communicate with thread.. yea yea... it's working fine
g_exit = False
g_response_time = None
@ -17,11 +21,14 @@ def main():
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 18')],
[sg.Graph((300,300), (0,0), (100,500),background_color='white', key='graph')],
[sg.Graph((6000,200), (0,0), (SAMPLES,500),background_color='black', key='graph')],
[sg.Quit()]]
form = sg.FlexForm('Canvas test', grab_anywhere=True)
form = sg.FlexForm('Canvas test', grab_anywhere=True, background_color='black')
form.Layout(layout)
prev_response_time = None
@ -33,19 +40,18 @@ def main():
button, values = form.ReadNonBlocking()
if button == 'Quit' or values is None:
break
graph = form.FindElement('graph')
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
form.FindElement('graph').DrawLine((prev_x, prev_y), (new_x, new_y), color='red')
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')
# form.FindElement('graph').DrawPoint((new_x, new_y), color='red')
prev_x, prev_y = new_x, new_y
if i >= 100:
i = 0
prev_x = prev_y = last_x = last_y = 0
form.FindElement('graph').Erase()
else: i += 4
i += STEP_SIZE if i < SAMPLES else 0
# tell thread we're done. wait for thread to exit
g_exit = True