From eeed00407b88a790d5613d896e8a9a2ede55c9e1 Mon Sep 17 00:00:00 2001 From: imarkoff Date: Wed, 8 Feb 2023 09:15:33 +0200 Subject: [PATCH] Change structured data in JSON --- colors.json | 599 +++++++++++++++++++++++++++++----------------------- install.py | 57 +++-- 2 files changed, 373 insertions(+), 283 deletions(-) diff --git a/colors.json b/colors.json index 27f6b18..f95390e 100644 --- a/colors.json +++ b/colors.json @@ -1,335 +1,416 @@ { - "dark" : { - "accent": { + "elements" : { + "accent-color": { "replace" : "ACCENT-COLOR", - "s" : 42, - "l" : 26, - "a" : 1 + + "light" : { + "s" : 75, + "l" : 75, + "a" : 1 + }, + + "dark" : { + "s" : 42, + "l" : 26, + "a" : 1 + } + }, "accent_hover" : { "replace" : "ACCENT_HOVER", - "s" : 66, - "l" : 22, - "a" : 1 + + "light" : { + "s" : 70, + "l" : 70, + "a" : 1 + }, + + "dark" : { + "s" : 66, + "l" : 22, + "a" : 1 + } }, "accent-disabled" : { - "replace" : "ACCENT-DISABLED", - "s" : 6, - "l" : 15, - "a" : 1 + "replace" : "ACCENT-DISABLED-COLOR", + + "light" : { + "s" : 35, + "l" : 90, + "a" : 1 + }, + + "dark" : { + "s" : 95, + "l" : 85, + "a" : 0.08 + } }, - "accent-disabled_hover" : { - "replace" : "ACCENT-DIS_HOVER", - "s" : 7, - "l" : 20, - "a" : 1 - }, + "replace" : "ACCENT-DISABLED_HOVER", - "background-color" : { - "replace" : "BACKGROUND-COLOR", - "s" : 7, - "l" : 8, - "a" : 1 - }, - - "dash-color" : { - "replace" : "DASH-COLOR", - "s" : 7, - "l" : 8, - "a" : 0.8 - }, - - "accent-opacity-color" : { - "replace": "ACCENT-OPACITY-COLOR", - "s" : 42, - "l" : 26, - "a" : 0.2 - }, + "light" : { + "s" : 35, + "l" : 85, + "a" : 1 + }, - "quick-toggle-menu-background" : { - "replace" : "QUICK-TOGGLE-MENU-BACKGROUND", - "s" : 6, - "l" : 10, - "a" : 1 + "dark" : { + "s" : 40, + "l" : 85, + "a" : 0.13 + } }, "accent-secondary-color" : { "replace" : "ACCENT-SECONDARY-COLOR", - "s" : 20, - "l" : 75, - "a" : 1 - }, + + "light" : { + "s" : 20, + "l" : 50, + "a" : 1 + }, + "dark" : { + "s" : 20, + "l" : 75, + "a" : 1 + } + }, "accent-secondary_hover" : { "replace" : "ACCENT-SECONDARY_HOVER", - "s" : 20, - "l" : 70, - "a" : 1 + + "light" : { + "s" : 20, + "l" : 45, + "a" : 1 + }, + + "dark" : { + "s" : 20, + "l" : 70, + "a" : 1 + } }, + "accent-opacity-color" : { + "replace": "ACCENT-OPACITY-COLOR", + + "light" : { + "s" : 78, + "l" : 84, + "a" : 0.5 + }, + + "dark" : { + "s" : 42, + "l" : 26, + "a" : 0.2 + } + }, + + "background-color" : { + "replace" : "BACKGROUND-COLOR", + + "light" : { + "s" : 40, + "l" : 98, + "a" : 1 + }, + + "dark" : { + "s" : 7, + "l" : 8, + "a" : 1 + } + }, + + "dash-color" : { + "replace" : "DASH-COLOR", + + "light" : { + "s" : 40, + "l" : 98, + "a" : 0.8 + }, + + "dark" : { + "s" : 0, + "l" : 7, + "a" : 0.7 + } + }, + "dash_overview" : { + "replace" : "DASH_OVERVIEW", + + "light" : { + "s" : 60, + "l" : 90, + "a" : 0.4 + }, + + "dark" : { + "s" : 0, + "l" : 100, + "a" : 0.12 + } + }, + "well-app-selected" : { "replace" : "WELL-APP-SELECTED", - "s" : 20, - "l" : 75, - "a" : 0.4 + + "light" : { + "s" : 20, + "l" : 50, + "a" : 0.4 + }, + + "dark" : { + "s" : 20, + "l" : 75, + "a" : 0.4 + } }, "text-primary-color" : { "replace" : "TEXT-PRIMARY-COLOR", - "s" : 65, - "l" : 95, - "a" : 1 + + "light" : { + "s" : 71, + "l" : 10, + "a" : 0.87 + }, + + "dark" : { + "s" : 65, + "l" : 95, + "a" : 1 + } }, "text-secondary-color" : { "replace" : "TEXT-SECONDARY-COLOR", - "s" : 65, - "l" : 95, - "a" : 0.67 + + "light" : { + "s" : 71, + "l" : 10, + "a" : 0.6 + }, + + "dark" : { + "s" : 65, + "l" : 95, + "a" : 0.67 + } }, "text-disabled-color" : { "replace" : "TEXT-DISABLED-COLOR", - "s" : 65, - "l" : 95, - "a" : 0.38 + + "light" : { + "s" : 71, + "l" : 10, + "a" : 0.38 + }, + + "dark" : { + "s" : 65, + "l" : 95, + "a" : 0.38 + } }, "text-inverted-color": { "replace" : "TEXT-INVERTED-COLOR", - "s" : 71, - "l" : 10, - "a" : 0.87 + + "light" : { + "s" : 65, + "l" : 95, + "a" : 1 + }, + + "dark" : { + "s" : 71, + "l" : 10, + "a" : 0.87 + } }, "border-shadow" : { "replace" : "BORDER-SHADOW", - "s" : 0, - "l" : 255, - "a" : 0.03 - }, - "bordermenu-shadow" : { - "replace" : "BORDER-MENU-SHADOW", - "s" : 0, - "l" : 255, - "a" : 0.07 - }, + "light" : { + "s" : 0, + "l" : 0, + "a" : 0.03 + }, - "separator-color" : { - "replace" : "SEPARATOR-COLOR", - "s" : 0, - "l" : 255, - "a" : 0.1 - }, - - "show-apps-icon-color" : { - "replace" : "SHOW-APPS-ICON-COLOR", - "s" : 65, - "l" : 95, - "a" : 1 - }, - - "scrollbar-color" : { - "replace" : "SCROLLBAR-COLOR", - "s" : 10, - "l" : 35, - "a" : 0.75 - }, - - "scrollbar_hover" : { - "replace" : "SCROLLBAR_HOVER", - "s" : 12, - "l" : 35, - "a" : 1 - }, - - "scrollbar_active" : { - "replace" : "SCROLLBAR_ACTIVE", - "s" : 12, - "l" : 35, - "a" : 0.87 - }, - - "page-nav-hint" : { - "replace" : "PAGE-NAV-HINT", - "s" : 15, - "l" : 90, - "a" : 0.05 - }, - - "section-color" : { - "replace" : "SECTION-COLOR", - "s" : 6, - "l" : 12, - "a" : 1 - } - }, - - "light" : { - "accent-color" : { - "replace" : "ACCENT-COLOR", - "s" : 75, - "l" : 75, - "a" : 1 - }, - - "accent_hover" : { - "replace" : "ACCENT_HOVER", - "s" : 70, - "l" : 70, - "a" : 1 - }, - - "accent-disabled" : { - "replace" : "ACCENT-DISABLED", - "s" : 35, - "l" : 90, - "a" : 1 - }, - - "accent-disabled_hover" : { - "replace" : "ACCENT-DIS_HOVER", - "s" : 35, - "l" : 85, - "a" : 1 - }, - - "background-color" : { - "replace" : "BACKGROUND-COLOR", - "s" : 40, - "l" : 98, - "a" : 1 - }, - - "dash-color" : { - "replace" : "DASH-COLOR", - "s" : 40, - "l" : 98, - "a" : 0.8 - }, - - "accent-opacity-color" : { - "replace": "ACCENT-OPACITY-COLOR", - "s" : 78, - "l" : 84, - "a" : 0.5 - }, - - "accent-secondary-color" : { - "replace" : "ACCENT-SECONDARY-COLOR", - "s" : 20, - "l" : 50, - "a" : 1 - }, - - "accent-secondary_hover" : { - "replace" : "ACCENT-SECONDARY_HOVER", - "s" : 20, - "l" : 45, - "a" : 1 - }, - - "well-app-selected" : { - "replace" : "WELL-APP-SELECTED", - "s" : 20, - "l" : 50, - "a" : 0.4 - }, - - "text-primary-color": { - "replace" : "TEXT-PRIMARY-COLOR", - "s" : 71, - "l" : 10, - "a" : 0.87 - }, - - "text-secondary-color" : { - "replace" : "TEXT-SECONDARY-COLOR", - "s" : 71, - "l" : 10, - "a" : 0.6 - }, - - "text-disabled-color" : { - "replace" : "TEXT-DISABLED-COLOR", - "s" : 71, - "l" : 10, - "a" : 0.38 - }, - - "text-inverted-color" : { - "replace" : "TEXT-INVERTED-COLOR", - "s" : 65, - "l" : 95, - "a" : 1 - }, - - "border-shadow" : { - "replace" : "BORDER-SHADOW", - "s" : 0, - "l" : 0, - "a" : 0.03 + "dark" : { + "s" : 0, + "l" : 255, + "a" : 0.03 + } }, "border-menu-shadow" : { "replace" : "BORDER-MENU-SHADOW", - "s" : 0, - "l" : 0, - "a" : 0.07 + + "light" : { + "s" : 0, + "l" : 0, + "a" : 0.07 + }, + + "dark" : { + "s" : 0, + "l" : 255, + "a" : 0.07 + } }, "separator-color" : { "replace" : "SEPARATOR-COLOR", - "s" : 0, - "l" : 0, - "a" : 0.1 + + "light" : { + "s" : 0, + "l" : 0, + "a" : 0.1 + }, + + "dark" : { + "s" : 0, + "l" : 255, + "a" : 0.1 + } }, "show-apps-icon-color" : { "replace" : "SHOW-APPS-ICON-COLOR", - "s" : 4, - "l" : 30, - "a" : 1 + + "light" : { + "s" : 4, + "l" : 30, + "a" : 1 + }, + + "dark" : { + "s" : 65, + "l" : 95, + "a" : 1 + } }, "scrollbar-color" : { "replace" : "SCROLLBAR-COLOR", - "s" : 20, - "l" : 70, - "a" : 0.75 - }, + "light" : { + "s" : 20, + "l" : 70, + "a" : 0.75 + }, + + "dark" : { + "s" : 10, + "l" : 25, + "a" : 0.75 + } + }, "scrollbar_hover" : { "replace" : "SCROLLBAR_HOVER", - "s" : 20, - "l" : 70, - "a" : 1 - }, + "light" : { + "s" : 20, + "l" : 70, + "a" : 1 + }, + + "dark" : { + "s" : 12, + "l" : 25, + "a" : 1 + } + }, "scrollbar_active" : { "replace" : "SCROLLBAR_ACTIVE", - "s" : 20, - "l" : 70, - "a" : 0.87 - }, + "light" : { + "s" : 20, + "l" : 70, + "a" : 0.87 + }, + + "dark" : { + "s" : 12, + "l" : 35, + "a" : 0.87 + } + }, + "page-nav-hint" : { "replace" : "PAGE-NAV-HINT", - "s" : 95, - "l" : 20, - "a" : 0.05 - }, + "light" : { + "s" : 95, + "l" : 20, + "a" : 0.05 + }, + + "dark" : { + "s" : 15, + "l" : 90, + "a" : 0.05 + } + }, + "section-color" : { "replace" : "SECTION-COLOR", - "s" : 45, - "l" : 92, - "a" : 1 + + "light" : { + "s" : 45, + "l" : 92, + "a" : 1 + }, + + "dark" : { + "s" : 6, + "l" : 12, + "a" : 1 + } + }, + + "close-button-color" : { + "replace" : "CLOSE-BUTTON-COLOR", + + "light" : { + "s" : 35, + "l" : 90, + "a" : 1 + }, + + "dark" : { + "s" : 6, + "l" : 15, + "a" : 1 + } + }, + "close-button_hover" : { + "replace" : "CLOSE-BUTTON_HOVER", + + "light" : { + "s" : 35, + "l" : 85, + "a" : 1 + }, + + "dark" : { + "s" : 7, + "l" : 20, + "a" : 1 + } } + }, "colors" : { @@ -351,7 +432,5 @@ "pink" : { "h" : 295 } - }, - - "apply-theme-files" : ["gnome-shell.css", "checkbox.svg", "checkbox-focused.svg", "checkbox-off.svg", "checkbox-off-focused.svg", "workspace-placeholder.svg", "toggle-off.svg", "toggle-on.svg", "calendar-today.svg"] + } } \ No newline at end of file diff --git a/install.py b/install.py index 097e9eb..0c49c95 100644 --- a/install.py +++ b/install.py @@ -69,6 +69,7 @@ def copy_files(source, destination): destinationDirs = destination.split("/") loopCreateDirs = f"{destinationDirs[0]}/" + # create every folder for i in range(1, len(destinationDirs)): loopCreateDirs += f"{destinationDirs[i]}/" os.system(f"mkdir -p {loopCreateDirs}") @@ -89,24 +90,25 @@ def apply_theme_to_file(hue, destination, theme_mode, apply_file, sat=None): with open(os.path.expanduser(f"{destination}/{apply_file}"), "r") as file: edit_file = file.read() + # colorsys works in range(0, 1) h = hue / 360 - for i in colors[f"{theme_mode}"]: - lightness = int(colors[f"{theme_mode}"][i]["l"]) / 100 - saturation = int(colors[f"{theme_mode}"][i]["s"]) / 100 if sat is None else sat + for element in colors["elements"]: + + # convert to range(0, 1) + lightness = int(colors["elements"][element][theme_mode]["l"]) / 100 + saturation = int(colors["elements"][element][theme_mode]["s"]) / 100 if sat is None else sat + alpha = colors["elements"][element][theme_mode]["a"] - hls_to_rgb = colorsys.hls_to_rgb(h, lightness, saturation) + # convert hsl to rgb and multiple every item + red, green, blue = [int(item * 256) for item in colorsys.hls_to_rgb(h, lightness, saturation)] - edit_file = edit_file.replace(colors[f"{theme_mode}"][i]["replace"], - f"rgba({int(hls_to_rgb[0] * 256)}," - f"{int(hls_to_rgb[1] * 256)}," - f"{int(hls_to_rgb[2] * 256)}," - f"{colors[f'{theme_mode}'][i]['a']})") + replace_keyword = colors["elements"][element]["replace"] + + edit_file = edit_file.replace(replace_keyword, f"rgba({red}, {green}, {blue}, {alpha})") with open(os.path.expanduser(f"{destination}/{apply_file}"), "w") as file: file.write(edit_file) - colorsOpen.close() - def apply_theme(hue, destination, theme_mode, sat=None): """ @@ -117,8 +119,8 @@ def apply_theme(hue, destination, theme_mode, sat=None): :param sat: color saturation (optional) """ - for applyFile in colors["apply-theme-files"]: - apply_theme_to_file(hue, destination, theme_mode, applyFile, sat=sat) + for apply_file in os.listdir("./gnome-shell/"): + apply_theme_to_file(hue, destination, theme_mode, apply_file, sat=sat) def install_color(hue, path_name, theme_mode, sat=None): @@ -131,20 +133,28 @@ def install_color(hue, path_name, theme_mode, sat=None): """ print(f"Creating {path_name} {theme_mode} theme...", end=" ") + + try: + copy_files("./gnome-shell", destination_return(path_name, theme_mode)) + apply_theme(hue, destination_return(path_name, theme_mode), theme_mode, sat=sat) + + except Exception as err: + print("\nError: " + str(err)) - copy_files("./gnome-shell", destination_return(path_name, theme_mode)) - apply_theme(hue, destination_return(path_name, theme_mode), theme_mode, sat=sat) - - print("Done.") - + else: + print("Done.") def install_all(theme_mode): """ Install all accent colors listed in "colors", colors.json :param theme_mode: theme name (light or dark) """ + + # install hue colors listed in colors.json for color in colors["colors"]: install_color(colors["colors"][color]["h"], color, theme_mode) + + # install gray color separately install_color(0, "gray", theme_mode, sat=0) @@ -152,7 +162,6 @@ def main(): user_input = input("\n>>> ").lower().split() userInputLength = len(user_input) - # this part is a piece of sh.... # i'll rewrite it later match user_input[0]: case "-a" | "--all": @@ -204,9 +213,11 @@ def main(): install_color(int(user_input[1]), user_input[2], user_input[3]) -print_help() -colorsOpen = open("colors.json") -colors = json.loads(colorsOpen.read()) # used as database for replacing colors, files which must be generated +if __name__ == "__main__": -main() + print_help() + + colors = json.load(open("colors.json")) # used as database for replacing colors, files which must be generated + + main() \ No newline at end of file