From 54f53991a0e78059df609a41c18c70fd3986af47 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 15 Dec 2019 12:14:55 -0500 Subject: [PATCH] Draws Axis, moves the individual lines instead of the graph. --- DemoPrograms/Demo_Graph_Noise.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/DemoPrograms/Demo_Graph_Noise.py b/DemoPrograms/Demo_Graph_Noise.py index 6161c2d6..be6f0d42 100644 --- a/DemoPrograms/Demo_Graph_Noise.py +++ b/DemoPrograms/Demo_Graph_Noise.py @@ -7,6 +7,8 @@ import sys Example of random line in Graph element. ''' +sg.change_look_and_feel('black') + STEP_SIZE = 1 SAMPLES = 300 SAMPLE_MAX = 300 @@ -17,7 +19,7 @@ def main(): global g_exit, g_response_time layout = [[sg.Text('Enter width, height of graph')], - [sg.Input(size=(6, 1), key='w'), sg.Input(size=(6, 1), key='h')], + [sg.Input(300, size=(6, 1), key='w'), sg.Input(300, size=(6, 1), key='h')], [sg.Ok(), sg.Cancel()]] window = sg.Window('Enter graph size', layout) @@ -34,18 +36,22 @@ def main(): sg.set_options(element_padding=(0, 0)) layout = [[sg.Button('Quit', button_color=('white', 'black'))], - [sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, SAMPLE_MAX) + [sg.Graph(CANVAS_SIZE, (0, 0), (SAMPLES, SAMPLE_MAX), background_color='black', key='graph')], ] window = sg.Window('Canvas test', layout, grab_anywhere=True, background_color='black', no_titlebar=False, use_default_focus=False, finalize=True) - graph = window['graph'] + graph = window['graph'] # type:sg.Graph + + graph.draw_line((SAMPLES//2, 0), (SAMPLES//2,SAMPLE_MAX),color='white') + graph.draw_line((0,SAMPLE_MAX//2), (SAMPLES, SAMPLE_MAX//2),color='white') prev_response_time = None i = 0 prev_x, prev_y = 0, 0 graph_value = 250 + figures = [] while True: event, values = window.read(timeout=0) if event == 'Quit' or event is None: @@ -63,10 +69,15 @@ def main(): prev_value = graph_value if i >= SAMPLES: - graph.move(-STEP_SIZE, 0) + graph.delete_figure(figures[0]) + figures = figures[1:] + for count, figure in enumerate(figures): + graph.move_figure(figure, -STEP_SIZE, 0) prev_x = prev_x - STEP_SIZE - graph.draw_line((prev_x, prev_y), (new_x, new_y), color='white') + # print(f'io={i} {prev_x,prev_y} to {new_x, new_y}') + last_figure = graph.draw_line((prev_x, prev_y), (new_x, new_y), color='white') + figures.append(last_figure) prev_x, prev_y = new_x, new_y i += STEP_SIZE if i < SAMPLES else 0