MCPcopy Index your code
hub / github.com/PySimpleGUI/PySimpleGUI / choose_theme

Function choose_theme

DemoPrograms/Demo_Desktop_Widget_Template.py:47–85  ·  view source on GitHub ↗

A window to allow new themes to be tried out. Changes the theme to the newly chosen one and returns theme's name Automaticallyi switches to new theme and saves the setting in user settings file :param location: (x,y) location of the Widget's window :type location: Tuple[int, i

(location, size)

Source from the content-addressed store, hash-verified

45UPDATE_FREQUENCY_MILLISECONDS = 1000 * 60 * 60 # update every hour by default until set by user
46
47def choose_theme(location, size):
48 """
49 A window to allow new themes to be tried out.
50 Changes the theme to the newly chosen one and returns theme's name
51 Automaticallyi switches to new theme and saves the setting in user settings file
52
53 :param location: (x,y) location of the Widget's window
54 :type location: Tuple[int, int]
55 :param size: Size in pixels of the Widget's window
56 :type size: Tuple[int, int]
57 :return: The name of the newly selected theme
58 :rtype: None | str
59 """
60 layout = [[sg.Text('Try a theme')],
61 [sg.Listbox(values=sg.theme_list(), size=(20, 20), key='-LIST-', enable_events=True)],
62 [sg.OK(), sg.Cancel()]]
63
64 window = sg.Window('Look and Feel Browser', layout, location=location, keep_on_top=True)
65 old_theme = sg.theme()
66 while True: # Event Loop
67 event, values = window.read()
68 if event in (sg.WIN_CLOSED, 'Exit', 'OK', 'Cancel'):
69 break
70 sg.theme(values['-LIST-'][0])
71 window.hide()
72 # make at test window to the left of the current one
73 test_window = make_window(location=((location[0]-size[0]*1.2, location[1])), test_window=True)
74 test_window.read(close=True)
75 window.un_hide()
76 window.close()
77
78 # after choice made, save theme or restore the old one
79 if event == 'OK' and values['-LIST-']:
80 sg.theme(values['-LIST-'][0])
81 sg.user_settings_set_entry('-theme-', values['-LIST-'][0])
82 return values['-LIST-'][0]
83 else:
84 sg.theme(old_theme)
85 return None
86
87def make_window(location, test_window=False):
88 """

Callers 1

mainFunction · 0.70

Calls 5

readMethod · 0.95
hideMethod · 0.95
un_hideMethod · 0.95
closeMethod · 0.95
make_windowFunction · 0.70

Tested by

no test coverage detected