diff --git a/scripts/utils/theme/gnome_shell_theme_builder.py b/scripts/utils/theme/gnome_shell_theme_builder.py index c51b0eb..5a6a586 100644 --- a/scripts/utils/theme/gnome_shell_theme_builder.py +++ b/scripts/utils/theme/gnome_shell_theme_builder.py @@ -4,11 +4,13 @@ from scripts import config from scripts.install.colors_definer import ColorsDefiner from scripts.utils.color_converter import ColorConverterImpl from scripts.utils.logger.console import Console +from scripts.utils.style_manager import StyleManager from scripts.utils.theme.theme import Theme from scripts.utils.theme.theme_color_applier import ColorReplacementGenerator, ThemeColorApplier from scripts.utils.theme.theme_installer import ThemeInstaller from scripts.utils.theme.theme_path_provider import ThemePathProvider from scripts.utils.theme.theme_preparation import ThemePreparation +from scripts.utils.theme.theme_temp_manager import ThemeTempManager from theme import SourceFolder @@ -78,8 +80,12 @@ class GnomeShellThemeBuilder: return Theme(self.preparation, self.installer, self.mode, self.is_filled) def _resolve_preparation(self): - if self.preparation is None: - self.preparation = ThemePreparation(self.source_folder, self.temp_folder, self.main_styles) + if self.preparation is not None: return + + file_manager = ThemeTempManager(self.temp_folder) + style_manager = StyleManager(self.main_styles) + self.preparation = ThemePreparation(self.source_folder, + file_manager=file_manager, style_manager=style_manager) def _resolve_installer(self): if self.installer is not None: return diff --git a/scripts/utils/theme/theme_preparation.py b/scripts/utils/theme/theme_preparation.py index fb7dedd..6d12c83 100644 --- a/scripts/utils/theme/theme_preparation.py +++ b/scripts/utils/theme/theme_preparation.py @@ -1,4 +1,5 @@ import os +import warnings from scripts.utils import replace_keywords from scripts.utils.theme.theme_temp_manager import ThemeTempManager @@ -11,32 +12,49 @@ class ThemePreparation: and preparing them for installation. """ - def __init__(self, sources_location: str, temp_folder: str, combined_styles_location: str): + def __init__(self, sources_location: str, file_manager: ThemeTempManager, style_manager: StyleManager): self.sources_location = sources_location - self.temp_folder = temp_folder - self.combined_styles_location = combined_styles_location - self.file_manager = ThemeTempManager(temp_folder) - self.style_manager = StyleManager(combined_styles_location) + self.file_manager = file_manager + self.style_manager = style_manager + + @property + def temp_folder(self): + return self.file_manager.temp_folder + + @property + def combined_styles_location(self): + return self.style_manager.output_file def __add__(self, content: str) -> "ThemePreparation": + """Append additional styles to the main styles file.""" self.style_manager.append_content(content) return self def __mul__(self, content: str) -> "ThemePreparation": + """Adds a file to the theme, copying it to the temporary folder.""" self.file_manager.copy_to_temp(content) return self def add_to_start(self, content) -> "ThemePreparation": + """Inserts content at the beginning of the main styles file.""" self.style_manager.prepend_content(content) return self def prepare(self): + """ + Extract theme from source folder and prepare it for installation. + """ self.file_manager.prepare_files(self.sources_location) self.style_manager.generate_combined_styles(self.sources_location, self.temp_folder) self.file_manager.cleanup() + @warnings.deprecated def replace_filled_keywords(self): + """ + Replace keywords in the theme files for filled mode. + This method is deprecated and will be removed in future versions. + """ for apply_file in os.listdir(f"{self.temp_folder}/"): replace_keywords(f"{self.temp_folder}/{apply_file}", ("BUTTON-COLOR", "ACCENT-FILLED-COLOR"),