From 3b093e1c4ae84106ed1e8c4d90f14db5e3969a05 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 15 Aug 2021 17:53:35 -0400 Subject: [PATCH 1/2] Renamed the user settings key for window location to '-location-' --- DemoPrograms/Demo_Auto_Save_Window_Position.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/DemoPrograms/Demo_Auto_Save_Window_Position.py b/DemoPrograms/Demo_Auto_Save_Window_Position.py index e83314c1..ef7f6368 100644 --- a/DemoPrograms/Demo_Auto_Save_Window_Position.py +++ b/DemoPrograms/Demo_Auto_Save_Window_Position.py @@ -17,13 +17,13 @@ import PySimpleGUI as sg layout = [[sg.Text('Window that Auto-saves position', font='_ 25')], [sg.Button('Ok'), sg.Button('Exit')]] -window = sg.Window('Auto-saves Location', layout, enable_close_attempted_event=True, location=sg.user_settings_get_entry('-position-', (None, None))) +window = sg.Window('Auto-saves Location', layout, enable_close_attempted_event=True, location=sg.user_settings_get_entry('-location-', (None, None))) while True: event, values = window.read() print(event, values) if event in ('Exit', sg.WINDOW_CLOSE_ATTEMPTED_EVENT): - sg.user_settings_set_entry('-position-', window.current_location()) # The line of code to save the position before exiting + sg.user_settings_set_entry('-location-', window.current_location()) # The line of code to save the position before exiting break window.close() From 8cef4831e8382a9ed7d06db8282f09e640eca696 Mon Sep 17 00:00:00 2001 From: PySimpleGUI Date: Sun, 15 Aug 2021 17:54:15 -0400 Subject: [PATCH 2/2] Added auto-save of window location upon exit. This is going to be a new design pattern to be applied to all desktop widgets eventually --- DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py b/DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py index 10e29479..8ee2c959 100644 --- a/DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py +++ b/DemoPrograms/Demo_Desktop_Widget_Digital_Picture_Frame.py @@ -61,7 +61,7 @@ def make_window(location): layout = [[sg.Image(k='-IMAGE-', enable_events=True)], [sg.pin(sg.Column(refresh_info, key='-REFRESH INFO-', element_justification='c', visible=sg.user_settings_get_entry('-show refresh-', True)))]] - window = sg.Window('Photo Frame', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_justification='c', element_padding=(0, 0), alpha_channel=alpha, finalize=True, right_click_menu=right_click_menu, keep_on_top=True) + window = sg.Window('Photo Frame', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_justification='c', element_padding=(0, 0), alpha_channel=alpha, finalize=True, right_click_menu=right_click_menu, keep_on_top=True, enable_close_attempted_event=True) return window @@ -115,7 +115,10 @@ def main(): # -------------- Start of normal event loop -------------- timeout = time_per_image * 1000 + (random.randint(int(-time_per_image * 500), int(time_per_image * 500)) if vary_randomly else 0) if single_image is None else None event, values = window.read(timeout=timeout) - if event == sg.WIN_CLOSED or event == 'Exit': + if event == sg.WIN_CLOSED: + break + elif event in (sg.WIN_CLOSE_ATTEMPTED_EVENT, 'Exit'): + sg.user_settings_set_entry('-location-', window.current_location()) # The line of code to save the position before exiting break if event == 'Edit Me': sg.execute_editor(__file__)