Skip to content

Commit 58b987b

Browse files
theme_previewer changes. (#21)
* theme_previewer changes. User can now choose a theme by clicking on the OK button of the previewed theme. The function returns the theme name. e.g. new_theme = sg.preview_all_look_and_feel_themes(scrollable=True,columns=8) if new_theme: sg.theme(new_theme) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent f221122 commit 58b987b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

FreeSimpleGUI/__init__.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9109,6 +9109,7 @@ def theme_previewer(columns=12, scrollable=False, scroll_area_size=(None, None),
91099109
"""
91109110
Displays a "Quick Reference Window" showing all of the different Look and Feel settings that are available.
91119111
They are sorted alphabetically. The legacy color names are mixed in, but otherwise they are sorted into Dark and Light halves
9112+
If one of the "OK" buttons are pressed then that theme name is returned.
91129113

91139114
:param columns: The number of themes to display per row
91149115
:type columns: int
@@ -9138,10 +9139,10 @@ def theme_previewer(columns=12, scrollable=False, scroll_area_size=(None, None),
91389139

91399140
win_bg = 'black'
91409141

9141-
def sample_layout():
9142+
def sample_layout(theme_name):
91429143
return [
91439144
[Text('Text element'), InputText('Input data here', size=(10, 1))],
9144-
[Button('Ok'), Button('Disabled', disabled=True), Slider((1, 10), orientation='h', size=(5, 15))],
9145+
[Button('Ok', key=f"choose_{theme_name}", tooltip=f"Choose {theme_name}"), Button('Disabled', disabled=True), Slider((1, 10), orientation='h', size=(5, 15))],
91459146
]
91469147

91479148
names = list_of_look_and_feel_values()
@@ -9161,7 +9162,7 @@ def sample_layout():
91619162
if not count % columns:
91629163
col_layout += [row]
91639164
row = []
9164-
row += [Frame(theme_name, sample_layout() if not web else [[T(theme_name)]] + sample_layout(), pad=(2, 2))]
9165+
row += [Frame(theme_name, sample_layout(theme_name) if not web else [[T(theme_name)]] + sample_layout(theme_name), pad=(2, 2))]
91659166
if row:
91669167
col_layout += [row]
91679168

@@ -9188,8 +9189,10 @@ def sample_layout():
91889189
modal=True,
91899190
)
91909191
window['-COL-'].expand(True, True, True) # needed so that col will expand with the window
9191-
window.read(close=True)
9192+
event, values = window.read(close=True)
91929193
theme(current_theme)
9194+
if event and event.startswith('choose_'):
9195+
return event[7:]
91939196

91949197

91959198
preview_all_look_and_feel_themes = theme_previewer

0 commit comments

Comments
 (0)