MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / main

Function main

DemoPrograms/Demo_Timer_API_State_Machine.py:53–99  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

51
52
53def main():
54 layout = [[sg.Text('State Machine Example', font='_ 14')],
55 [sg.Text('Click Send to begin sequence')],
56 [sg.Text('State:'), sg.Text(key='-STATE-')],
57 [sg.Button('Send', key='-SEND-'), sg.Button('Exit')]]
58
59 window = sg.Window('State Machine Example', layout, font='Any 12')
60
61 window_send = None
62 state = State.stopped
63
64 while True:
65 event, values = window.read()
66 if event == sg.WIN_CLOSED or event == 'Exit':
67 break
68
69 if event == '-SEND-':
70 state = State.start
71 elif event == NEXT_STATE:
72 state = values[event]
73
74 window['-STATE-'].update(state)
75 if window_send:
76 window_send.refresh()
77
78 # ----- STATE MACHINE PROCESSING -----
79 if state == State.start:
80 window['-SEND-'].update(disabled=True)
81 window_send = make_send_window()
82 window.write_event_value(NEXT_STATE, State.delay_3_sec)
83 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
84 window.write_event_value(NEXT_STATE, State.close_win)
85 elif state == State.delay_3_sec:
86 window.timer_start(TIMER1, repeating=False)
87 elif state == State.close_win:
88 window_send.close()
89 window_send = None
90 window.write_event_value(NEXT_STATE, State.delay_2_sec)
91 elif event == sg.TIMER_KEY and state == State.delay_2_sec:
92 window.write_event_value(NEXT_STATE, State.enable_send)
93 elif state == State.delay_2_sec:
94 window.timer_start(TIMER2, repeating=False)
95 elif state == State.enable_send:
96 window['-SEND-'].update(disabled=False)
97 window.write_event_value(NEXT_STATE, State.stopped)
98
99 window.close()
100
101
102if __name__ == '__main__':

Callers 1

Calls 8

readMethod · 0.95
write_event_valueMethod · 0.95
timer_startMethod · 0.95
closeMethod · 0.95
make_send_windowFunction · 0.85
refreshMethod · 0.80
updateMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected