()
| 79 | |
| 80 | |
| 81 | def main(): |
| 82 | layout = [[sg.Text('Window with periodic time events')], |
| 83 | [sg.Text(key='-MESSAGE-')], |
| 84 | [sg.Text('Timer Status:'), sg.Text(key='-TIMER STATUS-')], |
| 85 | [sg.Text('Duration:'), sg.In(s=3, key='-DURATION-'), sg.Button('Start')], |
| 86 | [sg.Text('Timer ID:'), sg.In(s=3, key='-STOP ID-'), sg.Button('Stop'),], |
| 87 | [ sg.Button('Dummy'), sg.Button('Exit')], ] |
| 88 | |
| 89 | window = sg.Window('Blinking LED Window', layout) |
| 90 | |
| 91 | timer_counter = 0 |
| 92 | # --------------------- EVENT LOOP --------------------- |
| 93 | while True: |
| 94 | event, values = window.read() |
| 95 | if event in (sg.WIN_CLOSED, 'Exit'): |
| 96 | break |
| 97 | window['-MESSAGE-'].update(f'{event} {values}') |
| 98 | window['-TIMER STATUS-'].update(f'{timer_running}') |
| 99 | if event == 'Start': |
| 100 | if values['-DURATION-']: |
| 101 | timer_status_change(timer_counter, start=True) |
| 102 | window.start_thread(lambda: periodic_timer_thread(window, float(values['-DURATION-']), timer_counter), ('-THREAD-', '-THREAD ENDED-')) |
| 103 | timer_counter += 1 |
| 104 | else: |
| 105 | window['-MESSAGE-'].update('Please enter a numeric duration') |
| 106 | elif event == 'Stop': |
| 107 | if values['-STOP ID-']: |
| 108 | timer_status_change(int(values['-STOP ID-']), stop=True) |
| 109 | |
| 110 | window.close() |
| 111 | |
| 112 | if __name__ == '__main__': |
| 113 | main() |
no test coverage detected