()
| 20 | |
| 21 | |
| 22 | def main(): |
| 23 | global g_exit, g_response_time |
| 24 | |
| 25 | layout = [[sg.Text('Enter width, height of graph')], |
| 26 | [sg.Input(300, size=(6, 1), key='w'), sg.Input(300, size=(6, 1), key='h')], |
| 27 | [sg.Ok(), sg.Cancel()]] |
| 28 | |
| 29 | window = sg.Window('Enter graph size', layout) |
| 30 | event, values = window.read() |
| 31 | if event == sg.WIN_CLOSED or event == 'Cancel': |
| 32 | return |
| 33 | |
| 34 | CANVAS_SIZE = int(values['w']), int(values['h']) |
| 35 | window.close() |
| 36 | |
| 37 | # start ping measurement thread |
| 38 | |
| 39 | sg.theme('Black') |
| 40 | sg.set_options(element_padding=(0, 0)) |
| 41 | |
| 42 | layout = [[sg.Button('Quit', button_color=('white', 'black'))], |
| 43 | [sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, SAMPLE_MAX), |
| 44 | background_color='black', key='graph')], ] |
| 45 | |
| 46 | window = sg.Window('Canvas test', layout, grab_anywhere=True, |
| 47 | background_color='black', no_titlebar=False, |
| 48 | use_default_focus=False, finalize=True) |
| 49 | graph = window['graph'] # type:sg.Graph |
| 50 | |
| 51 | graph.draw_line((SAMPLES//2, 0), (SAMPLES//2,SAMPLE_MAX),color='white') |
| 52 | graph.draw_line((0,SAMPLE_MAX//2), (SAMPLES, SAMPLE_MAX//2),color='white') |
| 53 | |
| 54 | prev_response_time = None |
| 55 | i = 0 |
| 56 | prev_x, prev_y = 0, 0 |
| 57 | graph_value = 250 |
| 58 | figures = [] |
| 59 | while True: |
| 60 | event, values = window.read(timeout=0) |
| 61 | if event == 'Quit' or event == sg.WIN_CLOSED: |
| 62 | break |
| 63 | |
| 64 | graph_offset = random.randint(-10, 10) |
| 65 | graph_value = graph_value + graph_offset |
| 66 | |
| 67 | if graph_value > SAMPLE_MAX: |
| 68 | graph_value = SAMPLE_MAX |
| 69 | if graph_value < 0: |
| 70 | graph_value = 0 |
| 71 | |
| 72 | new_x, new_y = i, graph_value |
| 73 | prev_value = graph_value |
| 74 | |
| 75 | if i >= SAMPLES: |
| 76 | graph.delete_figure(figures[0]) |
| 77 | figures = figures[1:] |
| 78 | for count, figure in enumerate(figures): |
| 79 | graph.move_figure(figure, -STEP_SIZE, 0) |
no test coverage detected