Merge pull request #2286 from PySimpleGUI/Dev-latest
Much more user friendly theme maker! Can choose window layout, etc
This commit is contained in:
commit
4a4afbab82
|
@ -1,6 +1,56 @@
|
|||
import PySimpleGUI as sg
|
||||
import color_themes
|
||||
|
||||
"""
|
||||
Program that is used to create new themes for use with PySimpleGUI's "Look and Feel" settings.
|
||||
You are presented with a grid of mini-windows that is created for color palettes downloaded from https://colorhunt.co/palettes
|
||||
The file color_themes.py contains a large dictionary of approx 1780 palettes.
|
||||
|
||||
For each palette you are shown 4 candidate themes, 2 "light" and 2 "dark". The window shows 5 palettes so you'll have a
|
||||
total of 20 candidate themes displayed in total.
|
||||
Each candidate theme has a 3 options - The button color (text and background), the text color for Input/Multiline elements,
|
||||
and the name of the theme when you save it. These you choose using the radio buttons and one input field.
|
||||
To "save" one of these candidate themes, check the checkbox to the left of the layout, choose the radio buttons for button
|
||||
& text settings and optionally change the theme name that is shown above the grid of OK buttons. By default the name starts
|
||||
with either "Dark" or "Light" and is followed by the first 2 "tags" that were posted with the palette on the colorhunt site.
|
||||
|
||||
After you've selected the themes you want to save from the window of 20 click any "OK" button in the window or close the
|
||||
window with the "X". You will see the dictionary text in the Debug Window and the values will also be written to a file.
|
||||
You'll then be shown the next group of 20 candidate themes.
|
||||
|
||||
If you want to exit the program entirely, click any "Cancel" button the page. Note - cliicking "Cancel" will not save any
|
||||
theme you have checked with the checkbox. You should only exit from a window you have not selected any themes for saving
|
||||
|
||||
If a Theme is selected for saving, then the values for the LOOK_AND_FEEL dictionary are displayed in a debug window and are
|
||||
also appended to the file new_theme_dict.py. You will need to edit the new_theme_dict.py file to get the syntax correct.
|
||||
A "," or "}" may need to be added in order to make the table be correct.
|
||||
|
||||
If you're using this program it's assumed you know what you're doing and understand the LOOK_AND_FEEL dictionary and can
|
||||
figure out how to get the syntax correct for adding it to the main dictionary of themes.
|
||||
"""
|
||||
|
||||
CANDIDATES_PER_ROW = 4
|
||||
PALETTES_PER_WINDOW = 5
|
||||
sg.change_look_and_feel('Dark Blue 3')
|
||||
layout = [
|
||||
[sg.T('Choose your window layout (default is a huge window)')],
|
||||
[sg.In(default_text=CANDIDATES_PER_ROW),sg.T('Candidates Per Row')],
|
||||
[sg.In(default_text=PALETTES_PER_WINDOW),sg.T('Palettes Per Window (4 candidates for each)')],
|
||||
[sg.OK()]]
|
||||
window = sg.Window('Choose Theme Layout', layout,default_element_size=(4,1))
|
||||
event, values = window.read()
|
||||
window.close()
|
||||
|
||||
if event is None:
|
||||
sg.popup_no_buttons('Aborting....', no_titlebar=True, auto_close=True, keep_on_top=True)
|
||||
exit()
|
||||
try:
|
||||
CANDIDATES_PER_ROW = int(values[0])
|
||||
TOTAL_CANDIDATES_PER_PAGE = int(values[1]) * 4
|
||||
except:
|
||||
sg.popup_no_buttons('Bad input... Aborting....', no_titlebar=True, auto_close=True, keep_on_top=True)
|
||||
exit()
|
||||
|
||||
def rgb_to_hsl(r, g, b):
|
||||
r = float(r)
|
||||
g = float(g)
|
||||
|
@ -32,6 +82,7 @@ def sorted_tuple(tup, position):
|
|||
tup.sort(key=lambda x: x[position])
|
||||
return tup
|
||||
|
||||
sg.popup_quick_message('Hang on this could me a few moments....', background_color='red', text_color='white', keep_on_top=True)
|
||||
|
||||
sg.LOOK_AND_FEEL_TABLE = {} # Entirely replace the look and feel table in PySimpleGUI
|
||||
for key, colors in color_themes.themes.items():
|
||||
|
@ -129,14 +180,14 @@ def sample_layout(theme_name, colors, description):
|
|||
layout = []
|
||||
row = []
|
||||
layouts = []
|
||||
for count, theme in enumerate(sg.ListOfLookAndFeelValues()):
|
||||
for count, theme in enumerate(sg.LOOK_AND_FEEL_TABLE.keys()):
|
||||
sg.change_look_and_feel(theme)
|
||||
if count and not(count % 4):
|
||||
if count and not(count % CANDIDATES_PER_ROW):
|
||||
layout += [row]
|
||||
row = []
|
||||
row += [sg.CB('',text_color='black', background_color=WINDOW_BACKGROUND, key='-CB-'+theme)]
|
||||
row += [sg.Frame(theme, sample_layout(theme, sg.LOOK_AND_FEEL_TABLE[theme]['COLOR_LIST'], sg.LOOK_AND_FEEL_TABLE[theme]['DESCRIPTION']))]
|
||||
if count and not (count % 20):
|
||||
if count and not (count % TOTAL_CANDIDATES_PER_PAGE):
|
||||
if layout:
|
||||
layouts.append(layout)
|
||||
layout = []
|
||||
|
@ -145,6 +196,7 @@ if row:
|
|||
if layout:
|
||||
layouts.append(layout)
|
||||
|
||||
print(f'len layouts = {len(layouts)}')
|
||||
for layout in layouts:
|
||||
window = sg.Window('PySimpleGUI Theme Maker', layout, background_color=WINDOW_BACKGROUND, default_element_size=(30,1))
|
||||
event, values = window.read()
|
||||
|
@ -195,6 +247,6 @@ for layout in layouts:
|
|||
sg.LOOK_AND_FEEL_TABLE[theme]['BUTTON'] = b_color
|
||||
with open('new_theme_dict.py', 'a') as outfile:
|
||||
outfile.write(f"'{values['-NEW_THEME_NAME-'+theme]}' : {sg.LOOK_AND_FEEL_TABLE[theme]},\n")
|
||||
print(f"'{values['-NEW_THEME_NAME-'+theme]}' : {sg.LOOK_AND_FEEL_TABLE[theme]}")
|
||||
sg.Print(f"'{values['-NEW_THEME_NAME-'+theme]}' : {sg.LOOK_AND_FEEL_TABLE[theme]}\n")
|
||||
window.close()
|
||||
del window
|
||||
|
|
Loading…
Reference in New Issue