Add the now standard "save last location" code that most of the "Desktop Widget" demo programs have

This commit is contained in:
PySimpleGUI 2022-09-07 09:18:20 -04:00
parent 6c480dcf1c
commit 9a31a75be1
1 changed files with 5 additions and 4 deletions

View File

@ -275,7 +275,7 @@ def main(location):
[sg.T(size=(8, 1), font='Any 14', justification='c', background_color='black', k='-RAM USED-')], [sg.T(size=(8, 1), font='Any 14', justification='c', background_color='black', k='-RAM USED-')],
] ]
window = sg.Window('CPU Usage Widget Square', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_padding=(0, 0), alpha_channel=ALPHA, background_color='black', element_justification='c', finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT) window = sg.Window('CPU Usage Widget Square', layout, location=location, no_titlebar=True, grab_anywhere=True, margins=(0, 0), element_padding=(0, 0), alpha_channel=ALPHA, background_color='black', element_justification='c', finalize=True, right_click_menu=sg.MENU_RIGHT_CLICK_EDITME_VER_EXIT, enable_close_attempted_event=True)
gauge = Gauge(pointer_color=sg.theme_text_color(), clock_color=sg.theme_text_color(), major_tick_color=sg.theme_text_color(), gauge = Gauge(pointer_color=sg.theme_text_color(), clock_color=sg.theme_text_color(), major_tick_color=sg.theme_text_color(),
minor_tick_color=sg.theme_input_background_color(), pointer_outer_color=sg.theme_text_color(), major_tick_start_radius=45, minor_tick_color=sg.theme_input_background_color(), pointer_outer_color=sg.theme_text_color(), major_tick_start_radius=45,
@ -290,7 +290,7 @@ def main(location):
if gauge.change(): if gauge.change():
new_angle = ram_percent*180/100 new_angle = ram_percent*180/100
window['-gauge VALUE-'].update(f'{ram_percent}') window['-gauge VALUE-'].update(f'{ram_percent}%')
window['-RAM USED-'].update(f'{human_size(ram.used)}') window['-RAM USED-'].update(f'{human_size(ram.used)}')
gauge.change(degree=new_angle, step=180) gauge.change(degree=new_angle, step=180)
gauge.change() gauge.change()
@ -298,7 +298,8 @@ def main(location):
# update the window, wait for a while, then check for exit # update the window, wait for a while, then check for exit
event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS) event, values = window.read(timeout=UPDATE_FREQUENCY_MILLISECONDS)
if event == sg.WIN_CLOSED or event == 'Exit': if 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 break
if event == 'Edit Me': if event == 'Edit Me':
sg.execute_editor(__file__) sg.execute_editor(__file__)
@ -313,5 +314,5 @@ if __name__ == '__main__':
location = sys.argv[1].split(',') location = sys.argv[1].split(',')
location = (int(location[0]), int(location[1])) location = (int(location[0]), int(location[1]))
else: else:
location = (None, None) location = sg.user_settings_get_entry('-location-', (None, None))
main(location) main(location)