2021-07-14 06:14:04 +00:00
|
|
|
'''
|
|
|
|
configure
|
|
|
|
=========
|
|
|
|
|
2021-07-16 01:28:48 +00:00
|
|
|
Configure icons, stylesheets, and resource files.
|
2021-07-14 06:14:04 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
import glob
|
|
|
|
import os
|
|
|
|
|
|
|
|
home = os.path.dirname(os.path.realpath(__file__))
|
|
|
|
# TODO(ahuszagh) Need a script to generate the qrc
|
|
|
|
# Should be easy: styles.qss + assets.
|
|
|
|
|
|
|
|
# Assets should be easy.
|
|
|
|
|
|
|
|
colors_map = {
|
|
|
|
'light': {},
|
|
|
|
'dark': {
|
2021-07-16 01:28:48 +00:00
|
|
|
# Might want to change the icon names as well to include the color changes.
|
|
|
|
# First we need to stabilize the names.
|
|
|
|
# Main theme colors.
|
|
|
|
# -----------------
|
|
|
|
# Note: these colors are inversed for light
|
|
|
|
# themes.
|
2021-07-14 06:14:04 +00:00
|
|
|
'foreground': '#eff0f1',
|
2021-07-16 01:28:48 +00:00
|
|
|
'foreground-light': '#ffffff',
|
2021-07-14 06:14:04 +00:00
|
|
|
'background': '#31363b',
|
2021-07-16 01:28:48 +00:00
|
|
|
'alternate-background': '#3b4045',
|
|
|
|
'background-light': '#454a4f',
|
|
|
|
'highlight': '#3daee9',
|
|
|
|
'highlight-light': '#58d3ff',
|
|
|
|
'highlight-dark': '#2a79a3',
|
|
|
|
'alternate-hover': '#369cd1',
|
|
|
|
'midtone': '#76797c',
|
|
|
|
'midtone-light': '#b0b0b0',
|
|
|
|
'midtone-dark': '#626568',
|
|
|
|
'midtone:hover': '#8a8d8f', #9ea0a3
|
|
|
|
'view:border': '#3A3939',
|
|
|
|
'view:checked': '#334e5e',
|
|
|
|
'view:hover': 'rgba(61, 173, 232, 0.1)',
|
|
|
|
'view:background': '#232629',
|
|
|
|
'tab:background': '#54575B',
|
2021-07-14 21:57:20 +00:00
|
|
|
'tree': '#afafaf',
|
2021-07-16 01:28:48 +00:00
|
|
|
'checkbox:disabled': '#c8c9ca',
|
|
|
|
'button:disabled': '#454545',
|
|
|
|
'close:hover': '#b37979',
|
|
|
|
'close:pressed': '#b33e3e',
|
|
|
|
'dock:float': '#a2a2a2',
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2021-07-16 01:28:48 +00:00
|
|
|
icons = {
|
2021-07-14 06:14:04 +00:00
|
|
|
# Arrows
|
|
|
|
'down_arrow': {
|
|
|
|
'default': ['foreground'],
|
2021-07-16 01:28:48 +00:00
|
|
|
'hover': ['highlight'],
|
|
|
|
'disabled': ['midtone-light'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'left_arrow': {
|
|
|
|
'default': ['foreground'],
|
2021-07-16 01:28:48 +00:00
|
|
|
'disabled': ['midtone-light'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'right_arrow': {
|
|
|
|
'default': ['foreground'],
|
2021-07-16 01:28:48 +00:00
|
|
|
'disabled': ['midtone-light'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'up_arrow': {
|
|
|
|
'default': ['foreground'],
|
2021-07-16 01:28:48 +00:00
|
|
|
'hover': ['highlight'],
|
|
|
|
'disabled': ['midtone-light'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
# Abstract buttons.
|
|
|
|
'checkbox_checked': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['highlight-light'],
|
|
|
|
'disabled': ['checkbox:disabled'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'checkbox_indeterminate': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['highlight-light'],
|
|
|
|
'disabled': ['checkbox:disabled'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'checkbox_unchecked': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['highlight-light'],
|
|
|
|
'disabled': ['checkbox:disabled'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'radio_checked': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['highlight-light'],
|
|
|
|
'disabled': ['checkbox:disabled'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'radio_unchecked': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['highlight-light'],
|
|
|
|
'disabled': ['checkbox:disabled'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
# Dock/Tab widgets
|
|
|
|
'close': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['midtone-dark'],
|
|
|
|
'hover': ['close:hover'],
|
|
|
|
'pressed': ['close:pressed'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'undock': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['dock:float'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
|
|
|
'undock_hover': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['dock:float', 'foreground'],
|
2021-07-14 06:14:04 +00:00
|
|
|
},
|
2021-07-14 21:57:20 +00:00
|
|
|
# Tree views.
|
|
|
|
'branch_open': {
|
|
|
|
'default': ['tree'],
|
2021-07-16 01:28:48 +00:00
|
|
|
'hover': ['highlight'],
|
2021-07-14 21:57:20 +00:00
|
|
|
},
|
|
|
|
'branch_closed': {
|
|
|
|
'default': ['tree'],
|
2021-07-16 01:28:48 +00:00
|
|
|
'hover': ['highlight'],
|
2021-07-14 21:57:20 +00:00
|
|
|
},
|
2021-07-15 01:22:33 +00:00
|
|
|
'branch_end': {
|
|
|
|
'default': ['tree'],
|
|
|
|
},
|
2021-07-14 21:57:20 +00:00
|
|
|
'branch_end_arrow': {
|
|
|
|
'default': ['tree'],
|
|
|
|
},
|
|
|
|
'branch_more': {
|
|
|
|
'default': ['tree'],
|
|
|
|
},
|
|
|
|
'branch_more_arrow': {
|
|
|
|
'default': ['tree'],
|
|
|
|
},
|
|
|
|
'vline': {
|
|
|
|
'default': ['tree'],
|
|
|
|
},
|
2021-07-15 21:44:59 +00:00
|
|
|
'calendar_next': {
|
|
|
|
'default': ['foreground'],
|
2021-07-16 01:28:48 +00:00
|
|
|
'hover': ['highlight'],
|
2021-07-15 21:44:59 +00:00
|
|
|
},
|
|
|
|
'calendar_previous': {
|
|
|
|
'default': ['foreground'],
|
2021-07-16 01:28:48 +00:00
|
|
|
'hover': ['highlight'],
|
2021-07-15 21:44:59 +00:00
|
|
|
},
|
2021-07-15 23:27:07 +00:00
|
|
|
'transparent': {
|
|
|
|
'default': [],
|
|
|
|
},
|
|
|
|
'hmovetoolbar': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['midtone-light'],
|
2021-07-15 23:27:07 +00:00
|
|
|
},
|
|
|
|
'vmovetoolbar': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['midtone-light'],
|
2021-07-15 23:27:07 +00:00
|
|
|
},
|
|
|
|
'hseptoolbar': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['midtone-light'],
|
2021-07-15 23:27:07 +00:00
|
|
|
},
|
|
|
|
'vseptoolbar': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['midtone-light'],
|
2021-07-15 23:27:07 +00:00
|
|
|
},
|
|
|
|
'sizegrip': {
|
2021-07-16 01:28:48 +00:00
|
|
|
'default': ['midtone-light'],
|
2021-07-15 23:27:07 +00:00
|
|
|
}
|
2021-07-14 06:14:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def replace(contents, colors, color_map):
|
|
|
|
'''Replace all template values.'''
|
|
|
|
|
|
|
|
for index, color in enumerate(colors):
|
|
|
|
sub = f'^{index}^'
|
|
|
|
contents = contents.replace(sub, color_map[color])
|
|
|
|
return contents
|
|
|
|
|
2021-07-16 01:28:48 +00:00
|
|
|
def configure_icons(style):
|
|
|
|
'''Configure icons for a given style.'''
|
2021-07-14 06:14:04 +00:00
|
|
|
|
|
|
|
color_map = colors_map[style]
|
2021-07-16 01:28:48 +00:00
|
|
|
for icon, extensions in icons.items():
|
|
|
|
template = f'{home}/template/{icon}.svg.in'
|
2021-07-14 06:14:04 +00:00
|
|
|
template_contents = open(template).read()
|
|
|
|
for extension, colors in extensions.items():
|
|
|
|
contents = replace(template_contents, colors, color_map)
|
|
|
|
if extension == 'default':
|
2021-07-16 01:28:48 +00:00
|
|
|
filename = f'{home}/{style}/{icon}.svg'
|
2021-07-14 06:14:04 +00:00
|
|
|
else:
|
2021-07-16 01:28:48 +00:00
|
|
|
filename = f'{home}/{style}/{icon}_{extension}.svg'
|
2021-07-14 06:14:04 +00:00
|
|
|
with open(filename, 'w') as file:
|
|
|
|
file.write(contents)
|
|
|
|
|
2021-07-16 01:28:48 +00:00
|
|
|
def configure_stylesheet(style):
|
|
|
|
'''Configure the stylesheet for a given style.'''
|
|
|
|
|
|
|
|
color_map = colors_map[style]
|
|
|
|
contents = open(f'{home}/template/stylesheet.qss.in').read()
|
|
|
|
for key, color in color_map.items():
|
|
|
|
contents = contents.replace(f'^{key}^', color)
|
|
|
|
contents = contents.replace('^style^', style)
|
|
|
|
with open(f'{home}/{style}/stylesheet.qss', 'w') as file:
|
|
|
|
file.write(contents)
|
|
|
|
|
|
|
|
def configure_style(style):
|
|
|
|
'''Configure the icons and stylesheet for a given style.'''
|
|
|
|
|
|
|
|
os.makedirs(f'{home}/{style}', exist_ok=True)
|
|
|
|
configure_icons(style)
|
|
|
|
configure_stylesheet(style)
|
|
|
|
|
|
|
|
def configure(styles, resource):
|
|
|
|
'''Configure all styles and write the files to a QRC file.'''
|
|
|
|
|
|
|
|
for style in styles:
|
|
|
|
configure_style(style)
|
|
|
|
|
2021-07-14 06:14:04 +00:00
|
|
|
if __name__ == '__main__':
|
2021-07-16 01:28:48 +00:00
|
|
|
# TODO(ahuszagh) Replace with argparse values.
|
|
|
|
# Also need to parse from JSON.
|
|
|
|
configure(['dark'], None)
|
2021-07-14 06:14:04 +00:00
|
|
|
#configure('light')
|