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)
| 24 | |
| 25 | |
| 26 | def choose_theme(location, size): |
| 27 | """ |
| 28 | A window to allow new themes to be tried out. |
| 29 | Changes the theme to the newly chosen one and returns theme's name |
| 30 | Automaticallyi switches to new theme and saves the setting in user settings file |
| 31 | |
| 32 | :param location: (x,y) location of the Widget's window |
| 33 | :type location: Tuple[int, int] |
| 34 | :param size: Size in pixels of the Widget's window |
| 35 | :type size: Tuple[int, int] |
| 36 | :return: The name of the newly selected theme |
| 37 | :rtype: None | str |
| 38 | """ |
| 39 | layout = [[sg.Text('Try a theme')], |
| 40 | [sg.Listbox(values=sg.theme_list(), size=(20, 20), key='-LIST-', enable_events=True)], |
| 41 | [sg.OK(), sg.Cancel()]] |
| 42 | |
| 43 | window = sg.Window('Look and Feel Browser', layout, location=location) |
| 44 | old_theme = sg.theme() |
| 45 | while True: # Event Loop |
| 46 | event, values = window.read() |
| 47 | if event in (sg.WIN_CLOSED, 'Exit', 'OK', 'Cancel'): |
| 48 | break |
| 49 | sg.theme(values['-LIST-'][0]) |
| 50 | window.hide() |
| 51 | # make at test window to the left of the current one |
| 52 | test_window = make_window(location=((location[0] - size[0] * 1.2, location[1])), test_window=True) |
| 53 | test_window.read(close=True) |
| 54 | window.un_hide() |
| 55 | window.close() |
| 56 | |
| 57 | # after choice made, save theme or restore the old one |
| 58 | if event == 'OK' and values['-LIST-']: |
| 59 | sg.theme(values['-LIST-'][0]) |
| 60 | sg.user_settings_set_entry('-theme-', values['-LIST-'][0]) |
| 61 | return values['-LIST-'][0] |
| 62 | else: |
| 63 | sg.theme(old_theme) |
| 64 | return None |
| 65 | |
| 66 | |
| 67 | def make_window(location, test_window=False): |