diff --git a/scripts/gdm.py b/scripts/gdm.py index 78120f0..ea4fa3e 100644 --- a/scripts/gdm.py +++ b/scripts/gdm.py @@ -3,7 +3,7 @@ import subprocess import shutil from .theme import Theme -from .utils import label_files +from .utils import label_files, remove_properties, remove_keywords from . import config @@ -29,6 +29,8 @@ class GlobalTheme: self.backup_trigger = "\n/* Marble theme */\n" # trigger to check if theme is installed self.extracted_theme = f"{self.temp_folder}/{config.extracted_gdm_folder}" self.gst = f"{self.destination_folder}/{self.destination_file}" # use backup file if theme is installed + self.extracted_light_theme = f"{self.extracted_theme}/gnome-shell-light.css" + self.extracted_dark_theme = f"{self.extracted_theme}/gnome-shell-dark.css" os.makedirs(self.temp_folder, exist_ok=True) # create temp folder @@ -103,6 +105,15 @@ class GlobalTheme: # add -light label to light theme files because they are installed to the same folder label_files(self.light_theme.temp_folder, "light", self.light_theme.main_styles) + # remove !important from the gnome file + remove_keywords(self.extracted_light_theme, "!important") + remove_keywords(self.extracted_dark_theme, "!important") + + # remove properties from the gnome file + props_to_remove = ("background-color", "color", "box-shadow", "border-radius") + remove_properties(self.extracted_light_theme, *props_to_remove) + remove_properties(self.extracted_dark_theme, *props_to_remove) + # add gnome styles to the start of the file self.__add_gnome_styles(self.light_theme) self.__add_gnome_styles(self.dark_theme) diff --git a/scripts/utils.py b/scripts/utils.py index 8dca4f1..3f7fbf9 100644 --- a/scripts/utils.py +++ b/scripts/utils.py @@ -181,3 +181,43 @@ def label_files(directory, label, *args): file.seek(0) file.write(read_files[i]) file.close() + + +def remove_properties(file, *args): + """ + Remove properties from a file + :param file: file name + :param args: properties to remove + """ + + new_content = "" + + with open(file, "r+") as read_file: + content = read_file.read() + + for line in content.splitlines(): + if not any(prop in line for prop in args): + new_content += line + "\n" + elif "}" in line: + new_content += "}\n" + + read_file.seek(0) + read_file.write(new_content) + + +def remove_keywords(file, *args): + """ + Remove keywords from a file + :param file: file name + :param args: keywords to remove + """ + + with open(file, "r+") as read_file: + content = read_file.read() + + for arg in args: + content = content.replace(arg, "") + + read_file.seek(0) + read_file.write(content) + \ No newline at end of file