Created a settings > path_manager class and cleaned up srtting manager class
This commit is contained in:
@@ -58,7 +58,7 @@ builtins.settings_manager = SettingsManager()
|
|||||||
settings_manager.load_settings()
|
settings_manager.load_settings()
|
||||||
|
|
||||||
builtins.logger = Logger(
|
builtins.logger = Logger(
|
||||||
settings_manager.get_home_config_path(), \
|
settings_manager.path_manager.get_home_config_path(), \
|
||||||
_ch_log_lvl = settings_manager.settings.debugging.ch_log_lvl, \
|
_ch_log_lvl = settings_manager.settings.debugging.ch_log_lvl, \
|
||||||
_fh_log_lvl = settings_manager.settings.debugging.fh_log_lvl
|
_fh_log_lvl = settings_manager.settings.debugging.fh_log_lvl
|
||||||
).get_logger()
|
).get_logger()
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
|
|||||||
logger.debug("_tggl_top_main_menubar > stub...")
|
logger.debug("_tggl_top_main_menubar > stub...")
|
||||||
|
|
||||||
def _load_glade_file(self):
|
def _load_glade_file(self):
|
||||||
self.builder.add_from_file( settings_manager.get_glade_file() )
|
self.builder.add_from_file( settings_manager.path_manager.get_glade_file() )
|
||||||
self.builder.expose_object("main_window", self.window)
|
self.builder.expose_object("main_window", self.window)
|
||||||
|
|
||||||
settings_manager.set_builder(self.builder)
|
settings_manager.set_builder(self.builder)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ class KeyMapper:
|
|||||||
|
|
||||||
def load_map(self):
|
def load_map(self):
|
||||||
self.states = copy.deepcopy(self._map)
|
self.states = copy.deepcopy(self._map)
|
||||||
bindings_file = f"{settings_manager.get_home_config_path()}/code-key-bindings.json"
|
bindings_file = f"{settings_manager.path_manager.get_home_config_path()}/code-key-bindings.json"
|
||||||
|
|
||||||
with open(bindings_file, 'r') as f:
|
with open(bindings_file, 'r') as f:
|
||||||
data = json.load(f)["keybindings"]
|
data = json.load(f)["keybindings"]
|
||||||
|
|||||||
@@ -98,7 +98,7 @@ class SourceView(GtkSource.View, ObservableMixin, SourceViewEventsMixin, SourceV
|
|||||||
self.completion.set_completer( self.get_completion() )
|
self.completion.set_completer( self.get_completion() )
|
||||||
|
|
||||||
self.style_scheme_manager.append_search_path(
|
self.style_scheme_manager.append_search_path(
|
||||||
f"{settings_manager.get_home_config_path()}/code_styles"
|
f"{settings_manager.path_manager.get_home_config_path()}/code_styles"
|
||||||
)
|
)
|
||||||
self.syntax_theme = self.style_scheme_manager.get_scheme(
|
self.syntax_theme = self.style_scheme_manager.get_scheme(
|
||||||
f"{settings_manager.settings.theming.syntax_theme}"
|
f"{settings_manager.settings.theming.syntax_theme}"
|
||||||
|
|||||||
@@ -61,7 +61,7 @@ class VteWidget(Vte.Terminal):
|
|||||||
def _do_session_spawn(self):
|
def _do_session_spawn(self):
|
||||||
self.spawn_sync(
|
self.spawn_sync(
|
||||||
Vte.PtyFlags.DEFAULT,
|
Vte.PtyFlags.DEFAULT,
|
||||||
settings_manager.get_home_path(),
|
settings_manager.path_manager.get_home_path(),
|
||||||
["/bin/bash"],
|
["/bin/bash"],
|
||||||
[],
|
[],
|
||||||
GLib.SpawnFlags.DEFAULT,
|
GLib.SpawnFlags.DEFAULT,
|
||||||
@@ -76,8 +76,8 @@ class VteWidget(Vte.Terminal):
|
|||||||
"export LC_ALL=C\n",
|
"export LC_ALL=C\n",
|
||||||
"export XDG_RUNTIME_DIR='/run/user/1000'\n",
|
"export XDG_RUNTIME_DIR='/run/user/1000'\n",
|
||||||
"export DISPLAY=:0\n",
|
"export DISPLAY=:0\n",
|
||||||
f"export XAUTHORITY='{settings_manager.get_home_path()}/.Xauthority'\n",
|
f"export XAUTHORITY='{settings_manager.path_manager.get_home_path()}/.Xauthority'\n",
|
||||||
f"\nexport HOME='{settings_manager.get_home_path()}'\n",
|
f"\nexport HOME='{settings_manager.path_manager.get_home_path()}'\n",
|
||||||
"export PS1='\\h@\\u \\W -->: '\n",
|
"export PS1='\\h@\\u \\W -->: '\n",
|
||||||
"clear\n"
|
"clear\n"
|
||||||
]
|
]
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ class WebkitUI(WebKit2.WebView):
|
|||||||
self.set_settings( WebkitUISettings() )
|
self.set_settings( WebkitUISettings() )
|
||||||
|
|
||||||
def _load_view(self):
|
def _load_view(self):
|
||||||
path = settings_manager.get_context_path()
|
path = settings_manager.path_manager.get_context_path()
|
||||||
data = None
|
data = None
|
||||||
|
|
||||||
with open(f"{path}/index.html", "r") as f:
|
with open(f"{path}/index.html", "r") as f:
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ class Window(Gtk.ApplicationWindow):
|
|||||||
|
|
||||||
def _setup_styling(self):
|
def _setup_styling(self):
|
||||||
self.set_title(f"{APP_NAME}")
|
self.set_title(f"{APP_NAME}")
|
||||||
self.set_icon_from_file( settings_manager.get_window_icon() )
|
self.set_icon_from_file( settings_manager.path_manager.get_window_icon() )
|
||||||
self.set_decorated(True)
|
self.set_decorated(True)
|
||||||
self.set_skip_pager_hint(False)
|
self.set_skip_pager_hint(False)
|
||||||
self.set_skip_taskbar_hint(False)
|
self.set_skip_taskbar_hint(False)
|
||||||
@@ -119,7 +119,7 @@ class Window(Gtk.ApplicationWindow):
|
|||||||
# bind css file
|
# bind css file
|
||||||
cssProvider = Gtk.CssProvider()
|
cssProvider = Gtk.CssProvider()
|
||||||
styleContext = Gtk.StyleContext()
|
styleContext = Gtk.StyleContext()
|
||||||
cssProvider.load_from_path( settings_manager.get_css_file() )
|
cssProvider.load_from_path( settings_manager.path_manager.get_css_file() )
|
||||||
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
styleContext.add_provider_for_screen(screen, cssProvider, Gtk.STYLE_PROVIDER_PRIORITY_USER)
|
||||||
|
|
||||||
def _area_draw(self, widget: Gtk.ApplicationWindow, cr: cairo.Context) -> None:
|
def _area_draw(self, widget: Gtk.ApplicationWindow, cr: cairo.Context) -> None:
|
||||||
|
|||||||
@@ -1,138 +1,38 @@
|
|||||||
# Python imports
|
# Python imports
|
||||||
import inspect
|
import inspect
|
||||||
import time
|
import time
|
||||||
import json
|
|
||||||
import zipfile
|
|
||||||
|
|
||||||
from os import path
|
|
||||||
from os import mkdir
|
|
||||||
|
|
||||||
# Lib imports
|
# Lib imports
|
||||||
|
|
||||||
# Application imports
|
# Application imports
|
||||||
from ..singleton import Singleton
|
from ..singleton import Singleton
|
||||||
from .start_check_mixin import StartCheckMixin
|
from .start_check_mixin import StartCheckMixin
|
||||||
|
|
||||||
|
from .path_manager import PathManager
|
||||||
from .options.settings import Settings
|
from .options.settings import Settings
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class MissingConfigError(Exception):
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class SettingsManager(StartCheckMixin, Singleton):
|
class SettingsManager(StartCheckMixin, Singleton):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self._SCRIPT_PTH: str = path.dirname(path.realpath(__file__))
|
self.path_manager: PathManager = PathManager()
|
||||||
self._USER_HOME: str = path.expanduser('~')
|
self.settings: Settings = None
|
||||||
self._HOME_CONFIG_PATH: str = f"{self._USER_HOME}/.config/{APP_NAME.lower()}"
|
|
||||||
self._USR_PATH: str = f"/usr/share/{APP_NAME.lower()}"
|
|
||||||
self._USR_CONFIG_FILE: str = f"{self._USR_PATH}/settings.json"
|
|
||||||
|
|
||||||
self._CONTEXT_PATH: str = f"{self._HOME_CONFIG_PATH}/context_path"
|
self._main_window = None
|
||||||
self._PLUGINS_PATH: str = f"{self._HOME_CONFIG_PATH}/plugins"
|
self._builder = None
|
||||||
self._DEFAULT_ICONS: str = f"{self._HOME_CONFIG_PATH}/icons"
|
|
||||||
self._CONFIG_FILE: str = f"{self._HOME_CONFIG_PATH}/settings.json"
|
|
||||||
self._GLADE_FILE: str = f"{self._HOME_CONFIG_PATH}/Main_Window.glade"
|
|
||||||
self._CSS_FILE: str = f"{self._HOME_CONFIG_PATH}/stylesheet.css"
|
|
||||||
self._KEY_BINDINGS_FILE: str = f"{self._HOME_CONFIG_PATH}/key-bindings.json"
|
|
||||||
self._PID_FILE: str = f"{self._HOME_CONFIG_PATH}/{APP_NAME.lower()}.pid"
|
|
||||||
self._UI_WIDEGTS_PATH: str = f"{self._HOME_CONFIG_PATH}/ui_widgets"
|
|
||||||
self._CONTEXT_MENU: str = f"{self._HOME_CONFIG_PATH}/contexct_menu.json"
|
|
||||||
self._WINDOW_ICON: str = f"{self._DEFAULT_ICONS}/{APP_NAME.lower()}.png"
|
|
||||||
|
|
||||||
# self._USR_CONFIG_FILE: str = f"{self._USR_PATH}/settings.json"
|
self._trace_debug: bool = False
|
||||||
# self._PLUGINS_PATH: str = f"plugins"
|
self._debug: bool = False
|
||||||
# self._CONFIG_FILE: str = f"settings.json"
|
self._dirty_start: bool = False
|
||||||
# self._GLADE_FILE: str = f"Main_Window.glade"
|
self._passed_in_file: bool = False
|
||||||
# self._CSS_FILE: str = f"stylesheet.css"
|
self._starting_files: list = []
|
||||||
# self._KEY_BINDINGS_FILE: str = f"key-bindings.json"
|
|
||||||
# self._PID_FILE: str = f"{APP_NAME.lower()}.pid"
|
|
||||||
# self._WINDOW_ICON: str = f"{APP_NAME.lower()}.png"
|
|
||||||
# self._UI_WIDEGTS_PATH: str = f"ui_widgets"
|
|
||||||
# self._CONTEXT_MENU: str = f"contexct_menu.json"
|
|
||||||
# self._DEFAULT_ICONS: str = f"icons"
|
|
||||||
|
|
||||||
|
self.PAINT_BG_COLOR: tuple = (0, 0, 0, 0.0)
|
||||||
|
|
||||||
# with zipfile.ZipFile("files.zip", mode="r", allowZip64=True) as zf:
|
self.load_keybindings()
|
||||||
# with io.TextIOWrapper(zf.open("text1.txt"), encoding="utf-8") as f:
|
self.load_context_menu_data()
|
||||||
|
|
||||||
|
|
||||||
if not path.exists(self._HOME_CONFIG_PATH):
|
|
||||||
mkdir(self._HOME_CONFIG_PATH)
|
|
||||||
if not path.exists(self._PLUGINS_PATH):
|
|
||||||
mkdir(self._PLUGINS_PATH)
|
|
||||||
|
|
||||||
if not path.exists(self._DEFAULT_ICONS):
|
|
||||||
self._DEFAULT_ICONS = f"{self._USR_PATH}/icons"
|
|
||||||
if not path.exists(self._DEFAULT_ICONS):
|
|
||||||
raise MissingConfigError("Unable to find the application icons directory.")
|
|
||||||
if not path.exists(self._GLADE_FILE):
|
|
||||||
self._GLADE_FILE = f"{self._USR_PATH}/Main_Window.glade"
|
|
||||||
if not path.exists(self._GLADE_FILE):
|
|
||||||
raise MissingConfigError("Unable to find the application Glade file.")
|
|
||||||
if not path.exists(self._KEY_BINDINGS_FILE):
|
|
||||||
self._KEY_BINDINGS_FILE = f"{self._USR_PATH}/key-bindings.json"
|
|
||||||
if not path.exists(self._KEY_BINDINGS_FILE):
|
|
||||||
raise MissingConfigError("Unable to find the application Keybindings file.")
|
|
||||||
if not path.exists(self._CSS_FILE):
|
|
||||||
self._CSS_FILE = f"{self._USR_PATH}/stylesheet.css"
|
|
||||||
if not path.exists(self._CSS_FILE):
|
|
||||||
raise MissingConfigError("Unable to find the application Stylesheet file.")
|
|
||||||
if not path.exists(self._WINDOW_ICON):
|
|
||||||
self._WINDOW_ICON = f"{self._USR_PATH}/icons/{APP_NAME.lower()}.png"
|
|
||||||
if not path.exists(self._WINDOW_ICON):
|
|
||||||
raise MissingConfigError("Unable to find the application icon.")
|
|
||||||
if not path.exists(self._UI_WIDEGTS_PATH):
|
|
||||||
self._UI_WIDEGTS_PATH = f"{self._USR_PATH}/ui_widgets"
|
|
||||||
if not path.exists(self._CONTEXT_MENU):
|
|
||||||
self._CONTEXT_MENU = f"{self._USR_PATH}/contexct_menu.json"
|
|
||||||
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(self._KEY_BINDINGS_FILE) as file:
|
|
||||||
bindings = json.load(file)["keybindings"]
|
|
||||||
self._guake_key = bindings["guake_key"]
|
|
||||||
|
|
||||||
keybindings.configure(bindings)
|
|
||||||
except Exception as e:
|
|
||||||
print( f"Settings Manager: {self._KEY_BINDINGS_FILE}\n\t\t{repr(e)}" )
|
|
||||||
|
|
||||||
try:
|
|
||||||
with open(self._CONTEXT_MENU) as file:
|
|
||||||
self._context_menu_data = json.load(file)
|
|
||||||
except Exception as e:
|
|
||||||
print( f"Settings Manager: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
|
|
||||||
|
|
||||||
|
|
||||||
self.settings: Settings = None
|
|
||||||
self._main_window = None
|
|
||||||
self._builder = None
|
|
||||||
self.PAINT_BG_COLOR: tuple = (0, 0, 0, 0.0)
|
|
||||||
|
|
||||||
self._trace_debug: bool = False
|
|
||||||
self._debug: bool = False
|
|
||||||
self._dirty_start: bool = False
|
|
||||||
self._passed_in_file: bool = False
|
|
||||||
self._starting_files: list = []
|
|
||||||
|
|
||||||
|
|
||||||
def register_signals_to_builder(self, classes = None):
|
|
||||||
handlers = {}
|
|
||||||
|
|
||||||
for c in classes:
|
|
||||||
methods = None
|
|
||||||
try:
|
|
||||||
methods = inspect.getmembers(c, predicate = inspect.ismethod)
|
|
||||||
handlers.update(methods)
|
|
||||||
except Exception as e:
|
|
||||||
...
|
|
||||||
|
|
||||||
self._builder.connect_signals(handlers)
|
|
||||||
|
|
||||||
def set_main_window(self, window): self._main_window = window
|
|
||||||
def set_builder(self, builder) -> any: self._builder = builder
|
|
||||||
|
|
||||||
def get_monitor_data(self) -> list:
|
def get_monitor_data(self) -> list:
|
||||||
screen = self._main_window.get_screen()
|
screen = self._main_window.get_screen()
|
||||||
monitors = []
|
monitors = []
|
||||||
@@ -145,23 +45,18 @@ class SettingsManager(StartCheckMixin, Singleton):
|
|||||||
def get_main_window(self) -> any: return self._main_window
|
def get_main_window(self) -> any: return self._main_window
|
||||||
def get_builder(self) -> any: return self._builder
|
def get_builder(self) -> any: return self._builder
|
||||||
def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR
|
def get_paint_bg_color(self) -> any: return self.PAINT_BG_COLOR
|
||||||
def get_glade_file(self) -> str: return self._GLADE_FILE
|
|
||||||
def get_ui_widgets_path(self) -> str: return self._UI_WIDEGTS_PATH
|
|
||||||
def get_context_menu_data(self) -> str: return self._context_menu_data
|
def get_context_menu_data(self) -> str: return self._context_menu_data
|
||||||
|
|
||||||
def get_context_path(self) -> str: return self._CONTEXT_PATH
|
|
||||||
def get_plugins_path(self) -> str: return self._PLUGINS_PATH
|
|
||||||
def get_icon_theme(self) -> str: return self._ICON_THEME
|
def get_icon_theme(self) -> str: return self._ICON_THEME
|
||||||
def get_css_file(self) -> str: return self._CSS_FILE
|
|
||||||
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 get_starting_files(self) -> list: return self._starting_files
|
def get_starting_files(self) -> list: return self._starting_files
|
||||||
def get_guake_key(self) -> tuple: return self._guake_key
|
def get_guake_key(self) -> tuple: return self._guake_key
|
||||||
|
|
||||||
def get_starting_args(self):
|
def get_starting_args(self):
|
||||||
return self.args, self.unknownargs
|
return self.args, self.unknownargs
|
||||||
|
|
||||||
|
def set_main_window(self, window): self._main_window = window
|
||||||
|
def set_builder(self, builder) -> any: self._builder = builder
|
||||||
|
|
||||||
def set_main_window_x(self, x: int = 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: int = 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: int = 800): self.settings.config.main_window_width = width
|
def set_main_window_width(self, width: int = 800): self.settings.config.main_window_width = width
|
||||||
@@ -191,21 +86,41 @@ class SettingsManager(StartCheckMixin, Singleton):
|
|||||||
|
|
||||||
def log_load_time(self): logger.info( f"Load Time: {self._end_load_time - self._start_load_time}" )
|
def log_load_time(self): logger.info( f"Load Time: {self._end_load_time - self._start_load_time}" )
|
||||||
|
|
||||||
|
|
||||||
|
def register_signals_to_builder(self, classes = None):
|
||||||
|
handlers = {}
|
||||||
|
|
||||||
|
for c in classes:
|
||||||
|
methods = None
|
||||||
|
try:
|
||||||
|
methods = inspect.getmembers(c, predicate = inspect.ismethod)
|
||||||
|
handlers.update(methods)
|
||||||
|
except Exception as e:
|
||||||
|
...
|
||||||
|
|
||||||
|
self._builder.connect_signals(handlers)
|
||||||
|
|
||||||
def call_method(self, target_class: any = None, _method_name: str = "", data: any = 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 load_keybindings(self):
|
||||||
|
bindings = self.path_manager.load_keybindings()
|
||||||
|
self._guake_key = bindings["guake_key"]
|
||||||
|
|
||||||
|
keybindings.configure(bindings)
|
||||||
|
|
||||||
|
def load_context_menu_data(self):
|
||||||
|
self._context_menu_data = self.path_manager.load_context_menu_data()
|
||||||
|
|
||||||
def load_settings(self):
|
def load_settings(self):
|
||||||
if not path.exists(self._CONFIG_FILE):
|
data = self.path_manager.load_settings()
|
||||||
|
if not data:
|
||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
return
|
return
|
||||||
|
|
||||||
with open(self._CONFIG_FILE) as file:
|
self.settings = Settings(**data)
|
||||||
data = json.load(file)
|
|
||||||
data["load_defaults"] = False
|
|
||||||
self.settings = Settings(**data)
|
|
||||||
|
|
||||||
def save_settings(self):
|
def save_settings(self):
|
||||||
with open(self._CONFIG_FILE, 'w') as outfile:
|
self.path_manager.save_settings(self.settings)
|
||||||
json.dump(self.settings.as_dict(), outfile, separators=(',', ':'), indent=4)
|
|
||||||
|
|||||||
123
src/libs/settings/path_manager.py
Normal file
123
src/libs/settings/path_manager.py
Normal file
@@ -0,0 +1,123 @@
|
|||||||
|
# Python imports
|
||||||
|
import json
|
||||||
|
import zipfile
|
||||||
|
|
||||||
|
from os import path
|
||||||
|
from os import mkdir
|
||||||
|
|
||||||
|
# Lib imports
|
||||||
|
|
||||||
|
# Application imports
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class MissingConfigError(Exception):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
class PathManager:
|
||||||
|
def __init__(self):
|
||||||
|
self._SCRIPT_PTH: str = path.dirname(path.realpath(__file__))
|
||||||
|
self._USER_HOME: str = path.expanduser('~')
|
||||||
|
self._HOME_CONFIG_PATH: str = f"{self._USER_HOME}/.config/{APP_NAME.lower()}"
|
||||||
|
self._USR_PATH: str = f"/usr/share/{APP_NAME.lower()}"
|
||||||
|
self._USR_CONFIG_FILE: str = f"{self._USR_PATH}/settings.json"
|
||||||
|
|
||||||
|
self._CONTEXT_PATH: str = f"{self._HOME_CONFIG_PATH}/context_path"
|
||||||
|
self._PLUGINS_PATH: str = f"{self._HOME_CONFIG_PATH}/plugins"
|
||||||
|
self._DEFAULT_ICONS: str = f"{self._HOME_CONFIG_PATH}/icons"
|
||||||
|
self._CONFIG_FILE: str = f"{self._HOME_CONFIG_PATH}/settings.json"
|
||||||
|
self._GLADE_FILE: str = f"{self._HOME_CONFIG_PATH}/Main_Window.glade"
|
||||||
|
self._CSS_FILE: str = f"{self._HOME_CONFIG_PATH}/stylesheet.css"
|
||||||
|
self._KEY_BINDINGS_FILE: str = f"{self._HOME_CONFIG_PATH}/key-bindings.json"
|
||||||
|
self._PID_FILE: str = f"{self._HOME_CONFIG_PATH}/{APP_NAME.lower()}.pid"
|
||||||
|
self._UI_WIDEGTS_PATH: str = f"{self._HOME_CONFIG_PATH}/ui_widgets"
|
||||||
|
self._CONTEXT_MENU: str = f"{self._HOME_CONFIG_PATH}/contexct_menu.json"
|
||||||
|
self._WINDOW_ICON: str = f"{self._DEFAULT_ICONS}/{APP_NAME.lower()}.png"
|
||||||
|
|
||||||
|
# self._USR_CONFIG_FILE: str = f"{self._USR_PATH}/settings.json"
|
||||||
|
# self._PLUGINS_PATH: str = f"plugins"
|
||||||
|
# self._CONFIG_FILE: str = f"settings.json"
|
||||||
|
# self._GLADE_FILE: str = f"Main_Window.glade"
|
||||||
|
# self._CSS_FILE: str = f"stylesheet.css"
|
||||||
|
# self._KEY_BINDINGS_FILE: str = f"key-bindings.json"
|
||||||
|
# self._PID_FILE: str = f"{APP_NAME.lower()}.pid"
|
||||||
|
# self._WINDOW_ICON: str = f"{APP_NAME.lower()}.png"
|
||||||
|
# self._UI_WIDEGTS_PATH: str = f"ui_widgets"
|
||||||
|
# self._CONTEXT_MENU: str = f"contexct_menu.json"
|
||||||
|
# self._DEFAULT_ICONS: str = f"icons"
|
||||||
|
|
||||||
|
|
||||||
|
# with zipfile.ZipFile("files.zip", mode="r", allowZip64=True) as zf:
|
||||||
|
# with io.TextIOWrapper(zf.open("text1.txt"), encoding="utf-8") as f:
|
||||||
|
|
||||||
|
|
||||||
|
if not path.exists(self._HOME_CONFIG_PATH):
|
||||||
|
mkdir(self._HOME_CONFIG_PATH)
|
||||||
|
if not path.exists(self._PLUGINS_PATH):
|
||||||
|
mkdir(self._PLUGINS_PATH)
|
||||||
|
|
||||||
|
if not path.exists(self._DEFAULT_ICONS):
|
||||||
|
self._DEFAULT_ICONS = f"{self._USR_PATH}/icons"
|
||||||
|
if not path.exists(self._DEFAULT_ICONS):
|
||||||
|
raise MissingConfigError("Unable to find the application icons directory.")
|
||||||
|
if not path.exists(self._GLADE_FILE):
|
||||||
|
self._GLADE_FILE = f"{self._USR_PATH}/Main_Window.glade"
|
||||||
|
if not path.exists(self._GLADE_FILE):
|
||||||
|
raise MissingConfigError("Unable to find the application Glade file.")
|
||||||
|
if not path.exists(self._KEY_BINDINGS_FILE):
|
||||||
|
self._KEY_BINDINGS_FILE = f"{self._USR_PATH}/key-bindings.json"
|
||||||
|
if not path.exists(self._KEY_BINDINGS_FILE):
|
||||||
|
raise MissingConfigError("Unable to find the application Keybindings file.")
|
||||||
|
if not path.exists(self._CSS_FILE):
|
||||||
|
self._CSS_FILE = f"{self._USR_PATH}/stylesheet.css"
|
||||||
|
if not path.exists(self._CSS_FILE):
|
||||||
|
raise MissingConfigError("Unable to find the application Stylesheet file.")
|
||||||
|
if not path.exists(self._WINDOW_ICON):
|
||||||
|
self._WINDOW_ICON = f"{self._USR_PATH}/icons/{APP_NAME.lower()}.png"
|
||||||
|
if not path.exists(self._WINDOW_ICON):
|
||||||
|
raise MissingConfigError("Unable to find the application icon.")
|
||||||
|
if not path.exists(self._UI_WIDEGTS_PATH):
|
||||||
|
self._UI_WIDEGTS_PATH = f"{self._USR_PATH}/ui_widgets"
|
||||||
|
if not path.exists(self._CONTEXT_MENU):
|
||||||
|
self._CONTEXT_MENU = f"{self._USR_PATH}/contexct_menu.json"
|
||||||
|
|
||||||
|
|
||||||
|
def get_glade_file(self) -> str: return self._GLADE_FILE
|
||||||
|
def get_ui_widgets_path(self) -> str: return self._UI_WIDEGTS_PATH
|
||||||
|
def get_context_path(self) -> str: return self._CONTEXT_PATH
|
||||||
|
def get_plugins_path(self) -> str: return self._PLUGINS_PATH
|
||||||
|
def get_css_file(self) -> str: return self._CSS_FILE
|
||||||
|
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 load_keybindings(self):
|
||||||
|
try:
|
||||||
|
with open(self._KEY_BINDINGS_FILE) as file:
|
||||||
|
return json.load(file)["keybindings"]
|
||||||
|
except Exception as e:
|
||||||
|
print( f"Settings Path Manager: {self._KEY_BINDINGS_FILE}\n\t\t{repr(e)}" )
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def load_context_menu_data(self):
|
||||||
|
try:
|
||||||
|
with open(self._CONTEXT_MENU) as file:
|
||||||
|
return json.load(file)
|
||||||
|
except Exception as e:
|
||||||
|
print( f"Settings Path Manager: {self._CONTEXT_MENU}\n\t\t{repr(e)}" )
|
||||||
|
return {}
|
||||||
|
|
||||||
|
def load_settings(self):
|
||||||
|
if not path.exists(self._CONFIG_FILE):
|
||||||
|
return None
|
||||||
|
|
||||||
|
with open(self._CONFIG_FILE) as file:
|
||||||
|
data = json.load(file)
|
||||||
|
data["load_defaults"] = False
|
||||||
|
return data
|
||||||
|
|
||||||
|
def save_settings(self, settings: any):
|
||||||
|
with open(self._CONFIG_FILE, 'w') as outfile:
|
||||||
|
json.dump(settings.as_dict(), outfile, separators=(',', ':'), indent=4)
|
||||||
@@ -24,8 +24,8 @@ class StartCheckMixin:
|
|||||||
self._print_pid(pid)
|
self._print_pid(pid)
|
||||||
return
|
return
|
||||||
|
|
||||||
if os.path.exists(self._PID_FILE):
|
if os.path.exists(self.path_manager._PID_FILE):
|
||||||
with open(self._PID_FILE, "r") as f:
|
with open(self.path_manager._PID_FILE, "r") as f:
|
||||||
pid = f.readline().strip()
|
pid = f.readline().strip()
|
||||||
if pid not in ("", None):
|
if pid not in ("", None):
|
||||||
if self.is_pid_alive( int(pid) ):
|
if self.is_pid_alive( int(pid) ):
|
||||||
@@ -56,8 +56,8 @@ class StartCheckMixin:
|
|||||||
print(f"{APP_NAME} PID: {pid}")
|
print(f"{APP_NAME} PID: {pid}")
|
||||||
|
|
||||||
def _clean_pid(self):
|
def _clean_pid(self):
|
||||||
os.unlink(self._PID_FILE)
|
os.unlink(self.path_manager._PID_FILE)
|
||||||
|
|
||||||
def _write_pid(self, pid):
|
def _write_pid(self, pid):
|
||||||
with open(self._PID_FILE, "w") as _pid:
|
with open(self.path_manager._PID_FILE, "w") as _pid:
|
||||||
_pid.write(f"{pid}")
|
_pid.write(f"{pid}")
|
||||||
@@ -19,7 +19,7 @@ class ManifestMapperException(Exception):
|
|||||||
class ManifestManager:
|
class ManifestManager:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
|
||||||
self._plugins_path = settings_manager.get_plugins_path()
|
self._plugins_path = settings_manager.path_manager.get_plugins_path()
|
||||||
|
|
||||||
self.pre_launch_manifests = []
|
self.pre_launch_manifests = []
|
||||||
self.post_launch_manifests = []
|
self.post_launch_manifests = []
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ class PluginsController(PluginReloadMixin):
|
|||||||
|
|
||||||
self._plugin_collection = []
|
self._plugin_collection = []
|
||||||
|
|
||||||
self._plugins_path = settings_manager.get_plugins_path()
|
self._plugins_path = settings_manager.path_manager.get_plugins_path()
|
||||||
self._manifest_manager = ManifestManager()
|
self._manifest_manager = ManifestManager()
|
||||||
|
|
||||||
self._set_plugins_watcher()
|
self._set_plugins_watcher()
|
||||||
|
|||||||
Reference in New Issue
Block a user