From 5264103f315ec8bbfb756c7c6d16ea43c2d78e42 Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Sat, 5 Aug 2023 20:02:51 -0500 Subject: [PATCH] Internalized default settings --- .../solarfm/utils/settings_manager/manager.py | 12 ++- .../utils/settings_manager/options/config.py | 46 +++++----- .../settings_manager/options/debugging.py | 4 +- .../utils/settings_manager/options/filters.py | 90 +++++++++++++++++-- .../settings_manager/options/settings.py | 21 +++-- .../utils/settings_manager/options/theming.py | 6 +- user_config/usr/share/solarfm/settings.json | 45 ---------- 7 files changed, 126 insertions(+), 98 deletions(-) delete mode 100644 user_config/usr/share/solarfm/settings.json diff --git a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/manager.py b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/manager.py index e520914..75903b6 100644 --- a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/manager.py +++ b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/manager.py @@ -47,13 +47,6 @@ class SettingsManager(StartCheckMixin, Singleton): if not os.path.exists(self._PLUGINS_PATH): os.mkdir(self._PLUGINS_PATH) - if not os.path.exists(self._CONFIG_FILE): - import shutil - try: - shutil.copyfile(self._USR_CONFIG_FILE, self._CONFIG_FILE) - except Exception as e: - raise - if not os.path.exists(self._DEFAULT_ICONS): self._DEFAULT_ICONS = f"{self._USR_PATH}/icons" if not os.path.exists(self._DEFAULT_ICONS): @@ -158,8 +151,13 @@ class SettingsManager(StartCheckMixin, Singleton): self._debug = debug def load_settings(self): + if not os.path.exists(self._CONFIG_FILE): + self.settings = Settings() + return + with open(self._CONFIG_FILE) as file: data = json.load(file) + data["load_defaults"] = False self.settings = Settings(**data) def save_settings(self): diff --git a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/config.py b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/config.py index 7b2e5a6..d5f2e29 100644 --- a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/config.py +++ b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/config.py @@ -1,5 +1,5 @@ # Python imports -from dataclasses import dataclass +from dataclasses import dataclass, field # Lib imports @@ -8,25 +8,25 @@ from dataclasses import dataclass @dataclass class Config: - base_of_home: str - hide_hidden_files: str - thumbnailer_path: str - blender_thumbnailer_path: str - go_past_home: str - lock_folder: str - locked_folders: str - mplayer_options: str - music_app: str - media_app: str - image_app: str - office_app: str - pdf_app: str - code_app: str - text_app: str - terminal_app: str - container_icon_wh: [] - video_icon_wh: [] - sys_icon_wh: [] - file_manager_app: str - steam_cdn_url: str - remux_folder_max_disk_usage: str + base_of_home: str = "" + hide_hidden_files: str = "true" + thumbnailer_path: str = "ffmpegthumbnailer" + blender_thumbnailer_path: str = "" + go_past_home: str = "true" + lock_folder: str = "false" + locked_folders: list = field(default_factory=lambda: ["venv", "flasks"]) + mplayer_options: str = "-quiet -really-quiet -xy 1600 -geometry 50%:50%" + music_app: str = "deadbeef" + media_app: str = "mpv" + image_app: str = "mirage" + office_app: str = "libreoffice" + pdf_app: str = "evince" + code_app: str = "atom" + text_app: str = "mousepad" + terminal_app: str = "terminator" + file_manager_app: str = "solarfm" + container_icon_wh: list = field(default_factory=lambda: [128, 128]) + video_icon_wh: list = field(default_factory=lambda: [128, 64]) + sys_icon_wh: list = field(default_factory=lambda: [56, 56]) + steam_cdn_url: str = "https://steamcdn-a.akamaihd.net/steam/apps/" + remux_folder_max_disk_usage: str = "8589934592" diff --git a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/debugging.py b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/debugging.py index 22c9957..3fc605d 100644 --- a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/debugging.py +++ b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/debugging.py @@ -8,5 +8,5 @@ from dataclasses import dataclass @dataclass class Debugging: - ch_log_lvl: int - fh_log_lvl: int + ch_log_lvl: int = 10 + fh_log_lvl: int = 20 diff --git a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/filters.py b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/filters.py index 7666358..e5293bf 100644 --- a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/filters.py +++ b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/filters.py @@ -1,5 +1,5 @@ # Python imports -from dataclasses import dataclass +from dataclasses import dataclass, field # Lib imports @@ -8,11 +8,83 @@ from dataclasses import dataclass @dataclass class Filters: - meshs: [] - code: [] - videos: [] - office: [] - images: [] - text: [] - music: [] - pdf: [] + meshs: list = field(default_factory=lambda: [ + ".blend", + ".dae", + ".fbx", + ".gltf", + ".obj", + ".stl" + ]) + code: list = field(default_factory=lambda: [ + ".cpp", + ".css", + ".c", + ".go", + ".html", + ".htm", + ".java", + ".js", + ".json", + ".lua", + ".md", + ".py", + ".rs", + ".toml", + ".xml", + ".pom" + ]) + videos: list = field(default_factory=lambda:[ + ".mkv", + ".mp4", + ".webm", + ".avi", + ".mov", + ".m4v", + ".mpg", + ".mpeg", + ".wmv", + ".flv" + ]) + office: list = field(default_factory=lambda: [ + ".doc", + ".docx", + ".xls", + ".xlsx", + ".xlt", + ".xltx", + ".xlm", + ".ppt", + ".pptx", + ".pps", + ".ppsx", + ".odt", + ".rtf" + ]) + images: list = field(default_factory=lambda: [ + ".png", + ".jpg", + ".jpeg", + ".gif", + ".ico", + ".tga", + ".webp" + ]) + text: list = field(default_factory=lambda: [ + ".txt", + ".text", + ".sh", + ".cfg", + ".conf", + ".log" + ]) + music: list = field(default_factory=lambda: [ + ".psf", + ".mp3", + ".ogg", + ".flac", + ".m4a" + ]) + pdf: list = field(default_factory=lambda: [ + ".pdf" + ]) diff --git a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/settings.py b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/settings.py index 4aff789..0e3597b 100644 --- a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/settings.py +++ b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/settings.py @@ -1,5 +1,5 @@ # Python imports -from dataclasses import dataclass +from dataclasses import dataclass, field from dataclasses import asdict # Gtk imports @@ -13,16 +13,19 @@ from .debugging import Debugging @dataclass class Settings: - config: Config - filters: Filters - theming: Theming - debugging: Debugging + load_defaults: bool = True + config: Config = field(default_factory=lambda: Config()) + filters: Filters = field(default_factory=lambda: Filters()) + theming: Theming = field(default_factory=lambda: Theming()) + debugging: Debugging = field(default_factory=lambda: Debugging()) def __post_init__(self): - self.config = Config(**self.config) - self.filters = Filters(**self.filters) - self.theming = Theming(**self.theming) - self.debugging = Debugging(**self.debugging) + if not self.load_defaults: + self.load_defaults = False + self.config = Config(**self.config) + self.filters = Filters(**self.filters) + self.theming = Theming(**self.theming) + self.debugging = Debugging(**self.debugging) def as_dict(self): return asdict(self) diff --git a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/theming.py b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/theming.py index eff7696..034f7bd 100644 --- a/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/theming.py +++ b/src/versions/solarfm-0.0.1/solarfm/utils/settings_manager/options/theming.py @@ -8,6 +8,6 @@ from dataclasses import dataclass @dataclass class Theming: - success_color: str - warning_color: str - error_color: str + success_color: str = "#88cc27" + warning_color: str = "#ffa800" + error_color: str = "#ff0000" diff --git a/user_config/usr/share/solarfm/settings.json b/user_config/usr/share/solarfm/settings.json deleted file mode 100644 index 63644cb..0000000 --- a/user_config/usr/share/solarfm/settings.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "config": { - "base_of_home": "", - "hide_hidden_files": "true", - "thumbnailer_path": "ffmpegthumbnailer", - "blender_thumbnailer_path": "", - "go_past_home": "true", - "lock_folder": "false", - "locked_folders": "venv::::flasks", - "mplayer_options": "-quiet -really-quiet -xy 1600 -geometry 50%:50%", - "music_app": "deadbeef", - "media_app": "mpv", - "image_app": "mirage2", - "office_app": "libreoffice", - "pdf_app": "evince", - "code_app": "atom", - "text_app": "mousepad", - "terminal_app": "terminator", - "container_icon_wh": [128, 128], - "video_icon_wh": [128, 64], - "sys_icon_wh": [56, 56], - "file_manager_app": "solarfm", - "steam_cdn_url": "https://steamcdn-a.akamaihd.net/steam/apps/", - "remux_folder_max_disk_usage": "8589934592" - }, - "filters": { - "meshs": [".dae", ".fbx", ".gltf", ".obj", ".stl"], - "code": [".cpp", ".css", ".c", ".go", ".html", ".htm", ".java", ".js", ".json", ".lua", ".md", ".py", ".rs", ".toml", ".xml", ".pom"], - "videos": [".mkv", ".mp4", ".webm", ".avi", ".mov", ".m4v", ".mpg", ".mpeg", ".wmv", ".flv"], - "office": [".doc", ".docx", ".xls", ".xlsx", ".xlt", ".xltx", ".xlm", ".ppt", ".pptx", ".pps", ".ppsx", ".odt", ".rtf"], - "images": [".png", ".jpg", ".jpeg", ".gif", ".ico", ".tga", ".webp"], - "text": [".txt", ".text", ".sh", ".cfg", ".conf", ".log"], - "music": [".psf", ".mp3", ".ogg", ".flac", ".m4a"], - "pdf": [".pdf"] - }, - "theming":{ - "success_color": "#88cc27", - "warning_color": "#ffa800", - "error_color": "#ff0000" - }, - "debugging": { - "ch_log_lvl": 20, - "fh_log_lvl": 10 - } -}