Major update of all demo programs to use new PEP8 bindings, etc

This commit is contained in:
PySimpleGUI 2019-10-23 16:10:03 -04:00
parent 3f7c87c562
commit 7f52778bcc
307 changed files with 19546 additions and 3297 deletions

View file

@ -1,21 +1,25 @@
import ping
from threading import Thread
import time
import PySimpleGUI as sg
from threading import Thread
import ping
import time
# Yet another usage of Graph element.
STEP_SIZE=1
STEP_SIZE = 1
SAMPLES = 6000
CANVAS_SIZE = (6000,500)
CANVAS_SIZE = (6000, 500)
# globale used to communicate with thread.. yea yea... it's working fine
g_exit = False
g_response_time = None
def ping_thread(args):
global g_exit, g_response_time
while not g_exit:
g_response_time = ping.quiet_ping('google.com', timeout=1000)
def main():
global g_exit, g_response_time
@ -23,21 +27,22 @@ def main():
thread = Thread(target=ping_thread, args=(None,))
thread.start()
sg.ChangeLookAndFeel('Black')
sg.SetOptions(element_padding=(0,0))
sg.change_look_and_feel('Black')
sg.set_options(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')],]
layout = [[sg.Text('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')]
]
form = sg.FlexForm('Canvas test', grab_anywhere=True, background_color='black', no_titlebar=False, use_default_focus=False)
form.Layout(layout)
form.Finalize()
graph = form.FindElement('graph')
form = sg.FlexForm('Canvas test', layout, grab_anywhere=True, background_color='black',
no_titlebar=False, use_default_focus=False, finalize=True)
graph = form['graph']
prev_response_time = None
i=0
prev_x, prev_y = 0, 0
i = 0
prev_x, prev_y = 0, 0
while True:
time.sleep(.2)
@ -49,10 +54,10 @@ def main():
new_x, new_y = i, g_response_time[0]
prev_response_time = g_response_time
if i >= SAMPLES:
graph.Move(-STEP_SIZE,0)
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')
graph.draw_line((prev_x, prev_y), (new_x, new_y), color='white')
# form['graph'].draw_point((new_x, new_y), color='red')
prev_x, prev_y = new_x, new_y
i += STEP_SIZE if i < SAMPLES else 0
@ -63,4 +68,4 @@ def main():
if __name__ == '__main__':
main()
exit(69)