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

Function main

DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py:152–287  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

150
151
152def main():
153 loc = sg.user_settings_get_entry('-location-', (None, None))
154 sg.theme(sg.user_settings_get_entry('-theme-', None))
155
156 time_per_image = sg.user_settings_get_entry('-time per image-', 60)
157 vary_randomly = sg.user_settings_get_entry('-random time-', False)
158 width, height = sg.user_settings_get_entry('-image size-', (None, None))
159 image_folder = sg.user_settings_get_entry('-image_folder-', None)
160
161 try:
162 os.listdir(image_folder) # Try reading the folder to check to see if it is read
163 except:
164 image_folder = None
165 sg.user_settings_set_entry('-image_folder-', None)
166
167 image_name = single_image = sg.user_settings_get_entry('-single image-', None)
168
169 if image_folder is None and single_image is None:
170 image_name = single_image = sg.popup_get_file('Choose a starting image', keep_on_top=True)
171 if not single_image:
172 if sg.popup_yes_no('No folder entered', 'Go you want to exit the program entirely?',
173 keep_on_top=True) == 'Yes':
174 exit()
175 if image_folder is not None and single_image is None:
176 images = os.listdir(image_folder)
177 images = [i for i in images if i.lower().endswith(('.png', '.jpg', '.gif'))]
178 image_name = os.path.join(image_folder, random.choice(images))
179 else: # means single image is not none
180 images = None
181 image_name = single_image
182 window = make_window(loc)
183
184 window_size = window.size
185 image_data = convert_to_bytes(image_name, (width, height))
186
187 while True: # Event Loop
188 # -------------- Start of normal event loop --------------
189 timeout = time_per_image * 1000 + (random.randint(int(-time_per_image * 500),
190 int(time_per_image * 500)) if vary_randomly else 0) if single_image is None else None
191 event, values = window.read(timeout=timeout)
192 if event == sg.WIN_CLOSED:
193 break
194 elif event in (sg.WIN_CLOSE_ATTEMPTED_EVENT, 'Exit'):
195 sg.user_settings_set_entry('-location-',
196 window.current_location()) # The line of code to save the position before exiting
197 break
198 # First update the status information
199 # for debugging show the last update date time
200 if event == sg.TIMEOUT_EVENT:
201 if single_image is None:
202 image_name = random.choice(images)
203 image_data = convert_to_bytes(os.path.join(image_folder, image_name))
204 window['-FOLDER-'].update(image_folder)
205 else:
206 image_name = single_image
207 image_data = convert_to_bytes(single_image, (width, height))
208 window['-FILENAME-'].update(image_name)
209 window['-IMAGE-'].update(data=image_data)

Calls 9

get_image_sizeFunction · 0.85
current_locationMethod · 0.80
set_alphaMethod · 0.80
make_windowFunction · 0.70
convert_to_bytesFunction · 0.70
choose_themeFunction · 0.70
readMethod · 0.45
updateMethod · 0.45
closeMethod · 0.45

Tested by

no test coverage detected