2018-09-27 20:24:09 +00:00
|
|
|
#!/usr/bin/env python
|
2019-10-23 20:10:03 +00:00
|
|
|
import PySimpleGUI as sg
|
2018-09-20 14:41:47 +00:00
|
|
|
import ping
|
|
|
|
from threading import Thread
|
|
|
|
import time
|
|
|
|
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
STEP_SIZE = 1
|
2018-09-24 22:01:00 +00:00
|
|
|
SAMPLES = 1000
|
2019-10-23 20:10:03 +00:00
|
|
|
CANVAS_SIZE = (1000, 500)
|
2018-09-20 14:41:47 +00:00
|
|
|
|
|
|
|
# globale used to communicate with thread.. yea yea... it's working fine
|
|
|
|
g_exit = False
|
|
|
|
g_response_time = None
|
2019-10-23 20:10:03 +00:00
|
|
|
|
|
|
|
|
2018-09-20 14:41:47 +00:00
|
|
|
def ping_thread(args):
|
|
|
|
global g_exit, g_response_time
|
|
|
|
while not g_exit:
|
|
|
|
g_response_time = ping.quiet_ping('google.com', timeout=1000)
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
|
2018-09-20 14:41:47 +00:00
|
|
|
def main():
|
|
|
|
global g_exit, g_response_time
|
|
|
|
|
|
|
|
# start ping measurement thread
|
|
|
|
thread = Thread(target=ping_thread, args=(None,))
|
|
|
|
thread.start()
|
|
|
|
|
2019-12-24 23:52:47 +00:00
|
|
|
sg.theme('Black')
|
2019-10-23 20:10:03 +00:00
|
|
|
sg.set_options(element_padding=(0, 0))
|
2018-09-20 14:41:47 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
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')]
|
|
|
|
]
|
2018-09-20 14:41:47 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window = sg.Window('Canvas test', layout,
|
|
|
|
grab_anywhere=True, background_color='black',
|
|
|
|
no_titlebar=False, use_default_focus=False)
|
2018-09-20 14:41:47 +00:00
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
graph = window['graph']
|
2018-09-20 14:41:47 +00:00
|
|
|
prev_response_time = None
|
2019-10-23 20:10:03 +00:00
|
|
|
i = 0
|
|
|
|
prev_x, prev_y = 0, 0
|
|
|
|
|
2018-09-20 14:41:47 +00:00
|
|
|
while True:
|
2019-10-23 20:10:03 +00:00
|
|
|
event, values = window.read(timeout=200)
|
2020-05-07 10:22:59 +00:00
|
|
|
if event == 'Quit' or event == sg.WIN_CLOSED:
|
2018-09-20 14:41:47 +00:00
|
|
|
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:
|
2019-10-23 20:10:03 +00:00
|
|
|
graph.move(-STEP_SIZE, 0)
|
2018-09-20 14:41:47 +00:00
|
|
|
prev_x = prev_x - STEP_SIZE
|
2019-10-23 20:10:03 +00:00
|
|
|
graph.draw_line((prev_x, prev_y), (new_x, new_y), color='white')
|
|
|
|
# window['graph'].draw_point((new_x, new_y), color='red')
|
2018-09-20 14:41:47 +00:00
|
|
|
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()
|
|
|
|
|
2019-10-23 20:10:03 +00:00
|
|
|
window.close()
|
|
|
|
|
2018-09-20 14:41:47 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|