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" : { "elements" : {
"accent": { "accent-color": {
"replace" : "ACCENT-COLOR", "replace" : "ACCENT-COLOR",
"s" : 42,
"l" : 26, "light" : {
"a" : 1 "s" : 75,
"l" : 75,
"a" : 1
},
"dark" : {
"s" : 42,
"l" : 26,
"a" : 1
}
}, },
"accent_hover" : { "accent_hover" : {
"replace" : "ACCENT_HOVER", "replace" : "ACCENT_HOVER",
"s" : 66,
"l" : 22, "light" : {
"a" : 1 "s" : 70,
"l" : 70,
"a" : 1
},
"dark" : {
"s" : 66,
"l" : 22,
"a" : 1
}
}, },
"accent-disabled" : { "accent-disabled" : {
"replace" : "ACCENT-DISABLED", "replace" : "ACCENT-DISABLED-COLOR",
"s" : 6,
"l" : 15, "light" : {
"a" : 1 "s" : 35,
"l" : 90,
"a" : 1
},
"dark" : {
"s" : 95,
"l" : 85,
"a" : 0.08
}
}, },
"accent-disabled_hover" : { "accent-disabled_hover" : {
"replace" : "ACCENT-DIS_HOVER", "replace" : "ACCENT-DISABLED_HOVER",
"s" : 7,
"l" : 20,
"a" : 1
},
"background-color" : { "light" : {
"replace" : "BACKGROUND-COLOR", "s" : 35,
"s" : 7, "l" : 85,
"l" : 8, "a" : 1
"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" : { "dark" : {
"replace" : "QUICK-TOGGLE-MENU-BACKGROUND", "s" : 40,
"s" : 6, "l" : 85,
"l" : 10, "a" : 0.13
"a" : 1 }
}, },
"accent-secondary-color" : { "accent-secondary-color" : {
"replace" : "ACCENT-SECONDARY-COLOR", "replace" : "ACCENT-SECONDARY-COLOR",
"s" : 20,
"l" : 75, "light" : {
"a" : 1 "s" : 20,
}, "l" : 50,
"a" : 1
},
"dark" : {
"s" : 20,
"l" : 75,
"a" : 1
}
},
"accent-secondary_hover" : { "accent-secondary_hover" : {
"replace" : "ACCENT-SECONDARY_HOVER", "replace" : "ACCENT-SECONDARY_HOVER",
"s" : 20,
"l" : 70, "light" : {
"a" : 1 "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" : { "well-app-selected" : {
"replace" : "WELL-APP-SELECTED", "replace" : "WELL-APP-SELECTED",
"s" : 20,
"l" : 75, "light" : {
"a" : 0.4 "s" : 20,
"l" : 50,
"a" : 0.4
},
"dark" : {
"s" : 20,
"l" : 75,
"a" : 0.4
}
}, },
"text-primary-color" : { "text-primary-color" : {
"replace" : "TEXT-PRIMARY-COLOR", "replace" : "TEXT-PRIMARY-COLOR",
"s" : 65,
"l" : 95, "light" : {
"a" : 1 "s" : 71,
"l" : 10,
"a" : 0.87
},
"dark" : {
"s" : 65,
"l" : 95,
"a" : 1
}
}, },
"text-secondary-color" : { "text-secondary-color" : {
"replace" : "TEXT-SECONDARY-COLOR", "replace" : "TEXT-SECONDARY-COLOR",
"s" : 65,
"l" : 95, "light" : {
"a" : 0.67 "s" : 71,
"l" : 10,
"a" : 0.6
},
"dark" : {
"s" : 65,
"l" : 95,
"a" : 0.67
}
}, },
"text-disabled-color" : { "text-disabled-color" : {
"replace" : "TEXT-DISABLED-COLOR", "replace" : "TEXT-DISABLED-COLOR",
"s" : 65,
"l" : 95, "light" : {
"a" : 0.38 "s" : 71,
"l" : 10,
"a" : 0.38
},
"dark" : {
"s" : 65,
"l" : 95,
"a" : 0.38
}
}, },
"text-inverted-color": { "text-inverted-color": {
"replace" : "TEXT-INVERTED-COLOR", "replace" : "TEXT-INVERTED-COLOR",
"s" : 71,
"l" : 10, "light" : {
"a" : 0.87 "s" : 65,
"l" : 95,
"a" : 1
},
"dark" : {
"s" : 71,
"l" : 10,
"a" : 0.87
}
}, },
"border-shadow" : { "border-shadow" : {
"replace" : "BORDER-SHADOW", "replace" : "BORDER-SHADOW",
"s" : 0,
"l" : 255,
"a" : 0.03
},
"bordermenu-shadow" : { "light" : {
"replace" : "BORDER-MENU-SHADOW", "s" : 0,
"s" : 0, "l" : 0,
"l" : 255, "a" : 0.03
"a" : 0.07 },
},
"separator-color" : { "dark" : {
"replace" : "SEPARATOR-COLOR", "s" : 0,
"s" : 0, "l" : 255,
"l" : 255, "a" : 0.03
"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
}, },
"border-menu-shadow" : { "border-menu-shadow" : {
"replace" : "BORDER-MENU-SHADOW", "replace" : "BORDER-MENU-SHADOW",
"s" : 0,
"l" : 0, "light" : {
"a" : 0.07 "s" : 0,
"l" : 0,
"a" : 0.07
},
"dark" : {
"s" : 0,
"l" : 255,
"a" : 0.07
}
}, },
"separator-color" : { "separator-color" : {
"replace" : "SEPARATOR-COLOR", "replace" : "SEPARATOR-COLOR",
"s" : 0,
"l" : 0, "light" : {
"a" : 0.1 "s" : 0,
"l" : 0,
"a" : 0.1
},
"dark" : {
"s" : 0,
"l" : 255,
"a" : 0.1
}
}, },
"show-apps-icon-color" : { "show-apps-icon-color" : {
"replace" : "SHOW-APPS-ICON-COLOR", "replace" : "SHOW-APPS-ICON-COLOR",
"s" : 4,
"l" : 30, "light" : {
"a" : 1 "s" : 4,
"l" : 30,
"a" : 1
},
"dark" : {
"s" : 65,
"l" : 95,
"a" : 1
}
}, },
"scrollbar-color" : { "scrollbar-color" : {
"replace" : "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" : { "scrollbar_hover" : {
"replace" : "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" : { "scrollbar_active" : {
"replace" : "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" : { "page-nav-hint" : {
"replace" : "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" : { "section-color" : {
"replace" : "SECTION-COLOR", "replace" : "SECTION-COLOR",
"s" : 45,
"l" : 92, "light" : {
"a" : 1 "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" : { "colors" : {
@@ -351,7 +432,5 @@
"pink" : { "pink" : {
"h" : 295 "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("/") destinationDirs = destination.split("/")
loopCreateDirs = f"{destinationDirs[0]}/" loopCreateDirs = f"{destinationDirs[0]}/"
# create every folder
for i in range(1, len(destinationDirs)): for i in range(1, len(destinationDirs)):
loopCreateDirs += f"{destinationDirs[i]}/" loopCreateDirs += f"{destinationDirs[i]}/"
os.system(f"mkdir -p {loopCreateDirs}") 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: with open(os.path.expanduser(f"{destination}/{apply_file}"), "r") as file:
edit_file = file.read() edit_file = file.read()
# colorsys works in range(0, 1)
h = hue / 360 h = hue / 360
for i in colors[f"{theme_mode}"]: for element in colors["elements"]:
lightness = int(colors[f"{theme_mode}"][i]["l"]) / 100
saturation = int(colors[f"{theme_mode}"][i]["s"]) / 100 if sat is None else sat # 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"], replace_keyword = colors["elements"][element]["replace"]
f"rgba({int(hls_to_rgb[0] * 256)},"
f"{int(hls_to_rgb[1] * 256)}," edit_file = edit_file.replace(replace_keyword, f"rgba({red}, {green}, {blue}, {alpha})")
f"{int(hls_to_rgb[2] * 256)},"
f"{colors[f'{theme_mode}'][i]['a']})")
with open(os.path.expanduser(f"{destination}/{apply_file}"), "w") as file: with open(os.path.expanduser(f"{destination}/{apply_file}"), "w") as file:
file.write(edit_file) file.write(edit_file)
colorsOpen.close()
def apply_theme(hue, destination, theme_mode, sat=None): 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) :param sat: color saturation (optional)
""" """
for applyFile in colors["apply-theme-files"]: for apply_file in os.listdir("./gnome-shell/"):
apply_theme_to_file(hue, destination, theme_mode, applyFile, sat=sat) apply_theme_to_file(hue, destination, theme_mode, apply_file, sat=sat)
def install_color(hue, path_name, theme_mode, sat=None): 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=" ") 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)) else:
apply_theme(hue, destination_return(path_name, theme_mode), theme_mode, sat=sat) print("Done.")
print("Done.")
def install_all(theme_mode): def install_all(theme_mode):
""" """
Install all accent colors listed in "colors", colors.json Install all accent colors listed in "colors", colors.json
:param theme_mode: theme name (light or dark) :param theme_mode: theme name (light or dark)
""" """
# install hue colors listed in colors.json
for color in colors["colors"]: for color in colors["colors"]:
install_color(colors["colors"][color]["h"], color, theme_mode) install_color(colors["colors"][color]["h"], color, theme_mode)
# install gray color separately
install_color(0, "gray", theme_mode, sat=0) install_color(0, "gray", theme_mode, sat=0)
@@ -152,7 +162,6 @@ def main():
user_input = input("\n>>> ").lower().split() user_input = input("\n>>> ").lower().split()
userInputLength = len(user_input) userInputLength = len(user_input)
# this part is a piece of sh....
# i'll rewrite it later # i'll rewrite it later
match user_input[0]: match user_input[0]:
case "-a" | "--all": case "-a" | "--all":
@@ -204,9 +213,11 @@ def main():
install_color(int(user_input[1]), user_input[2], user_input[3]) install_color(int(user_input[1]), user_input[2], user_input[3])
print_help()
colorsOpen = open("colors.json") if __name__ == "__main__":
colors = json.loads(colorsOpen.read()) # used as database for replacing colors, files which must be generated
main() print_help()
colors = json.load(open("colors.json")) # used as database for replacing colors, files which must be generated
main()