Moved args info to settings and restructured calls
This commit is contained in:
parent
f2b33066af
commit
33c0827ca2
|
@ -17,7 +17,7 @@ from app import Application
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def main(args, unknownargs):
|
def main():
|
||||||
setproctitle(f'{APP_NAME}')
|
setproctitle(f'{APP_NAME}')
|
||||||
settings_manager.set_start_load_time()
|
settings_manager.set_start_load_time()
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ def main(args, unknownargs):
|
||||||
settings_manager.set_trace_debug(True)
|
settings_manager.set_trace_debug(True)
|
||||||
|
|
||||||
settings_manager.do_dirty_start_check()
|
settings_manager.do_dirty_start_check()
|
||||||
Application(args, unknownargs)
|
Application()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -37,19 +37,20 @@ if __name__ == "__main__":
|
||||||
|
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
# Add long and short arguments
|
# Add long and short arguments
|
||||||
parser.add_argument("--debug", "-d", default="false", help="Do extra console messaging.")
|
parser.add_argument("--debug", "-d", default = "false", help = "Do extra console messaging.")
|
||||||
parser.add_argument("--trace-debug", "-td", default="false", help="Disable saves, ignore IPC lock, do extra console messaging.")
|
parser.add_argument("--trace-debug", "-td", default = "false", help = "Disable saves, ignore IPC lock, do extra console messaging.")
|
||||||
parser.add_argument("--no-plugins", "-np", default="false", help="Do not load plugins.")
|
parser.add_argument("--no-plugins", "-np", default = "false", help = "Do not load plugins.")
|
||||||
|
|
||||||
parser.add_argument("--new-tab", "-nt", default="false", help="Opens a 'New Tab' if a handler is set for it.")
|
parser.add_argument("--new-tab", "-nt", default = "false", help = "Opens a 'New Tab' if a handler is set for it.")
|
||||||
parser.add_argument("--file", "-f", default="default", help="JUST SOME FILE ARG.")
|
parser.add_argument("--file", "-f", default = "default", help = "JUST SOME FILE ARG.")
|
||||||
|
|
||||||
# Read arguments (If any...)
|
# Read arguments (If any...)
|
||||||
args, unknownargs = parser.parse_known_args()
|
args, unknownargs = parser.parse_known_args()
|
||||||
|
settings_manager.set_starting_args( args, unknownargs )
|
||||||
|
|
||||||
try:
|
try:
|
||||||
faulthandler.enable() # For better debug info
|
faulthandler.enable() # For better debug info
|
||||||
main(args, unknownargs)
|
main()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
quit()
|
quit()
|
10
src/app.py
10
src/app.py
|
@ -19,18 +19,20 @@ class AppLaunchException(Exception):
|
||||||
class Application:
|
class Application:
|
||||||
""" docstring for Application. """
|
""" docstring for Application. """
|
||||||
|
|
||||||
def __init__(self, args, unknownargs):
|
def __init__(self):
|
||||||
super(Application, self).__init__()
|
super(Application, self).__init__()
|
||||||
|
|
||||||
if not settings_manager.is_trace_debug():
|
if not settings_manager.is_trace_debug():
|
||||||
self.load_ipc(args, unknownargs)
|
self.load_ipc()
|
||||||
|
|
||||||
self.setup_debug_hook()
|
self.setup_debug_hook()
|
||||||
Window(args, unknownargs).main()
|
Window().main()
|
||||||
|
|
||||||
|
|
||||||
def load_ipc(self, args, unknownargs):
|
def load_ipc(self):
|
||||||
|
args, unknownargs = settings_manager.get_starting_args()
|
||||||
ipc_server = IPCServer()
|
ipc_server = IPCServer()
|
||||||
|
|
||||||
self.ipc_realization_check(ipc_server)
|
self.ipc_realization_check(ipc_server)
|
||||||
|
|
||||||
if not ipc_server.is_ipc_alive:
|
if not ipc_server.is_ipc_alive:
|
||||||
|
|
|
@ -17,24 +17,15 @@ from .bridge_controller import BridgeController
|
||||||
|
|
||||||
|
|
||||||
class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
|
class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
|
||||||
def __init__(self, args, unknownargs):
|
def __init__(self):
|
||||||
self.collect_files_dirs(args, unknownargs)
|
self.collect_files_dirs()
|
||||||
|
|
||||||
self.setup_controller_data()
|
self.setup_controller_data()
|
||||||
|
|
||||||
self._setup_styling()
|
self._setup_styling()
|
||||||
self._setup_signals()
|
self._setup_signals()
|
||||||
self._subscribe_to_events()
|
self._subscribe_to_events()
|
||||||
self._load_controllers()
|
self._load_controllers()
|
||||||
|
self._load_plugins_and_files()
|
||||||
if args.no_plugins == "false":
|
|
||||||
self.plugins_controller.pre_launch_plugins()
|
|
||||||
|
|
||||||
if args.no_plugins == "false":
|
|
||||||
self.plugins_controller.post_launch_plugins()
|
|
||||||
|
|
||||||
for file in settings_manager.get_starting_files():
|
|
||||||
event_system.emit("post-file-to-ipc", file)
|
|
||||||
|
|
||||||
logger.info(f"Made it past {self.__class__} loading...")
|
logger.info(f"Made it past {self.__class__} loading...")
|
||||||
settings_manager.set_end_load_time()
|
settings_manager.set_end_load_time()
|
||||||
|
@ -58,11 +49,22 @@ class BaseController(IPCSignalsMixin, KeyboardSignalsMixin, BaseControllerData):
|
||||||
def _load_controllers(self):
|
def _load_controllers(self):
|
||||||
BridgeController()
|
BridgeController()
|
||||||
|
|
||||||
|
def _load_plugins_and_files(self):
|
||||||
|
args, unknownargs = settings_manager.get_starting_args()
|
||||||
|
if args.no_plugins == "false":
|
||||||
|
self.plugins_controller.pre_launch_plugins()
|
||||||
|
|
||||||
|
if args.no_plugins == "false":
|
||||||
|
self.plugins_controller.post_launch_plugins()
|
||||||
|
|
||||||
|
for file in settings_manager.get_starting_files():
|
||||||
|
event_system.emit("post-file-to-ipc", file)
|
||||||
|
|
||||||
def _tggl_top_main_menubar(self):
|
def _tggl_top_main_menubar(self):
|
||||||
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.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)
|
||||||
|
|
|
@ -28,8 +28,11 @@ class BaseControllerData:
|
||||||
self._load_glade_file()
|
self._load_glade_file()
|
||||||
|
|
||||||
|
|
||||||
def collect_files_dirs(self, args, unknownargs):
|
def collect_files_dirs(self):
|
||||||
|
args, \
|
||||||
|
unknownargs = settings_manager.get_starting_args()
|
||||||
files = []
|
files = []
|
||||||
|
|
||||||
for arg in unknownargs + [args.new_tab,]:
|
for arg in unknownargs + [args.new_tab,]:
|
||||||
if os.path.isdir( arg.replace("file://", "") ):
|
if os.path.isdir( arg.replace("file://", "") ):
|
||||||
files.append( f"DIR|{arg.replace('file://', '')}" )
|
files.append( f"DIR|{arg.replace('file://', '')}" )
|
||||||
|
|
|
@ -24,7 +24,7 @@ class ControllerStartExceptiom(Exception):
|
||||||
class Window(Gtk.ApplicationWindow):
|
class Window(Gtk.ApplicationWindow):
|
||||||
""" docstring for Window. """
|
""" docstring for Window. """
|
||||||
|
|
||||||
def __init__(self, args, unknownargs):
|
def __init__(self):
|
||||||
super(Window, self).__init__()
|
super(Window, self).__init__()
|
||||||
settings_manager.set_main_window(self)
|
settings_manager.set_main_window(self)
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ class Window(Gtk.ApplicationWindow):
|
||||||
self._setup_styling()
|
self._setup_styling()
|
||||||
self._setup_signals()
|
self._setup_signals()
|
||||||
self._subscribe_to_events()
|
self._subscribe_to_events()
|
||||||
self._load_widgets(args, unknownargs)
|
self._load_widgets()
|
||||||
|
|
||||||
self._set_window_data()
|
self._set_window_data()
|
||||||
self._set_size_constraints()
|
self._set_size_constraints()
|
||||||
|
@ -63,11 +63,11 @@ class Window(Gtk.ApplicationWindow):
|
||||||
event_system.subscribe("tear-down", self._tear_down)
|
event_system.subscribe("tear-down", self._tear_down)
|
||||||
event_system.subscribe("load-interactive-debug", self._load_interactive_debug)
|
event_system.subscribe("load-interactive-debug", self._load_interactive_debug)
|
||||||
|
|
||||||
def _load_widgets(self, args, unknownargs):
|
def _load_widgets(self):
|
||||||
if settings_manager.is_debug():
|
if settings_manager.is_debug():
|
||||||
self.set_interactive_debugging(True)
|
self.set_interactive_debugging(True)
|
||||||
|
|
||||||
self._controller = BaseController(args, unknownargs)
|
self._controller = BaseController()
|
||||||
self._status_icon = StatusIcon()
|
self._status_icon = StatusIcon()
|
||||||
if not self._controller:
|
if not self._controller:
|
||||||
raise ControllerStartException("BaseController exited and doesn't exist...")
|
raise ControllerStartException("BaseController exited and doesn't exist...")
|
||||||
|
|
|
@ -156,14 +156,8 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
def get_home_path(self) -> str: return self._USER_HOME
|
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 is_trace_debug(self) -> str: return self._trace_debug
|
def get_starting_args(self):
|
||||||
def is_debug(self) -> str: return self._debug
|
return self.args, self.unknownargs
|
||||||
def is_starting_with_file(self) -> bool: return self._passed_in_file
|
|
||||||
|
|
||||||
def call_method(self, target_class: any = None, _method_name: str = "", data: any = 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: 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
|
||||||
|
@ -172,10 +166,12 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
def set_main_window_min_width(self, width: int = 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: int = 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): self._starting_files = files
|
def set_starting_files(self, files: list): self._starting_files = files
|
||||||
|
|
||||||
def set_start_load_time(self): self._start_load_time = time.perf_counter()
|
def set_start_load_time(self): self._start_load_time = time.perf_counter()
|
||||||
def set_end_load_time(self): self._end_load_time = time.perf_counter()
|
def set_end_load_time(self): self._end_load_time = time.perf_counter()
|
||||||
def log_load_time(self): logger.info( f"Load Time: {self._end_load_time - self._start_load_time}" )
|
|
||||||
|
def set_starting_args(self, args, unknownargs):
|
||||||
|
self.args = args
|
||||||
|
self.unknownargs = unknownargs
|
||||||
|
|
||||||
def set_trace_debug(self, trace_debug: bool):
|
def set_trace_debug(self, trace_debug: bool):
|
||||||
self._trace_debug = trace_debug
|
self._trace_debug = trace_debug
|
||||||
|
@ -186,6 +182,17 @@ class SettingsManager(StartCheckMixin, Singleton):
|
||||||
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):
|
||||||
self._passed_in_file = is_passed_in_file
|
self._passed_in_file = is_passed_in_file
|
||||||
|
|
||||||
|
def is_trace_debug(self) -> str: return self._trace_debug
|
||||||
|
def is_debug(self) -> str: return self._debug
|
||||||
|
def is_starting_with_file(self) -> bool: return self._passed_in_file
|
||||||
|
|
||||||
|
def log_load_time(self): logger.info( f"Load Time: {self._end_load_time - self._start_load_time}" )
|
||||||
|
|
||||||
|
def call_method(self, target_class: any = None, _method_name: str = "", data: any = 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 load_settings(self):
|
def load_settings(self):
|
||||||
if not path.exists(self._CONFIG_FILE):
|
if not path.exists(self._CONFIG_FILE):
|
||||||
self.settings = Settings()
|
self.settings = Settings()
|
||||||
|
|
Loading…
Reference in New Issue