Skip to content

Commit af44f73

Browse files
authored
Merge pull request PySimpleGUI#3673 from PySimpleGUI/Dev-latest
Settings window location. Moved settings file to OS settings folder, …
2 parents b4a92ae + a013ad6 commit af44f73

File tree

1 file changed

+16
-18
lines changed

1 file changed

+16
-18
lines changed

DemoPrograms/Demo_Desktop_Widget_Weather.py

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
2929
"""
3030

31-
SETTINGS_PATH = '.'
31+
SETTINGS_PATH = None # use the default settings path (OS settings foloder)
3232

3333
API_KEY = '' # Set using the "Settings" window and saved in your config file
3434

@@ -60,8 +60,7 @@ def load_settings():
6060
settings = sg.UserSettings(path=SETTINGS_PATH)
6161
API_KEY = settings['-api key-']
6262
if not API_KEY:
63-
sg.popup_quick_message('No valid API key found... opening setup window...', keep_on_top=True, background_color='red', text_color='white',
64-
auto_close_duration=3, non_blocking=False)
63+
sg.popup_quick_message('No valid API key found... opening setup window...', keep_on_top=True, background_color='red', text_color='white', auto_close_duration=3, non_blocking=False, location=win_location)
6564
change_settings(settings)
6665
return settings
6766

@@ -139,15 +138,15 @@ def request_weather_data(endpoint):
139138
global APP_DATA
140139

141140
if endpoint is None:
142-
sg.popup_error('Could not connect to api. endpoint is None', keep_on_top=True)
141+
sg.popup_error('Could not connect to api. endpoint is None', keep_on_top=True, location=win_location)
143142
return
144143
else:
145144
try:
146145
response = request.urlopen(endpoint)
147146
except request.HTTPError:
148147
sg.popup_error('ERROR Obtaining Weather Data',
149148
'Is your API Key set correctly?',
150-
API_KEY, keep_on_top=True)
149+
API_KEY, keep_on_top=True, location=win_location)
151150
return
152151

153152
if response.reason == 'OK':
@@ -177,14 +176,12 @@ def metric_row(metric):
177176
def create_window(win_location):
178177
""" Create the application window """
179178
col1 = sg.Column(
180-
[[sg.Text(APP_DATA['City'], font=('Arial Rounded MT Bold', 18), pad=((10, 0), (50, 0)), size=(18, 1), background_color=BG_COLOR, text_color=TXT_COLOR,
181-
key='City')],
179+
[[sg.Text(APP_DATA['City'], font=('Arial Rounded MT Bold', 18), pad=((10, 0), (50, 0)), size=(18, 1), background_color=BG_COLOR, text_color=TXT_COLOR, key='City')],
182180
[sg.Text(APP_DATA['Description'], font=('Arial', 12), pad=(10, 0), background_color=BG_COLOR, text_color=TXT_COLOR, key='Description')]],
183181
background_color=BG_COLOR, key='COL1')
184182

185183
col2 = sg.Column(
186-
[[sg.Text('×', font=('Arial Black', 16), pad=(0, 0), justification='right', background_color=BG_COLOR, text_color=TXT_COLOR, enable_events=True,
187-
key='-QUIT-')],
184+
[[sg.Text('×', font=('Arial Black', 16), pad=(0, 0), justification='right', background_color=BG_COLOR, text_color=TXT_COLOR, enable_events=True, key='-QUIT-')],
188185
[sg.Image(data=APP_DATA['Icon'], pad=((5, 10), (0, 0)), size=(100, 100), background_color=BG_COLOR, key='Icon')]],
189186
element_justification='center', background_color=BG_COLOR, key='COL2')
190187

@@ -214,7 +211,8 @@ def create_window(win_location):
214211
[bot_col]]
215212

216213
window = sg.Window(layout=layout, title='Weather Widget', margins=(0, 0), finalize=True, location=win_location,
217-
element_justification='center', keep_on_top=True, no_titlebar=True, grab_anywhere=True, alpha_channel=ALPHA)
214+
element_justification='center', keep_on_top=True, no_titlebar=True, grab_anywhere=True, alpha_channel=ALPHA,
215+
right_click_menu=[[''], 'Exit'])
218216

219217
for col in ['COL1', 'COL2', 'TopCOL', 'BotCOL', '-QUIT-']:
220218
window[col].expand(expand_y=True, expand_x=True)
@@ -263,16 +261,16 @@ def main(refresh_rate, win_location):
263261

264262
while True: # Event Loop
265263
event, values = window.read(timeout=refresh_in_milliseconds)
266-
if event in (None, '-QUIT-'):
264+
if event in (None, '-QUIT-', 'Exit'):
267265
break
268266
if event == '-CHANGE-':
269267
x, y = window.current_location()
270-
settings = change_settings(settings, (x + 405, y))
268+
settings = change_settings(settings, (x + 200, y+50))
271269
elif event == '-REFRESH-':
272270
sg.popup_quick_message('Refreshing...', keep_on_top=True, background_color='red', text_color='white',
273-
auto_close_duration=3, non_blocking=False)
271+
auto_close_duration=3, non_blocking=False, location=(win_location[0]+170, win_location[1]+150))
274272
elif event != sg.TIMEOUT_KEY:
275-
sg.Print('Unknown event received\nEvent & values:\n', event, values)
273+
sg.Print('Unknown event received\nEvent & values:\n', event, values, location=win_location)
276274

277275
update_weather()
278276
update_metrics(window)
@@ -281,8 +279,8 @@ def main(refresh_rate, win_location):
281279

282280
if __name__ == '__main__':
283281
if len(sys.argv) > 1:
284-
location = sys.argv[1].split(',')
285-
location = (int(location[0]), int(location[1]))
282+
win_location = sys.argv[1].split(',')
283+
win_location = (int(win_location[0]), int(win_location[1]))
286284
else:
287-
location = (None, None)
288-
main(refresh_rate=1, win_location=location)
285+
win_location = (None, None)
286+
main(refresh_rate=1, win_location=win_location)

0 commit comments

Comments
 (0)