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

Function main

DemoPrograms/Demo_Desktop_Widget_Date.py:117–190  ·  view source on GitHub ↗

Where execution begins The Event Loop lives here, but the window creation is done in another function This is an important design pattern :param location: Location to create the main window if one is not found in the user settings :type location: Tuple[int, int]

(location)

Source from the content-addressed store, hash-verified

115
116
117def main(location):
118 """
119 Where execution begins
120 The Event Loop lives here, but the window creation is done in another function
121 This is an important design pattern
122
123 :param location: Location to create the main window if one is not found in the user settings
124 :type location: Tuple[int, int]
125 """
126
127 window = make_window(sg.user_settings_get_entry('-location-', location))
128
129 refresh_frequency = sg.user_settings_get_entry('-fresh frequency-', UPDATE_FREQUENCY_MILLISECONDS)
130
131 while True: # Event Loop
132 # Normally a window.read goes here, but first we're updating the values in the window, then reading it
133 # First update the status information
134 window['-MAIN INFO-'].update(get_date_string())
135 # for debugging show the last update date time
136 if sg.user_settings_get_entry('-title-', 'None') in ('None', 'Hide'):
137 window['-TITLE-'].update(visible=False)
138 else:
139 window['-TITLE-'].update(sg.user_settings_get_entry('-title-', 'None'),visible=True)
140 window['-REFRESHED-'].update(datetime.now().strftime("%m/%d/%Y\n%I:%M:%S %p"))
141
142 # -------------- Start of normal event loop --------------
143 event, values = window.read(timeout=refresh_frequency)
144 print(event, values)
145 if event in (sg.WIN_CLOSED, 'Exit'): # standard exit test... ALWAYS do this
146 break
147 if event == 'Edit Me':
148 sg.execute_editor(__file__)
149 elif event == 'Choose Title':
150 new_title = sg.popup_get_text('Choose a title for your Widget\nEnter None if you do not want anything displayed', location=window.current_location())
151 if new_title is not None:
152 if new_title in ('None', 'Hide'):
153 window['-TITLE-'].update(visible=False)
154 else:
155 window['-TITLE-'].update(new_title, visible=True)
156 sg.user_settings_set_entry('-title-', new_title)
157 elif event == 'Show Refresh Info':
158 window['-REFRESHED-'].update(visible=True)
159 sg.user_settings_set_entry('-show refresh-', True)
160 elif event == 'Save Location':
161 sg.user_settings_set_entry('-location-', window.current_location())
162 sg.popup_notify(f'Saved your current window location:', window.current_location(), title='Saved Location')
163 elif event == 'Hide Refresh Info':
164 window['-REFRESHED-'].update(visible=False)
165 sg.user_settings_set_entry('-show refresh-', False)
166 elif event in [str(x) for x in range(1, 11)]: # if Alpha Channel was chosen
167 window.set_alpha(int(event) / 10)
168 sg.user_settings_set_entry('-alpha-', int(event) / 10)
169 elif event == 'Set Refresh Rate':
170 choice = sg.popup_get_text('How frequently to update window in seconds? (can be a float)',
171 default_text=sg.user_settings_get_entry('-fresh frequency-', UPDATE_FREQUENCY_MILLISECONDS) / 1000,
172 location=window.current_location())
173 if choice is not None:
174 try:

Callers 1

Calls 8

get_date_stringFunction · 0.85
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