Addition of try around event loop to catch errors generated by the Weather API. Simplified/shortened the version information at the bottom

This commit is contained in:
PySimpleGUI 2022-06-21 15:32:17 -04:00
parent a526b282cd
commit 03922d77b6
1 changed files with 27 additions and 22 deletions

View File

@ -223,7 +223,7 @@ def create_window(win_location, settings):
layout = [[top_col], layout = [[top_col],
[lf_col, rt_col], [lf_col, rt_col],
[bot_col], [bot_col],
[sg.Text(f'{sg.ver} {sg.framework_version} {sys.version}', font=('Arial', 8), justification='c', background_color=BG_COLOR, text_color=TXT_COLOR, pad=(0,0), expand_x=True)]] [sg.Text(f'PSG: {sg.ver} Tk:{sg.framework_version} Py:{sys.version_info.major}.{sys.version_info.minor}.{sys.version_info.micro}', font=('Arial', 8), justification='c', background_color=BG_COLOR, text_color=TXT_COLOR, pad=(0,0), expand_x=True)]]
window = sg.Window(layout=layout, title='Weather Widget', margins=(0, 0), finalize=True, location=win_location, window = sg.Window(layout=layout, title='Weather Widget', margins=(0, 0), finalize=True, location=win_location,
element_justification='center', keep_on_top=True, no_titlebar=True, grab_anywhere=True, alpha_channel=ALPHA, element_justification='center', keep_on_top=True, no_titlebar=True, grab_anywhere=True, alpha_channel=ALPHA,
@ -280,6 +280,7 @@ def main(refresh_rate, win_location):
window = create_window(win_location, settings) window = create_window(win_location, settings)
try:
while True: # Event Loop while True: # Event Loop
event, values = window.read(timeout=refresh_in_milliseconds) event, values = window.read(timeout=refresh_in_milliseconds)
if event in (None, '-QUIT-', 'Exit', sg.WIN_CLOSE_ATTEMPTED_EVENT): if event in (None, '-QUIT-', 'Exit', sg.WIN_CLOSE_ATTEMPTED_EVENT):
@ -302,6 +303,10 @@ def main(refresh_rate, win_location):
update_weather() update_weather()
update_metrics(window) update_metrics(window)
except Exception as e:
sg.Print('*** GOT Exception in event loop ***', c='white on red', location=window.current_location(), keep_on_top=True)
sg.Print('File = ', __file__, f'Window title: {window.Title}')
sg.Print('Exception = ', e, wait=True) # IMPORTANT to add a wait/blocking so that the print pauses execution. Otherwise program continue and exits
window.close() window.close()