mirror of
https://github.com/ColinDuquesnoy/QDarkStyleSheet.git
synced 2026-08-29 08:34:30 +08:00
Update part of create_custom_qss function
This commit is contained in:
+59
-24
@@ -125,56 +125,86 @@ def _is_identifier(name):
|
||||
return check
|
||||
|
||||
|
||||
if palette is None:
|
||||
print("Please pass a palette class in order to create its "
|
||||
"qrc file")
|
||||
sys.exit(1)
|
||||
def create_qss(palette, base_path=''):
|
||||
"""Create variables files and run qtsass compilation.
|
||||
|
||||
This function will use the structure that must contain::
|
||||
|
||||
base_path
|
||||
[palette.ID]
|
||||
main.scss
|
||||
qss
|
||||
_style.scss
|
||||
|
||||
The structure after the execution will contain::
|
||||
|
||||
base_path
|
||||
[palette.ID]
|
||||
_variables.scss
|
||||
[palette.ID]style.qss
|
||||
main.scss
|
||||
qss
|
||||
_style.scss
|
||||
|
||||
Args:
|
||||
palette (Palette): Palette class.
|
||||
base_path (str): Base path for the palette directory, required for
|
||||
custom palettes. Defaults to '' that uses `[PACKAGE_PATH]`.
|
||||
|
||||
Returns:
|
||||
str: Stylesheet in string format.
|
||||
"""
|
||||
|
||||
if palette.ID is None:
|
||||
print("A QDarkStyle palette requires an ID!")
|
||||
sys.exit(1)
|
||||
|
||||
palette_path = os.path.join(PACKAGE_PATH, palette.ID)
|
||||
|
||||
if base_path:
|
||||
palette_path = os.path.join(base_path, palette.ID)
|
||||
|
||||
_logger.info(f"Creating QSS for palette: '{palette.ID} ...")
|
||||
_logger.info(f"Palette path: {palette_path}")
|
||||
|
||||
variables_scss_filepath = os.path.join(palette_path, VARIABLES_SCSS_FILE)
|
||||
main_scss_filepath = os.path.join(palette_path, MAIN_SCSS_FILE)
|
||||
qss_filepath = os.path.join(palette_path, palette.ID + QSS_FILE)
|
||||
qss_filepath = os.path.join(palette_path, palette.ID + QSS_FILE_SUFFIX)
|
||||
|
||||
_create_scss_variables(variables_scss_filepath, palette)
|
||||
|
||||
stylesheet = _create_qss(main_scss_filepath, qss_filepath)
|
||||
|
||||
return stylesheet
|
||||
|
||||
|
||||
def create_custom_qss(
|
||||
name,
|
||||
id,
|
||||
path,
|
||||
color_background_light,
|
||||
color_background_normal,
|
||||
color_background_dark,
|
||||
color_foreground_light,
|
||||
color_foreground_normal,
|
||||
color_foreground_dark,
|
||||
color_selection_light,
|
||||
color_selection_normal,
|
||||
color_selection_dark,
|
||||
border_radius,
|
||||
color_backgroung=[], # 6 elements
|
||||
color_text=[], # 4 elements
|
||||
color_accent=[], # 4 elemetns
|
||||
border=[], # 3 elements
|
||||
border_selection=[], # 3 elements
|
||||
opacity_tooltip=None,
|
||||
size_border_radius=None,
|
||||
w_status_bar_background_color=None,
|
||||
path_resources=None
|
||||
):
|
||||
"""
|
||||
Create a custom palette based on the parameters defined.
|
||||
|
||||
The `name` must be a valid Python identifier and will be stored
|
||||
The `id` must be a valid Python identifier and will be stored
|
||||
as a lowercased folder (even if the identifier had uppercase letters).
|
||||
|
||||
This function returns the custom stylesheet pointing to resources stored at
|
||||
.../path/name/.
|
||||
This function returns the custom stylesheet pointing to resources stored
|
||||
at path_resources/[id].
|
||||
"""
|
||||
# TODO: update this function for the new Palette class
|
||||
raise NotImplementedError("Update this function for the new Palette class")
|
||||
|
||||
stylesheet = ''
|
||||
|
||||
# Check if name is valid
|
||||
if is_identifier(name):
|
||||
# Check if name/id is valid
|
||||
if _is_identifier(id):
|
||||
name = name if name[0].isupper() else name.capitalize()
|
||||
else:
|
||||
raise Exception('The custom palette name must be a valid Python '
|
||||
@@ -200,6 +230,10 @@ def create_custom_qss(
|
||||
shutil.copytree(QSS_PATH, theme_qss_path)
|
||||
|
||||
# Create custom palette
|
||||
# ATTENTION: here we need to iterate over
|
||||
# args of this function to fill the values
|
||||
# of the Palette class member with correct values
|
||||
# they still using the old values below
|
||||
custom_palette = type(name, (Palette, ), {})
|
||||
custom_palette.COLOR_BACKGROUND_LIGHT = color_background_light
|
||||
custom_palette.COLOR_BACKGROUND_NORMAL = color_background_normal
|
||||
@@ -220,7 +254,8 @@ def create_custom_qss(
|
||||
# Compile SCSS
|
||||
variables_scss_filepath = os.path.join(theme_qss_path, VARIABLES_SCSS_FILE)
|
||||
theme_main_scss_filepath = os.path.join(theme_qss_path, MAIN_SCSS_FILE)
|
||||
theme_qss_filepath = os.path.join(theme_root_path, palette.ID + QSS_FILE)
|
||||
theme_qss_filepath = os.path.join(theme_root_path, palette.ID + QSS_FILE_SUFFIX)
|
||||
|
||||
stylesheet = create_qss(
|
||||
qss_filepath=theme_qss_filepath,
|
||||
main_scss_filepath=theme_main_scss_filepath,
|
||||
|
||||
Reference in New Issue
Block a user