Adding to settings control
This commit is contained in:
parent
9fd32b85f6
commit
4b4eac8f7d
|
@ -12,6 +12,9 @@ from utils.logger import Logger
|
||||||
from utils.settings_manager.manager import SettingsManager
|
from utils.settings_manager.manager import SettingsManager
|
||||||
|
|
||||||
|
|
||||||
|
class BuiltinsException(Exception):
|
||||||
|
...
|
||||||
|
|
||||||
|
|
||||||
# NOTE: Threads WILL NOT die with parent's destruction.
|
# NOTE: Threads WILL NOT die with parent's destruction.
|
||||||
def threaded_wrapper(fn):
|
def threaded_wrapper(fn):
|
||||||
|
@ -34,6 +37,9 @@ builtins.keybindings = Keybindings()
|
||||||
builtins.event_system = EventSystem()
|
builtins.event_system = EventSystem()
|
||||||
builtins.endpoint_registry = EndpointRegistry()
|
builtins.endpoint_registry = EndpointRegistry()
|
||||||
builtins.settings_manager = SettingsManager()
|
builtins.settings_manager = SettingsManager()
|
||||||
|
|
||||||
|
settings_manager.load_settings()
|
||||||
|
|
||||||
builtins.settings = settings_manager.settings
|
builtins.settings = settings_manager.settings
|
||||||
builtins.logger = Logger(settings_manager.get_home_config_path(), \
|
builtins.logger = Logger(settings_manager.get_home_config_path(), \
|
||||||
_ch_log_lvl=settings.debugging.ch_log_lvl, \
|
_ch_log_lvl=settings.debugging.ch_log_lvl, \
|
||||||
|
@ -42,3 +48,10 @@ builtins.logger = Logger(settings_manager.get_home_config_path(), \
|
||||||
builtins.threaded = threaded_wrapper
|
builtins.threaded = threaded_wrapper
|
||||||
builtins.daemon_threaded = daemon_threaded_wrapper
|
builtins.daemon_threaded = daemon_threaded_wrapper
|
||||||
builtins.event_sleep_time = 0.05
|
builtins.event_sleep_time = 0.05
|
||||||
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
from utils.models import _db
|
||||||
|
builtins.db = _db
|
||||||
|
except ModuleNotFoundError as e:
|
||||||
|
logger.debug("Warning: Likely Flask SQLAlchemy not installed...")
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
"""
|
"""
|
||||||
Gtk Bound Signal Module
|
Core Module
|
||||||
"""
|
"""
|
|
@ -0,0 +1,23 @@
|
||||||
|
# Python imports
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
from flask_sqlalchemy import SQLAlchemy
|
||||||
|
|
||||||
|
# Apoplication imports
|
||||||
|
|
||||||
|
|
||||||
|
_db = SQLAlchemy()
|
||||||
|
|
||||||
|
|
||||||
|
class User(_db.Model):
|
||||||
|
email = _db.Column(_db.Text())
|
||||||
|
username = _db.Column(_db.Text())
|
||||||
|
password = _db.Column(_db.Text())
|
||||||
|
id = _db.Column(_db.Integer, primary_key=True,
|
||||||
|
unique=True, autoincrement=True)
|
||||||
|
|
||||||
|
def __repr__(self):
|
||||||
|
return f"'{self.email}', '{self.username}', '{self.password}', '{self.id}'"
|
||||||
|
|
||||||
|
|
||||||
|
_db.create_all()
|
|
@ -1,10 +1,13 @@
|
||||||
# Python imports
|
# Python imports
|
||||||
import os
|
import signal
|
||||||
import io
|
import io
|
||||||
import json
|
import json
|
||||||
import inspect
|
import inspect
|
||||||
import zipfile
|
import zipfile
|
||||||
|
|
||||||
|
from os import path
|
||||||
|
from os import mkdir
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
|
@ -21,8 +24,8 @@ class MissingConfigError(Exception):
|
||||||
|
|
||||||
class SettingsManager(StartCheckMixin, Singleton):
|
class SettingsManager(StartCheckMixin, Singleton):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
|
self._SCRIPT_PTH = path.dirname(path.realpath(__file__))
|
||||||
self._USER_HOME = os.path.expanduser('~')
|
self._USER_HOME = path.expanduser('~')
|
||||||
self._HOME_CONFIG_PATH = f"{self._USER_HOME}/.config/{app_name.lower()}"
|
self._HOME_CONFIG_PATH = f"{self._USER_HOME}/.config/{app_name.lower()}"
|
||||||
self._USR_PATH = f"/usr/share/{app_name.lower()}"
|
self._USR_PATH = f"/usr/share/{app_name.lower()}"
|
||||||
self._USR_CONFIG_FILE = f"{self._USR_PATH}/settings.json"
|
self._USR_CONFIG_FILE = f"{self._USR_PATH}/settings.json"
|
||||||
|
@ -55,34 +58,34 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
# with io.TextIOWrapper(zf.open("text1.txt"), encoding="utf-8") as f:
|
# with io.TextIOWrapper(zf.open("text1.txt"), encoding="utf-8") as f:
|
||||||
|
|
||||||
|
|
||||||
if not os.path.exists(self._HOME_CONFIG_PATH):
|
if not path.exists(self._HOME_CONFIG_PATH):
|
||||||
os.mkdir(self._HOME_CONFIG_PATH)
|
mkdir(self._HOME_CONFIG_PATH)
|
||||||
if not os.path.exists(self._PLUGINS_PATH):
|
if not path.exists(self._PLUGINS_PATH):
|
||||||
os.mkdir(self._PLUGINS_PATH)
|
mkdir(self._PLUGINS_PATH)
|
||||||
|
|
||||||
if not os.path.exists(self._DEFAULT_ICONS):
|
if not path.exists(self._DEFAULT_ICONS):
|
||||||
self._DEFAULT_ICONS = f"{self._USR_PATH}/icons"
|
self._DEFAULT_ICONS = f"{self._USR_PATH}/icons"
|
||||||
if not os.path.exists(self._DEFAULT_ICONS):
|
if not path.exists(self._DEFAULT_ICONS):
|
||||||
raise MissingConfigError("Unable to find the application icons directory.")
|
raise MissingConfigError("Unable to find the application icons directory.")
|
||||||
if not os.path.exists(self._GLADE_FILE):
|
if not path.exists(self._GLADE_FILE):
|
||||||
self._GLADE_FILE = f"{self._USR_PATH}/Main_Window.glade"
|
self._GLADE_FILE = f"{self._USR_PATH}/Main_Window.glade"
|
||||||
if not os.path.exists(self._GLADE_FILE):
|
if not path.exists(self._GLADE_FILE):
|
||||||
raise MissingConfigError("Unable to find the application Glade file.")
|
raise MissingConfigError("Unable to find the application Glade file.")
|
||||||
if not os.path.exists(self._KEY_BINDINGS_FILE):
|
if not path.exists(self._KEY_BINDINGS_FILE):
|
||||||
self._KEY_BINDINGS_FILE = f"{self._USR_PATH}/key-bindings.json"
|
self._KEY_BINDINGS_FILE = f"{self._USR_PATH}/key-bindings.json"
|
||||||
if not os.path.exists(self._KEY_BINDINGS_FILE):
|
if not path.exists(self._KEY_BINDINGS_FILE):
|
||||||
raise MissingConfigError("Unable to find the application Keybindings file.")
|
raise MissingConfigError("Unable to find the application Keybindings file.")
|
||||||
if not os.path.exists(self._CSS_FILE):
|
if not path.exists(self._CSS_FILE):
|
||||||
self._CSS_FILE = f"{self._USR_PATH}/stylesheet.css"
|
self._CSS_FILE = f"{self._USR_PATH}/stylesheet.css"
|
||||||
if not os.path.exists(self._CSS_FILE):
|
if not path.exists(self._CSS_FILE):
|
||||||
raise MissingConfigError("Unable to find the application Stylesheet file.")
|
raise MissingConfigError("Unable to find the application Stylesheet file.")
|
||||||
if not os.path.exists(self._WINDOW_ICON):
|
if not path.exists(self._WINDOW_ICON):
|
||||||
self._WINDOW_ICON = f"{self._USR_PATH}/icons/{app_name.lower()}.png"
|
self._WINDOW_ICON = f"{self._USR_PATH}/icons/{app_name.lower()}.png"
|
||||||
if not os.path.exists(self._WINDOW_ICON):
|
if not path.exists(self._WINDOW_ICON):
|
||||||
raise MissingConfigError("Unable to find the application icon.")
|
raise MissingConfigError("Unable to find the application icon.")
|
||||||
if not os.path.exists(self._UI_WIDEGTS_PATH):
|
if not path.exists(self._UI_WIDEGTS_PATH):
|
||||||
self._UI_WIDEGTS_PATH = f"{self._USR_PATH}/ui_widgets"
|
self._UI_WIDEGTS_PATH = f"{self._USR_PATH}/ui_widgets"
|
||||||
if not os.path.exists(self._CONTEXT_MENU):
|
if not path.exists(self._CONTEXT_MENU):
|
||||||
self._CONTEXT_MENU = f"{self._USR_PATH}/contexct_menu.json"
|
self._CONTEXT_MENU = f"{self._USR_PATH}/contexct_menu.json"
|
||||||
|
|
||||||
|
|
||||||
|
@ -109,8 +112,6 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
self._debug = False
|
self._debug = False
|
||||||
self._dirty_start = False
|
self._dirty_start = False
|
||||||
|
|
||||||
self.load_settings()
|
|
||||||
|
|
||||||
|
|
||||||
def register_signals_to_builder(self, classes=None):
|
def register_signals_to_builder(self, classes=None):
|
||||||
handlers = {}
|
handlers = {}
|
||||||
|
@ -155,6 +156,11 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
def is_trace_debug(self) -> str: return self._trace_debug
|
def is_trace_debug(self) -> str: return self._trace_debug
|
||||||
def is_debug(self) -> str: return self._debug
|
def is_debug(self) -> str: return self._debug
|
||||||
|
|
||||||
|
def call_method(self, target_class = None, _method_name = None, data = None):
|
||||||
|
method_name = str(_method_name)
|
||||||
|
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()
|
||||||
|
|
||||||
def set_main_window_x(self, x = 0): self.settings.config.window_x = x
|
def set_main_window_x(self, x = 0): self.settings.config.window_x = x
|
||||||
def set_main_window_y(self, y = 0): self.settings.config.window_y = y
|
def set_main_window_y(self, y = 0): self.settings.config.window_y = y
|
||||||
def set_main_window_width(self, width = 800): self.settings.config.window_width = width
|
def set_main_window_width(self, width = 800): self.settings.config.window_width = width
|
||||||
|
@ -170,7 +176,7 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
|
|
||||||
|
|
||||||
def load_settings(self):
|
def load_settings(self):
|
||||||
if not os.path.exists(self._CONFIG_FILE):
|
if not path.exists(self._CONFIG_FILE):
|
||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|
|
@ -33,3 +33,7 @@ class Config:
|
||||||
main_window_min_height: int = 480
|
main_window_min_height: int = 480
|
||||||
main_window_width: int = 800
|
main_window_width: int = 800
|
||||||
main_window_height: int = 600
|
main_window_height: int = 600
|
||||||
|
application_dirs: list = field(default_factory=lambda: [
|
||||||
|
"/usr/share/applications",
|
||||||
|
f"{settings_manager.get_home_path()}/.local/share/applications"
|
||||||
|
])
|
||||||
|
|
Loading…
Reference in New Issue