()
| 92 | |
| 93 | |
| 94 | def main(): |
| 95 | loc = sg.user_settings_get_entry('-location-', (None, None)) |
| 96 | window = make_window(loc) |
| 97 | |
| 98 | counter = sg.user_settings_get_entry('-counter-', 0) |
| 99 | sound_file = sg.user_settings_get_entry('-sound file-', None) |
| 100 | |
| 101 | while True: # Event Loop |
| 102 | # First update the status information |
| 103 | window['-MAIN INFO NUM-'].update(counter) |
| 104 | # for debugging show the last update date time |
| 105 | |
| 106 | # -------------- Start of normal event loop -------------- |
| 107 | event, values = window.read() |
| 108 | print(event, values) |
| 109 | if event == sg.WIN_CLOSED: |
| 110 | break |
| 111 | elif event in (sg.WIN_CLOSE_ATTEMPTED_EVENT, 'Exit'): |
| 112 | sg.user_settings_set_entry('-location-', window.current_location()) |
| 113 | break |
| 114 | if event == 'Edit Me': |
| 115 | sg.execute_editor(__file__) |
| 116 | elif event == 'Set Counter': |
| 117 | new_count = sg.popup_get_text('What value do you want to set the counter to?', location=window.current_location(), keep_on_top=True) |
| 118 | try: |
| 119 | new_count = int(new_count) |
| 120 | except Exception as e: |
| 121 | sg.popup_error('Counter must be a valid int') |
| 122 | continue |
| 123 | if new_count is not None: |
| 124 | counter = int(new_count) |
| 125 | elif event == 'Choose Title': |
| 126 | new_title = sg.popup_get_text('Choose a title for your counter', default_text=sg.user_settings_get_entry('-title-', ''), location=window.current_location(), ) |
| 127 | if new_title is not None: |
| 128 | window['-TITLE-'].update(new_title) |
| 129 | sg.user_settings_set_entry('-title-', new_title) |
| 130 | elif event in [str(x) for x in range(1, 11)]: |
| 131 | window.set_alpha(int(event) / 10) |
| 132 | sg.user_settings_set_entry('-alpha-', int(event) / 10) |
| 133 | elif event == 'Change Theme': |
| 134 | loc = window.current_location() |
| 135 | if choose_theme(loc) is not None: |
| 136 | # this is result of hacking code down to 99 lines in total. Not tried it before. Interesting test. |
| 137 | _, window = window.close(), make_window(loc) |
| 138 | elif event == 'Set Main Font': |
| 139 | font = sg.popup_get_text('Main Information Font and Size (e.g. courier 70)', default_text=sg.user_settings_get_entry('-main number font-'), keep_on_top=False, location=window.current_location()) |
| 140 | if font: |
| 141 | sg.user_settings_set_entry('-main number font-', font) |
| 142 | _, window = window.close(), make_window(loc) |
| 143 | elif event == 'Set Button Font': |
| 144 | font = sg.popup_get_text('Font for the +/- symbols (e.g. courier 70)', default_text=sg.user_settings_get_entry('-button font-'), keep_on_top=True, location=window.current_location()) |
| 145 | if font: |
| 146 | sg.user_settings_set_entry('-button font-', font) |
| 147 | _, window = window.close(), make_window(loc) |
| 148 | elif event == 'Set Title Font': |
| 149 | font = sg.popup_get_text('Title Font and Size (e.g. courier 8)', default_text=sg.user_settings_get_entry('-title font-'), keep_on_top=True, location=window.current_location()) |
| 150 | if font: |
| 151 | sg.user_settings_set_entry('-title font-', font) |
no test coverage detected