fix: replace all instances in case of accents
Signed-off-by: Pranav <npv12@iitbbs.ac.in>
This commit is contained in:
@@ -1,32 +1,23 @@
|
|||||||
from catppuccin import Flavour
|
from catppuccin import Flavour
|
||||||
|
|
||||||
from .utils import replacetext
|
from .utils import replacetext, replaceAllText
|
||||||
from .var import (def_accent_dark, def_accent_light, def_color_map, src_dir,
|
from .var import (def_accent_dark, def_accent_light, def_color_map, src_dir,
|
||||||
theme_name, work_dir)
|
theme_name, work_dir)
|
||||||
|
|
||||||
|
|
||||||
def recolor_accent(flavor, file: str, accent: str = "blue"):
|
def recolor_accent(flavor, accent: str = "blue"):
|
||||||
"""
|
"""
|
||||||
Recolors the accent color in a file.
|
Recolors the accent color in a file.
|
||||||
flavor:
|
flavor:
|
||||||
The flavor to recolor to. Like mocha, frappe, latte, etc.
|
The flavor to recolor to. Like mocha, frappe, latte, etc.
|
||||||
file:
|
|
||||||
The file to modify
|
|
||||||
accent:
|
accent:
|
||||||
The accent color to replace. Defaults to Blue
|
The accent color to replace. Defaults to Blue
|
||||||
"""
|
"""
|
||||||
print(f"Recoloring accent for {file}...")
|
print(f"Recoloring all accents")
|
||||||
# Recolor as per accent for light. Hard code it as latte
|
replaceAllText( # Recolor as per base for dark theme.
|
||||||
for key, value in Flavour.latte().__dict__.items():
|
work_dir, def_accent_dark[def_color_map[accent]], flavor.__dict__[accent].hex)
|
||||||
if key == accent:
|
replaceAllText( # Recolor as per accent for light. Hard code it as latte
|
||||||
replacetext(
|
work_dir, def_accent_light[def_color_map[accent]], Flavour.latte().__dict__[accent].hex)
|
||||||
file, def_accent_light[def_color_map[accent]], value.hex)
|
|
||||||
|
|
||||||
# Recolor as per base for dark theme.
|
|
||||||
for key, value in flavor.__dict__.items():
|
|
||||||
if key == accent:
|
|
||||||
replacetext(
|
|
||||||
file, def_accent_dark[def_color_map[accent]], value.hex)
|
|
||||||
|
|
||||||
|
|
||||||
def recolor(flavor, accent: str):
|
def recolor(flavor, accent: str):
|
||||||
@@ -36,10 +27,10 @@ def recolor(flavor, accent: str):
|
|||||||
print("Recoloring to suit catppuccin theme")
|
print("Recoloring to suit catppuccin theme")
|
||||||
replacetext(f"{work_dir}/install.sh", "Colloid", theme_name)
|
replacetext(f"{work_dir}/install.sh", "Colloid", theme_name)
|
||||||
|
|
||||||
print("MOD: Gtkrc.sh")
|
print("Recoloring accents")
|
||||||
# Recolor as per accent for dark
|
recolor_accent(flavor, accent)
|
||||||
recolor_accent(flavor, f"{work_dir}/gtkrc.sh", accent)
|
|
||||||
|
|
||||||
|
print("MOD: Gtkrc.sh")
|
||||||
replacetext(f"{work_dir}/gtkrc.sh", "background_light='#FFFFFF'",
|
replacetext(f"{work_dir}/gtkrc.sh", "background_light='#FFFFFF'",
|
||||||
f"background_light='#{Flavour.latte().base.hex}'") # use latte_base for background_light
|
f"background_light='#{Flavour.latte().base.hex}'") # use latte_base for background_light
|
||||||
replacetext(f"{work_dir}/gtkrc.sh", "background_dark='#0F0F0F'",
|
replacetext(f"{work_dir}/gtkrc.sh", "background_dark='#0F0F0F'",
|
||||||
@@ -64,8 +55,6 @@ def recolor(flavor, accent: str):
|
|||||||
"titlebar_dark='#242424'", f"titlebar_dark='#{flavor.crust.hex}'")
|
"titlebar_dark='#242424'", f"titlebar_dark='#{flavor.crust.hex}'")
|
||||||
|
|
||||||
print("Mod SASS Color_Palette_default")
|
print("Mod SASS Color_Palette_default")
|
||||||
recolor_accent(
|
|
||||||
flavor, f"{src_dir}/sass/_color-palette-default.scss", accent)
|
|
||||||
|
|
||||||
# Greys
|
# Greys
|
||||||
if flavor == Flavour.latte(): # Hardcode till someone smarter than me comes along
|
if flavor == Flavour.latte(): # Hardcode till someone smarter than me comes along
|
||||||
@@ -126,16 +115,3 @@ def recolor(flavor, accent: str):
|
|||||||
"button-max: #38c76a", f"button-max: #{flavor.green.hex}")
|
"button-max: #38c76a", f"button-max: #{flavor.green.hex}")
|
||||||
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
|
replacetext(f"{src_dir}/sass/_color-palette-default.scss",
|
||||||
"button-min: #fdbe04", f"button-min: #{flavor.yellow.hex}")
|
"button-min: #fdbe04", f"button-min: #{flavor.yellow.hex}")
|
||||||
|
|
||||||
print("Mod Accent Cinnamon")
|
|
||||||
recolor_accent(flavor, f"{src_dir}/assets/cinnamon/make-assets.sh", accent)
|
|
||||||
|
|
||||||
print("Mod Accent Gnome shell")
|
|
||||||
recolor_accent(
|
|
||||||
flavor, f"{src_dir}/assets/gnome-shell/make-assets.sh", accent)
|
|
||||||
|
|
||||||
print("Mod Accent GTK")
|
|
||||||
recolor_accent(flavor, f"{src_dir}/assets/gtk/make-assets.sh", accent)
|
|
||||||
|
|
||||||
print("Mod Accent GTK 2.0")
|
|
||||||
recolor_accent(flavor, f"{src_dir}/assets/gtk-2.0/make-assets.sh", accent)
|
|
||||||
|
@@ -4,25 +4,38 @@ import shutil
|
|||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
|
||||||
def replacetext(file_name: str, search_text: str, replace_text: str) -> None:
|
def replacetext(filepath: str, search_text: str, replace_text: str) -> None:
|
||||||
"""
|
"""
|
||||||
Helper function to replace the color in the file.
|
Helper function to replace the color in the file.
|
||||||
Can be used to replace any text in the file.
|
Can be used to replace any text in the file.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
file_name (str): The file to replace the text in.
|
filepath (str): The file to replace the text in.
|
||||||
search_text (str): The text to be replaced.
|
search_text (str): The text to be replaced.
|
||||||
replace_text (str): The text to replace with.
|
replace_text (str): The text to replace with.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
None
|
None
|
||||||
"""
|
"""
|
||||||
with open(file_name, 'r+') as f:
|
|
||||||
file = f.read()
|
try:
|
||||||
file = re.sub(search_text, replace_text, file)
|
with open(filepath, 'r+') as f:
|
||||||
f.seek(0)
|
file = f.read()
|
||||||
f.write(file)
|
file = re.sub(search_text, replace_text, file)
|
||||||
f.truncate()
|
f.seek(0)
|
||||||
|
f.write(file)
|
||||||
|
f.truncate()
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Failed to recolor {filepath}")
|
||||||
|
|
||||||
|
|
||||||
|
def replaceAllText(start_dir: str, search_text: str, replace_text: str) -> None:
|
||||||
|
for path, _, files in os.walk(os.path.abspath(start_dir)):
|
||||||
|
for filename in files:
|
||||||
|
filepath = os.path.join(path, filename)
|
||||||
|
if filepath.endswith(".png"):
|
||||||
|
continue
|
||||||
|
replacetext(filepath, search_text, replace_text)
|
||||||
|
|
||||||
|
|
||||||
def zipdir(path, ziph):
|
def zipdir(path, ziph):
|
||||||
@@ -38,7 +51,7 @@ def zipdir(path, ziph):
|
|||||||
os.path.join(path, '..')))
|
os.path.join(path, '..')))
|
||||||
|
|
||||||
|
|
||||||
def zip_multiple_folders(dir_list, zip_name, remove = True):
|
def zip_multiple_folders(dir_list, zip_name, remove=True):
|
||||||
zipf = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED)
|
zipf = zipfile.ZipFile(zip_name, 'w', zipfile.ZIP_DEFLATED)
|
||||||
for dir in dir_list:
|
for dir in dir_list:
|
||||||
zipdir(dir, zipf)
|
zipdir(dir, zipf)
|
||||||
|
Reference in New Issue
Block a user