rework logging, add more dataclasses, reworked config

This commit is contained in:
2024-12-17 10:02:56 +01:00
parent ccb4df10bb
commit eda556b5ea
41 changed files with 1624 additions and 865 deletions

View File

@@ -64,19 +64,62 @@ class Mail:
def _setattr(self, name, value):
setattr(self, name, value)
def setValue(self, **kwargs):
for key, value in kwargs.items():
if hasattr(self, key):
setattr(self, key, value)
else:
raise KeyError(f"Invalid option: {key}")
class Icons:
def __init__(self):
self._path = None
self._colors = None
self._icons = None
def assign(self, key, value):
setattr(self, key, value)
@property
def path(self):
return self._path
@path.setter
def path(self, value):
self._path = value
@property
def colors(self):
return self._colors
@colors.setter
def colors(self, value):
self._colors = value
@property
def icons(self):
return self._icons
@icons.setter
def icons(self, value):
self._icons = value
def get(self, name):
return self.icons.get(name)
class Config:
'''A class to handle the configuration of the application. After initializing, it will try to load the config file and store it for future access. Any changes made can be saved to the file using the .save() method. Changes are used in real time in the app, if a restart is required, the Application will show a window.
"""A class to handle the configuration of the application. After initializing, it will try to load the config file and store it for future access. Any changes made can be saved to the file using the .save() method. Changes are used in real time in the app, if a restart is required, the Application will show a window.
Raises:
RuntimeError: Configuration not loaded
KeyError: Invalid option
'''
"""
_config: Optional[DictConfig] = None
def __init__(self, config_path: str):
"""
Loads the configuration file and stores it for future access.
@@ -141,6 +184,9 @@ class Config:
def set_zotero_attr(self, name, value):
OmegaConf.update(self._config, f"zotero.{name}", value)
def set_icon_attr(self, name, value):
OmegaConf.update(self._config, f"icons.{name}", value)
@property
def save_path(self):
return self._config.save_path
@@ -149,14 +195,16 @@ class Config:
def save_path(self, value: str):
self._config.save_path = value
@property
def icon_path(self):
"""Path to Icon folder
def load_config(self, path, filename):
return OmegaConf.load(os.path.join(path, filename))
Returns:
str: Folder path as string
"""
return self._config.icon_path
@property
def icons(self):
icons = Icons()
icons.assign("path", self._config.icon_path)
icons.assign("colors", self._config.colors)
icons.assign("icons", self._config.icons)
return icons
def dict(self):
return OmegaConf.to_container(self._config)
return OmegaConf.to_container(self._config)