Restructured settings logic and loading
This commit is contained in:
@@ -19,12 +19,29 @@ def debug_signal_handler(signal, frame):
|
||||
rpdb2.setbreak(depth=1)
|
||||
return
|
||||
except StandardError:
|
||||
pass
|
||||
...
|
||||
|
||||
try:
|
||||
from rfoo.utils import rconsole
|
||||
logger.debug("\n\nStarting embedded rconsole debugger...\n\n")
|
||||
rconsole.spawn_server()
|
||||
return
|
||||
except StandardError as ex:
|
||||
...
|
||||
|
||||
try:
|
||||
from pudb import set_trace
|
||||
logger.debug("\n\nStarting PuDB debugger...\n\n")
|
||||
set_trace(paused = True)
|
||||
return
|
||||
except StandardError as ex:
|
||||
...
|
||||
|
||||
try:
|
||||
import pdb
|
||||
logger.debug("\n\nStarting embedded PDB debugger...\n\n")
|
||||
pdb.Pdb(skip=['gi.*']).set_trace()
|
||||
return
|
||||
except StandardError as ex:
|
||||
...
|
||||
|
||||
|
@@ -40,7 +40,7 @@ class IPCServer(Singleton):
|
||||
|
||||
def create_ipc_listener(self) -> None:
|
||||
if self._conn_type == "socket":
|
||||
if os.path.exists(self._ipc_address) and settings.is_dirty_start():
|
||||
if os.path.exists(self._ipc_address) and settings_manager.is_dirty_start():
|
||||
os.unlink(self._ipc_address)
|
||||
|
||||
listener = Listener(address=self._ipc_address, family="AF_UNIX", authkey=self._ipc_authkey)
|
||||
@@ -69,7 +69,7 @@ class IPCServer(Singleton):
|
||||
def _handle_ipc_message(self, conn, start_time) -> None:
|
||||
while True:
|
||||
msg = conn.recv()
|
||||
if settings.is_debug():
|
||||
if settings_manager.is_debug():
|
||||
print(msg)
|
||||
|
||||
if "FILE|" in msg:
|
||||
|
@@ -1,4 +0,0 @@
|
||||
"""
|
||||
Settings module
|
||||
"""
|
||||
from .settings import Settings
|
4
src/utils/settings_manager/__init__.py
Normal file
4
src/utils/settings_manager/__init__.py
Normal file
@@ -0,0 +1,4 @@
|
||||
"""
|
||||
Settings module
|
||||
"""
|
||||
from .manager import SettingsManager
|
@@ -4,12 +4,15 @@ import io
|
||||
import json
|
||||
import inspect
|
||||
import zipfile
|
||||
from dataclasses import asdict
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
from ..singleton import Singleton
|
||||
from .start_check_mixin import StartCheckMixin
|
||||
from .options.settings import Settings
|
||||
|
||||
|
||||
|
||||
class MissingConfigError(Exception):
|
||||
@@ -17,7 +20,7 @@ class MissingConfigError(Exception):
|
||||
|
||||
|
||||
|
||||
class Settings(StartCheckMixin, Singleton):
|
||||
class SettingsManager(StartCheckMixin, Singleton):
|
||||
def __init__(self):
|
||||
self._SCRIPT_PTH = os.path.dirname(os.path.realpath(__file__))
|
||||
self._USER_HOME = os.path.expanduser('~')
|
||||
@@ -105,18 +108,14 @@ class Settings(StartCheckMixin, Singleton):
|
||||
print( f"Settings: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
|
||||
|
||||
|
||||
self._main_window = None
|
||||
self._main_window_w = 800
|
||||
self._main_window_h = 600
|
||||
self._main_window_mw = 720
|
||||
self._main_window_mh = 480
|
||||
self.settings: Settings = None
|
||||
self._main_window = None
|
||||
self._builder = None
|
||||
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
|
||||
|
||||
self._builder = None
|
||||
self.PAINT_BG_COLOR = (0, 0, 0, 0.54)
|
||||
|
||||
self._trace_debug = False
|
||||
self._debug = False
|
||||
self._dirty_start = False
|
||||
self._trace_debug = False
|
||||
self._debug = False
|
||||
self._dirty_start = False
|
||||
|
||||
self.load_settings()
|
||||
|
||||
@@ -148,10 +147,6 @@ class Settings(StartCheckMixin, Singleton):
|
||||
return monitors
|
||||
|
||||
def get_main_window(self) -> any: return self._main_window
|
||||
def get_main_window_width(self) -> any: return self._main_window_w
|
||||
def get_main_window_height(self) -> any: return self._main_window_h
|
||||
def get_main_window_min_width(self) -> any: return self._main_window_mw
|
||||
def get_main_window_min_height(self) -> any: return self._main_window_mh
|
||||
def get_builder(self) -> any: return self._builder
|
||||
def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR
|
||||
def get_glade_file(self) -> str: return self._GLADE_FILE
|
||||
@@ -164,25 +159,16 @@ class Settings(StartCheckMixin, Singleton):
|
||||
def get_home_config_path(self) -> str: return self._HOME_CONFIG_PATH
|
||||
def get_window_icon(self) -> str: return self._WINDOW_ICON
|
||||
def get_home_path(self) -> str: return self._USER_HOME
|
||||
def make_transparent(self) -> int: return self._config["make_transparent"]
|
||||
|
||||
# Filter returns
|
||||
def get_office_filter(self) -> tuple: return tuple(self._settings["filters"]["office"])
|
||||
def get_vids_filter(self) -> tuple: return tuple(self._settings["filters"]["videos"])
|
||||
def get_text_filter(self) -> tuple: return tuple(self._settings["filters"]["text"])
|
||||
def get_music_filter(self) -> tuple: return tuple(self._settings["filters"]["music"])
|
||||
def get_images_filter(self) -> tuple: return tuple(self._settings["filters"]["images"])
|
||||
def get_pdf_filter(self) -> tuple: return tuple(self._settings["filters"]["pdf"])
|
||||
|
||||
def get_success_color(self) -> str: return self._theming["success_color"]
|
||||
def get_warning_color(self) -> str: return self._theming["warning_color"]
|
||||
def get_error_color(self) -> str: return self._theming["error_color"]
|
||||
|
||||
def is_trace_debug(self) -> str: return self._trace_debug
|
||||
def is_debug(self) -> str: return self._debug
|
||||
|
||||
def get_ch_log_lvl(self) -> str: return self._settings["debugging"]["ch_log_lvl"]
|
||||
def get_fh_log_lvl(self) -> str: return self._settings["debugging"]["fh_log_lvl"]
|
||||
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_width(self, width = 800): self.settings.config.window_width = width
|
||||
def set_main_window_height(self, height = 600): self.settings.config.window_height = height
|
||||
def set_main_window_min_width(self, width = 720): self.settings.config.window_min_width = width
|
||||
def set_main_window_min_height(self, height = 480): self.settings.config.window_min_height = height
|
||||
|
||||
def set_trace_debug(self, trace_debug):
|
||||
self._trace_debug = trace_debug
|
||||
@@ -192,11 +178,10 @@ class Settings(StartCheckMixin, Singleton):
|
||||
|
||||
|
||||
def load_settings(self):
|
||||
with open(self._CONFIG_FILE) as f:
|
||||
self._settings = json.load(f)
|
||||
self._config = self._settings["config"]
|
||||
self._theming = self._settings["theming"]
|
||||
with open(self._CONFIG_FILE) as file:
|
||||
data = json.load(file)
|
||||
self.settings = Settings(**data)
|
||||
|
||||
def save_settings(self):
|
||||
with open(self._CONFIG_FILE, 'w') as outfile:
|
||||
json.dump(self._settings, outfile, separators=(',', ':'), indent=4)
|
||||
json.dump(asdict(self.settings), outfile, separators=(',', ':'), indent=4)
|
8
src/utils/settings_manager/options/__init__.py
Normal file
8
src/utils/settings_manager/options/__init__.py
Normal file
@@ -0,0 +1,8 @@
|
||||
"""
|
||||
Options module
|
||||
"""
|
||||
from .settings import Settings
|
||||
from .config import Config
|
||||
from .filters import Filters
|
||||
from .theming import Theming
|
||||
from .debugging import Debugging
|
35
src/utils/settings_manager/options/config.py
Normal file
35
src/utils/settings_manager/options/config.py
Normal file
@@ -0,0 +1,35 @@
|
||||
# Python imports
|
||||
from dataclasses import dataclass
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
@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: []
|
||||
mplayer_options: str
|
||||
music_app: str
|
||||
media_app: str
|
||||
image_app: str
|
||||
office_app: str
|
||||
pdf_app: str
|
||||
code_app: str
|
||||
text_app: str
|
||||
file_manager_app: str
|
||||
terminal_app: str
|
||||
remux_folder_max_disk_usage: str
|
||||
make_transparent: int
|
||||
main_window_x: int
|
||||
main_window_y: int
|
||||
main_window_min_width: int
|
||||
main_window_min_height: int
|
||||
main_window_width: int
|
||||
main_window_height: int
|
12
src/utils/settings_manager/options/debugging.py
Normal file
12
src/utils/settings_manager/options/debugging.py
Normal file
@@ -0,0 +1,12 @@
|
||||
# Python imports
|
||||
from dataclasses import dataclass
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
@dataclass
|
||||
class Debugging:
|
||||
ch_log_lvl: int
|
||||
fh_log_lvl: int
|
18
src/utils/settings_manager/options/filters.py
Normal file
18
src/utils/settings_manager/options/filters.py
Normal file
@@ -0,0 +1,18 @@
|
||||
# Python imports
|
||||
from dataclasses import dataclass
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
@dataclass
|
||||
class Filters:
|
||||
meshs: []
|
||||
code: []
|
||||
videos: []
|
||||
office: []
|
||||
images: []
|
||||
text: []
|
||||
music: []
|
||||
pdf: []
|
24
src/utils/settings_manager/options/settings.py
Normal file
24
src/utils/settings_manager/options/settings.py
Normal file
@@ -0,0 +1,24 @@
|
||||
# Python imports
|
||||
from dataclasses import dataclass
|
||||
|
||||
# Gtk imports
|
||||
|
||||
# Application imports
|
||||
from .config import Config
|
||||
from .filters import Filters
|
||||
from .theming import Theming
|
||||
from .debugging import Debugging
|
||||
|
||||
|
||||
@dataclass
|
||||
class Settings:
|
||||
config: Config
|
||||
filters: Filters
|
||||
theming: Theming
|
||||
debugging: 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)
|
13
src/utils/settings_manager/options/theming.py
Normal file
13
src/utils/settings_manager/options/theming.py
Normal file
@@ -0,0 +1,13 @@
|
||||
# Python imports
|
||||
from dataclasses import dataclass
|
||||
|
||||
# Lib imports
|
||||
|
||||
# Application imports
|
||||
|
||||
|
||||
@dataclass
|
||||
class Theming:
|
||||
success_color: str
|
||||
warning_color: str
|
||||
error_color: str
|
@@ -41,6 +41,7 @@ class StartCheckMixin:
|
||||
def _write_new_pid(self):
|
||||
pid = os.getpid()
|
||||
self._write_pid(pid)
|
||||
print(f"{app_name} PID: {pid}")
|
||||
|
||||
def _clean_pid(self):
|
||||
os.unlink(self._PID_FILE)
|
Reference in New Issue
Block a user