Merge pull request #5560 from PySimpleGUI/Dev-latest

Added settings to the right click menu in addition to link in the win…
This commit is contained in:
PySimpleGUI 2022-06-04 13:18:23 -04:00 committed by GitHub
commit ef6c82e164
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 21 deletions

View File

@ -226,7 +226,7 @@ def create_window(win_location):
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,
right_click_menu=[[''], ['Edit Me', 'Versions', 'Exit',]], enable_close_attempted_event=True) right_click_menu=[[''], ['Edit Me', 'Versions', 'Settings', 'Exit',]], enable_close_attempted_event=True)
for col in ['COL1', 'COL2', 'TopCOL', 'BotCOL', '-QUIT-']: for col in ['COL1', 'COL2', 'TopCOL', 'BotCOL', '-QUIT-']:
window[col].expand(expand_y=True, expand_x=True) window[col].expand(expand_y=True, expand_x=True)
@ -278,13 +278,13 @@ def main(refresh_rate, win_location):
exit() exit()
window = create_window(win_location) window = create_window(win_location)
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):
sg.user_settings_set_entry('-win location-', window.current_location()) # The line of code to save the position before exiting sg.user_settings_set_entry('-win location-', window.current_location()) # The line of code to save the position before exiting
break break
if event == '-CHANGE-': if event in ('-CHANGE-', 'Settings'):
x, y = window.current_location() x, y = window.current_location()
settings = change_settings(settings, (x + 200, y+50)) settings = change_settings(settings, (x + 200, y+50))
elif event == '-REFRESH-': elif event == '-REFRESH-':
@ -293,12 +293,14 @@ def main(refresh_rate, win_location):
elif event == 'Edit Me': elif event == 'Edit Me':
sg.execute_editor(__file__) sg.execute_editor(__file__)
elif event == 'Versions': elif event == 'Versions':
sg.main_get_debug_data() sg.popup_scrolled(__file__, sg.get_versions(), keep_on_top=True, location=window.current_location())
elif event != sg.TIMEOUT_KEY: elif event != sg.TIMEOUT_KEY:
sg.Print('Unknown event received\nEvent & values:\n', event, values, location=win_location) sg.Print('Unknown event received\nEvent & values:\n', event, values, location=win_location, keep_on_top=True)
update_weather() update_weather()
update_metrics(window) update_metrics(window)
except Exception as e:
sg.Print('Exception in Weather Widget event loop', sg.__file__, e, keep_on_top=True, wait=True, location=win_location)
window.close() window.close()