Adding stronger type enforcement for settings; css transparency changes

This commit is contained in:
itdominator 2024-10-20 15:06:20 -05:00
parent fafc1a985f
commit fa46c39a7b
1 changed files with 47 additions and 47 deletions

View File

@ -22,35 +22,35 @@ class MissingConfigError(Exception):
class SettingsManager(StartCheckMixin, Singleton): class SettingsManager(StartCheckMixin, Singleton):
def __init__(self): def __init__(self):
self._SCRIPT_PTH = path.dirname(path.realpath(__file__)) self._SCRIPT_PTH: str = path.dirname(path.realpath(__file__))
self._USER_HOME = path.expanduser('~') self._USER_HOME: str = path.expanduser('~')
self._HOME_CONFIG_PATH = f"{self._USER_HOME}/.config/{APP_NAME.lower()}" self._HOME_CONFIG_PATH: str = f"{self._USER_HOME}/.config/{APP_NAME.lower()}"
self._USR_PATH = f"/usr/share/{APP_NAME.lower()}" self._USR_PATH: str = f"/usr/share/{APP_NAME.lower()}"
self._USR_CONFIG_FILE = f"{self._USR_PATH}/settings.json" self._USR_CONFIG_FILE: str = f"{self._USR_PATH}/settings.json"
self._CONTEXT_PATH = f"{self._HOME_CONFIG_PATH}/context_path" self._CONTEXT_PATH: str = f"{self._HOME_CONFIG_PATH}/context_path"
self._PLUGINS_PATH = f"{self._HOME_CONFIG_PATH}/plugins" self._PLUGINS_PATH: str = f"{self._HOME_CONFIG_PATH}/plugins"
self._DEFAULT_ICONS = f"{self._HOME_CONFIG_PATH}/icons" self._DEFAULT_ICONS: str = f"{self._HOME_CONFIG_PATH}/icons"
self._CONFIG_FILE = f"{self._HOME_CONFIG_PATH}/settings.json" self._CONFIG_FILE: str = f"{self._HOME_CONFIG_PATH}/settings.json"
self._GLADE_FILE = f"{self._HOME_CONFIG_PATH}/Main_Window.glade" self._GLADE_FILE: str = f"{self._HOME_CONFIG_PATH}/Main_Window.glade"
self._CSS_FILE = f"{self._HOME_CONFIG_PATH}/stylesheet.css" self._CSS_FILE: str = f"{self._HOME_CONFIG_PATH}/stylesheet.css"
self._KEY_BINDINGS_FILE = f"{self._HOME_CONFIG_PATH}/key-bindings.json" self._KEY_BINDINGS_FILE: str = f"{self._HOME_CONFIG_PATH}/key-bindings.json"
self._PID_FILE = f"{self._HOME_CONFIG_PATH}/{APP_NAME.lower()}.pid" self._PID_FILE: str = f"{self._HOME_CONFIG_PATH}/{APP_NAME.lower()}.pid"
self._UI_WIDEGTS_PATH = f"{self._HOME_CONFIG_PATH}/ui_widgets" self._UI_WIDEGTS_PATH: str = f"{self._HOME_CONFIG_PATH}/ui_widgets"
self._CONTEXT_MENU = f"{self._HOME_CONFIG_PATH}/contexct_menu.json" self._CONTEXT_MENU: str = f"{self._HOME_CONFIG_PATH}/contexct_menu.json"
self._WINDOW_ICON = f"{self._DEFAULT_ICONS}/{APP_NAME.lower()}.png" self._WINDOW_ICON: str = f"{self._DEFAULT_ICONS}/{APP_NAME.lower()}.png"
# self._USR_CONFIG_FILE = f"{self._USR_PATH}/settings.json" # self._USR_CONFIG_FILE: str = f"{self._USR_PATH}/settings.json"
# self._PLUGINS_PATH = f"plugins" # self._PLUGINS_PATH: str = f"plugins"
# self._CONFIG_FILE = f"settings.json" # self._CONFIG_FILE: str = f"settings.json"
# self._GLADE_FILE = f"Main_Window.glade" # self._GLADE_FILE: str = f"Main_Window.glade"
# self._CSS_FILE = f"stylesheet.css" # self._CSS_FILE: str = f"stylesheet.css"
# self._KEY_BINDINGS_FILE = f"key-bindings.json" # self._KEY_BINDINGS_FILE: str = f"key-bindings.json"
# self._PID_FILE = f"{APP_NAME.lower()}.pid" # self._PID_FILE: str = f"{APP_NAME.lower()}.pid"
# self._WINDOW_ICON = f"{APP_NAME.lower()}.png" # self._WINDOW_ICON: str = f"{APP_NAME.lower()}.png"
# self._UI_WIDEGTS_PATH = f"ui_widgets" # self._UI_WIDEGTS_PATH: str = f"ui_widgets"
# self._CONTEXT_MENU = f"contexct_menu.json" # self._CONTEXT_MENU: str = f"contexct_menu.json"
# self._DEFAULT_ICONS = f"icons" # self._DEFAULT_ICONS: str = f"icons"
# with zipfile.ZipFile("files.zip", mode="r", allowZip64=True) as zf: # with zipfile.ZipFile("files.zip", mode="r", allowZip64=True) as zf:
@ -102,16 +102,16 @@ class SettingsManager(StartCheckMixin, Singleton):
print( f"Settings Manager: {self._CONTEXT_MENU}\n\t\t{repr(e)}" ) print( f"Settings Manager: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
self.settings: Settings = None self.settings: Settings = None
self._main_window = None self._main_window = None
self._builder = None self._builder = None
self.PAINT_BG_COLOR = (0, 0, 0, 0.0) self.PAINT_BG_COLOR: tuple = (0, 0, 0, 0.0)
self._trace_debug = False self._trace_debug: bool = False
self._debug = False self._debug: bool = False
self._dirty_start = False self._dirty_start: bool = False
self._passed_in_file = False self._passed_in_file: bool = False
self._starting_files = [] self._starting_files: list = []
def register_signals_to_builder(self, classes = None): def register_signals_to_builder(self, classes = None):
@ -159,23 +159,23 @@ class SettingsManager(StartCheckMixin, Singleton):
def is_debug(self) -> str: return self._debug def is_debug(self) -> str: return self._debug
def is_starting_with_file(self) -> bool: return self._passed_in_file def is_starting_with_file(self) -> bool: return self._passed_in_file
def call_method(self, target_class = None, _method_name = None, data = None): def call_method(self, target_class: any = None, _method_name: str = "", data: any = None):
method_name = str(_method_name) method_name = str(_method_name)
method = getattr(target_class, method_name, lambda data: f"No valid key passed...\nkey={method_name}\nargs={data}") method = getattr(target_class, method_name, lambda data: f"No valid key passed...\nkey={method_name}\nargs={data}")
return method(data) if data else method() return method(data) if data else method()
def set_main_window_x(self, x = 0): self.settings.config.main_window_x = x def set_main_window_x(self, x: int = 0): self.settings.config.main_window_x = x
def set_main_window_y(self, y = 0): self.settings.config.main_window_y = y def set_main_window_y(self, y: int = 0): self.settings.config.main_window_y = y
def set_main_window_width(self, width = 800): self.settings.config.main_window_width = width def set_main_window_width(self, width: int = 800): self.settings.config.main_window_width = width
def set_main_window_height(self, height = 600): self.settings.config.main_window_height = height def set_main_window_height(self, height: int = 600): self.settings.config.main_window_height = height
def set_main_window_min_width(self, width = 720): self.settings.config.main_window_min_width = width def set_main_window_min_width(self, width: int = 720): self.settings.config.main_window_min_width = width
def set_main_window_min_height(self, height = 480): self.settings.config.main_window_min_height = height def set_main_window_min_height(self, height: int = 480): self.settings.config.main_window_min_height = height
def set_starting_files(self, files: list) -> None: self._starting_files = files def set_starting_files(self, files: list): self._starting_files = files
def set_trace_debug(self, trace_debug): def set_trace_debug(self, trace_debug: bool):
self._trace_debug = trace_debug self._trace_debug = trace_debug
def set_debug(self, debug): def set_debug(self, debug: bool):
self._debug = debug self._debug = debug
def set_is_starting_with_file(self, is_passed_in_file: bool = False): def set_is_starting_with_file(self, is_passed_in_file: bool = False):
@ -193,4 +193,4 @@ class SettingsManager(StartCheckMixin, Singleton):
def save_settings(self): def save_settings(self):
with open(self._CONFIG_FILE, 'w') as outfile: with open(self._CONFIG_FILE, 'w') as outfile:
json.dump(self.settings.as_dict(), outfile, separators=(',', ':'), indent=4) json.dump(self.settings.as_dict(), outfile, separators=(',', ':'), indent=4)