From 5bab941f2d6ae474a74102d0140a34df6dddfdbf Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sat, 3 Feb 2024 10:55:14 -0500 Subject: [PATCH] Simplified code some --- DemoPrograms/Demo_Timer_API_State_Machine.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/DemoPrograms/Demo_Timer_API_State_Machine.py b/DemoPrograms/Demo_Timer_API_State_Machine.py index b8565bd7..67697202 100644 --- a/DemoPrograms/Demo_Timer_API_State_Machine.py +++ b/DemoPrograms/Demo_Timer_API_State_Machine.py @@ -70,13 +70,6 @@ def main(): state = State.start elif event == NEXT_STATE: state = values[event] - elif event == sg.TIMER_KEY: - if state == State.delay_3_sec: - window.write_event_value(NEXT_STATE, State.close_win) - continue # skip state processing until next_state is received by read - elif state == State.delay_2_sec: - window.write_event_value(NEXT_STATE, State.enable_send) - continue # skip state processing until next_state is received by read window['-STATE-'].update(state) if window_send: @@ -87,12 +80,16 @@ def main(): window['-SEND-'].update(disabled=True) window_send = make_send_window() window.write_event_value(NEXT_STATE, State.delay_3_sec) + elif event == sg.TIMER_KEY and state == State.delay_3_sec: # be sure the if with the timer check AND state is above if with only state + window.write_event_value(NEXT_STATE, State.close_win) elif state == State.delay_3_sec: window.timer_start(TIMER1, repeating=False) elif state == State.close_win: window_send.close() window_send = None window.write_event_value(NEXT_STATE, State.delay_2_sec) + elif event == sg.TIMER_KEY and state == State.delay_2_sec: + window.write_event_value(NEXT_STATE, State.enable_send) elif state == State.delay_2_sec: window.timer_start(TIMER2, repeating=False) elif state == State.enable_send: