Merge pull request #5627 from PySimpleGUI/Dev-latest
Addition of try around event loop to catch errors generated by the We…
This commit is contained in:
commit
5569ea7ec2
|
@ -223,7 +223,7 @@ def create_window(win_location, settings):
|
|||
layout = [[top_col],
|
||||
[lf_col, rt_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,
|
||||
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)
|
||||
|
||||
try:
|
||||
while True: # Event Loop
|
||||
event, values = window.read(timeout=refresh_in_milliseconds)
|
||||
if event in (None, '-QUIT-', 'Exit', sg.WIN_CLOSE_ATTEMPTED_EVENT):
|
||||
|
@ -302,6 +303,10 @@ def main(refresh_rate, win_location):
|
|||
|
||||
update_weather()
|
||||
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()
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue