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

Function main

DemoPrograms/Demo_Desktop_Widget_Days_Counter.py:95–156  ·  view source on GitHub ↗
(location)

Source from the content-addressed store, hash-verified

93 return window
94
95def main(location):
96 loc = sg.user_settings_get_entry('-location-', location)
97 window = make_window(loc)
98
99 saved_date = sg.user_settings_get_entry('-start date-', (1,1,2021))
100 start_date = datetime.datetime(saved_date[2], saved_date[0], saved_date[1])
101
102 while True: # Event Loop
103 # First update the status information
104 delta = datetime.datetime.now() - start_date
105 window['-MAIN INFO-'].update(f'{delta.days}')
106
107 # for debugging show the last update date time
108 window['-REFRESHED-'].update(datetime.datetime.now().strftime("%m/%d/%Y\n%I:%M:%S %p"))
109
110 # -------------- Start of normal event loop --------------
111 event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS)
112 print(event, values)
113 if event == sg.WIN_CLOSED or event == 'Exit':
114 break
115 if event == 'Edit Me':
116 sg.execute_editor(__file__)
117 elif event == 'Choose Date':
118 new_start = sg.popup_get_date(location=window.current_location(), keep_on_top=True)
119 if new_start is not None:
120 start_date = datetime.datetime(new_start[2], new_start[0], new_start[1])
121 sg.user_settings_set_entry('-start date-', new_start)
122 elif event == 'Choose Title':
123 new_title = sg.popup_get_text('Choose a title for your date', location=window.current_location(), keep_on_top=True)
124 if new_title is not None:
125 window['-TITLE-'].update(new_title)
126 sg.user_settings_set_entry('-title-', new_title)
127 elif event == 'Show Refresh Info':
128 window['-REFRESHED-'].update(visible=True)
129 sg.user_settings_set_entry('-show refresh-', True)
130 elif event == 'Save Location':
131 sg.user_settings_set_entry('-location-', window.current_location())
132 elif event == 'Hide Refresh Info':
133 window['-REFRESHED-'].update(visible=False)
134 sg.user_settings_set_entry('-show refresh-', False)
135 elif event in [str(x) for x in range(1,11)]:
136 window.set_alpha(int(event)/10)
137 sg.user_settings_set_entry('-alpha-', int(event)/10)
138 elif event == 'Change Theme':
139 loc = window.current_location()
140 if choose_theme(loc) is not None:
141 # this is result of hacking code down to 99 lines in total. Not tried it before. Interesting test.
142 _, window = window.close(), make_window(loc)
143 elif event == 'Set Main Font':
144 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=True)
145 if font:
146 sg.user_settings_set_entry('-main number 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)
150 if font:
151 sg.user_settings_set_entry('-title font-', font)
152 _, window = window.close(), make_window(loc)

Calls 7

current_locationMethod · 0.80
set_alphaMethod · 0.80
make_windowFunction · 0.70
choose_themeFunction · 0.70
updateMethod · 0.45
readMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected