Change structured data in JSON

This commit is contained in:
imarkoff
2023-02-08 09:15:33 +02:00
parent f519fa24bf
commit eeed00407b
2 changed files with 373 additions and 283 deletions

View File

@@ -1,335 +1,416 @@
{
"dark" : {
"accent": {
"elements" : {
"accent-color": {
"replace" : "ACCENT-COLOR",
"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
},
"accent-disabled" : {
"replace" : "ACCENT-DISABLED",
"s" : 6,
"l" : 15,
"a" : 1
},
"accent-disabled_hover" : {
"replace" : "ACCENT-DIS_HOVER",
"s" : 7,
"l" : 20,
"a" : 1
},
"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
},
"quick-toggle-menu-background" : {
"replace" : "QUICK-TOGGLE-MENU-BACKGROUND",
"s" : 6,
"l" : 10,
"a" : 1
},
"accent-secondary-color" : {
"replace" : "ACCENT-SECONDARY-COLOR",
"s" : 20,
"l" : 75,
"a" : 1
},
"accent-secondary_hover" : {
"replace" : "ACCENT-SECONDARY_HOVER",
"s" : 20,
"light" : {
"s" : 70,
"l" : 70,
"a" : 1
},
"dark" : {
"s" : 66,
"l" : 22,
"a" : 1
}
},
"accent-disabled" : {
"replace" : "ACCENT-DISABLED-COLOR",
"light" : {
"s" : 35,
"l" : 90,
"a" : 1
},
"dark" : {
"s" : 95,
"l" : 85,
"a" : 0.08
}
},
"accent-disabled_hover" : {
"replace" : "ACCENT-DISABLED_HOVER",
"light" : {
"s" : 35,
"l" : 85,
"a" : 1
},
"dark" : {
"s" : 40,
"l" : 85,
"a" : 0.13
}
},
"accent-secondary-color" : {
"replace" : "ACCENT-SECONDARY-COLOR",
"light" : {
"s" : 20,
"l" : 50,
"a" : 1
},
"dark" : {
"s" : 20,
"l" : 75,
"a" : 1
}
},
"accent-secondary_hover" : {
"replace" : "ACCENT-SECONDARY_HOVER",
"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",
"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
},
"text-secondary-color" : {
"replace" : "TEXT-SECONDARY-COLOR",
"s" : 65,
"l" : 95,
"a" : 0.67
},
"text-disabled-color" : {
"replace" : "TEXT-DISABLED-COLOR",
"s" : 65,
"l" : 95,
"a" : 0.38
},
"text-inverted-color": {
"replace" : "TEXT-INVERTED-COLOR",
"light" : {
"s" : 71,
"l" : 10,
"a" : 0.87
},
"border-shadow" : {
"replace" : "BORDER-SHADOW",
"s" : 0,
"l" : 255,
"a" : 0.03
"dark" : {
"s" : 65,
"l" : 95,
"a" : 1
}
},
"bordermenu-shadow" : {
"replace" : "BORDER-MENU-SHADOW",
"s" : 0,
"l" : 255,
"a" : 0.07
"text-secondary-color" : {
"replace" : "TEXT-SECONDARY-COLOR",
"light" : {
"s" : 71,
"l" : 10,
"a" : 0.6
},
"separator-color" : {
"replace" : "SEPARATOR-COLOR",
"s" : 0,
"l" : 255,
"a" : 0.1
"dark" : {
"s" : 65,
"l" : 95,
"a" : 0.67
}
},
"show-apps-icon-color" : {
"replace" : "SHOW-APPS-ICON-COLOR",
"text-disabled-color" : {
"replace" : "TEXT-DISABLED-COLOR",
"light" : {
"s" : 71,
"l" : 10,
"a" : 0.38
},
"dark" : {
"s" : 65,
"l" : 95,
"a" : 0.38
}
},
"text-inverted-color": {
"replace" : "TEXT-INVERTED-COLOR",
"light" : {
"s" : 65,
"l" : 95,
"a" : 1
},
"scrollbar-color" : {
"replace" : "SCROLLBAR-COLOR",
"s" : 10,
"l" : 35,
"a" : 0.75
"dark" : {
"s" : 71,
"l" : 10,
"a" : 0.87
}
},
"scrollbar_hover" : {
"replace" : "SCROLLBAR_HOVER",
"s" : 12,
"l" : 35,
"border-shadow" : {
"replace" : "BORDER-SHADOW",
"light" : {
"s" : 0,
"l" : 0,
"a" : 0.03
},
"dark" : {
"s" : 0,
"l" : 255,
"a" : 0.03
}
},
"border-menu-shadow" : {
"replace" : "BORDER-MENU-SHADOW",
"light" : {
"s" : 0,
"l" : 0,
"a" : 0.07
},
"dark" : {
"s" : 0,
"l" : 255,
"a" : 0.07
}
},
"separator-color" : {
"replace" : "SEPARATOR-COLOR",
"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",
"light" : {
"s" : 4,
"l" : 30,
"a" : 1
},
"dark" : {
"s" : 65,
"l" : 95,
"a" : 1
}
},
"scrollbar-color" : {
"replace" : "SCROLLBAR-COLOR",
"light" : {
"s" : 20,
"l" : 70,
"a" : 0.75
},
"dark" : {
"s" : 10,
"l" : 25,
"a" : 0.75
}
},
"scrollbar_hover" : {
"replace" : "SCROLLBAR_HOVER",
"light" : {
"s" : 20,
"l" : 70,
"a" : 1
},
"dark" : {
"s" : 12,
"l" : 25,
"a" : 1
}
},
"scrollbar_active" : {
"replace" : "SCROLLBAR_ACTIVE",
"light" : {
"s" : 20,
"l" : 70,
"a" : 0.87
},
"dark" : {
"s" : 12,
"l" : 35,
"a" : 0.87
}
},
"page-nav-hint" : {
"replace" : "PAGE-NAV-HINT",
"light" : {
"s" : 95,
"l" : 20,
"a" : 0.05
},
"dark" : {
"s" : 15,
"l" : 90,
"a" : 0.05
}
},
"section-color" : {
"replace" : "SECTION-COLOR",
"light" : {
"s" : 45,
"l" : 92,
"a" : 1
},
"dark" : {
"s" : 6,
"l" : 12,
"a" : 1
}
},
"close-button-color" : {
"replace" : "CLOSE-BUTTON-COLOR",
"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",
"dark" : {
"s" : 6,
"l" : 15,
"a" : 1
}
},
"close-button_hover" : {
"replace" : "CLOSE-BUTTON_HOVER",
"light" : {
"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
},
"border-menu-shadow" : {
"replace" : "BORDER-MENU-SHADOW",
"s" : 0,
"l" : 0,
"a" : 0.07
},
"separator-color" : {
"replace" : "SEPARATOR-COLOR",
"s" : 0,
"l" : 0,
"a" : 0.1
},
"show-apps-icon-color" : {
"replace" : "SHOW-APPS-ICON-COLOR",
"s" : 4,
"l" : 30,
"a" : 1
},
"scrollbar-color" : {
"replace" : "SCROLLBAR-COLOR",
"s" : 20,
"l" : 70,
"a" : 0.75
},
"scrollbar_hover" : {
"replace" : "SCROLLBAR_HOVER",
"s" : 20,
"l" : 70,
"a" : 1
},
"scrollbar_active" : {
"replace" : "SCROLLBAR_ACTIVE",
"s" : 20,
"l" : 70,
"a" : 0.87
},
"page-nav-hint" : {
"replace" : "PAGE-NAV-HINT",
"s" : 95,
"dark" : {
"s" : 7,
"l" : 20,
"a" : 0.05
},
"section-color" : {
"replace" : "SECTION-COLOR",
"s" : 45,
"l" : 92,
"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"]
}
}

View File

@@ -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"]:
hls_to_rgb = colorsys.hls_to_rgb(h, lightness, saturation)
# 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"]
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']})")
# convert hsl to rgb and multiple every item
red, green, blue = [int(item * 256) for item in colorsys.hls_to_rgb(h, lightness, saturation)]
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):
@@ -132,19 +134,27 @@ 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)
print("Done.")
except Exception as err:
print("\nError: " + str(err))
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])
if __name__ == "__main__":
print_help()
colorsOpen = open("colors.json")
colors = json.loads(colorsOpen.read()) # used as database for replacing colors, files which must be generated
colors = json.load(open("colors.json")) # used as database for replacing colors, files which must be generated
main()