spyoungtech / FreeSimpleGUI

The free-forever GUI library
GNU Lesser General Public License v3.0
228 stars 26 forks source link

Suggestion for the theme_previewer to return the selected theme #20

Closed RoboPickle closed 4 days ago

RoboPickle commented 2 weeks ago

theme_previewer

It would be useful if the theme_previewer could take a more active part in the selection of the themes.

Current behaviour

Currently the theme_previewer provides a static example of all the themes. The caller needs to also then provide a mechanism to handle the selection of the theme, such as a scrollable list.

Recommendation

The theme_previewer function is updated so that the individual example frames “Ok” buttons can return the name of the theme.

Resolution

I will be creating a pull request with a solution for this.

Example usage

The following example code can demonstrate how it would be used.

import FreeSimpleGUI as sg
from FreeSimpleGUI import Text, Button, InputText, Slider, Window

def get_layout():
    return [
        [Text(f'Current Theme: {current_theme}', size=(40,1))],
        [Text('Example Text'), InputText('Input data here', size=(10, 1), expand_x=True)],
        [Button('Ok'), Button('Disabled', disabled=True),],
        [Slider((1, 100), orientation='h', size=(5, 15), expand_x=True)],
        [Button('Preview Themes', key="Preview"), Button('Quit'),],
    ]

def rebuild_window(win:Window = None):
    if win:
        win.close()

    return Window(
        'Preview of Themes',
        get_layout(),
        resizable=True,
        finalize=True,
    )

current_theme = sg.theme()
window = rebuild_window()    
event, values = window.read()
while event == "Preview":
    new_theme = sg.preview_all_look_and_feel_themes(scrollable=True,columns=8)
    if new_theme not in (None, current_theme):
        current_theme = new_theme
        sg.theme(new_theme)
        window = rebuild_window(window)
    event, values = window.read()
spyoungtech commented 1 week ago

Thanks. I think this is a good improvement for theme_previewer. It may take me a few more days, but I will review your PR soon :)