From b4120bdca4a581510d4e95213db54ac125703b4a Mon Sep 17 00:00:00 2001 From: itdominator <1itdominator@gmail.com> Date: Mon, 27 Mar 2023 21:25:54 -0500 Subject: [PATCH] Added args handler, made IPC singleton --- src/app.py | 4 ++-- src/core/controller.py | 13 +++++++++++++ src/core/mixins/signals/ipc_signals_mixin.py | 5 ++++- src/core/window.py | 2 +- src/utils/ipc_server.py | 9 +++++++-- src/utils/singleton.py | 1 + 6 files changed, 28 insertions(+), 6 deletions(-) diff --git a/src/app.py b/src/app.py index 1ea9b36..85809d6 100644 --- a/src/app.py +++ b/src/app.py @@ -14,7 +14,7 @@ class AppLaunchException(Exception): class Application(IPCServer): - ''' Create Settings and Controller classes. Bind signal to Builder. Inherit from Builtins to bind global methods and classes.''' + """ docstring for Application. """ def __init__(self, args, unknownargs): super(Application, self).__init__() @@ -26,7 +26,7 @@ class Application(IPCServer): if not self.is_ipc_alive: for arg in unknownargs + [args.new_tab,]: - if os.path.isdir(arg): + if os.path.isfile(arg): message = f"FILE|{arg}" self.send_ipc_message(message) diff --git a/src/core/controller.py b/src/core/controller.py index 1ca363f..3d16cf7 100644 --- a/src/core/controller.py +++ b/src/core/controller.py @@ -27,6 +27,18 @@ class Controller(DummyMixin, SignalsMixins, ControllerData): self.print_hello_world() # A mixin method from the DummyMixin file + if args.no_plugins == "false": + self.plugins.launch_plugins() + + for arg in unknownargs + [args.new_tab,]: + if os.path.isfile(arg): + message = f"FILE|{arg}" + event_system.emit("post_file_to_ipc", message) + + if os.path.isdir(arg): + message = f"DIR|{arg}" + event_system.emit("post_file_to_ipc", message) + logger.info(f"Made it past {self.__class__} loading...") @@ -40,6 +52,7 @@ class Controller(DummyMixin, SignalsMixins, ControllerData): def _subscribe_to_events(self): event_system.subscribe("handle_file_from_ipc", self.handle_file_from_ipc) + event_system.subscribe("handle_dir_from_ipc", self.handle_dir_from_ipc) event_system.subscribe("tggl_top_main_menubar", self._tggl_top_main_menubar) def load_glade_file(self): diff --git a/src/core/mixins/signals/ipc_signals_mixin.py b/src/core/mixins/signals/ipc_signals_mixin.py index 34c6555..760fe8e 100644 --- a/src/core/mixins/signals/ipc_signals_mixin.py +++ b/src/core/mixins/signals/ipc_signals_mixin.py @@ -14,4 +14,7 @@ class IPCSignalsMixin: print(message) def handle_file_from_ipc(self, path: str) -> None: - print(f"Path From IPC: {path}") + print(f"File From IPC: {path}") + + def handle_dir_from_ipc(self, path: str) -> None: + print(f"Dir From IPC: {path}") diff --git a/src/core/window.py b/src/core/window.py index 45c79b5..0ee3b0f 100644 --- a/src/core/window.py +++ b/src/core/window.py @@ -22,7 +22,7 @@ class ControllerStartExceptiom(Exception): class Window(Gtk.ApplicationWindow): - """docstring for Window.""" + """ docstring for Window. """ def __init__(self, args, unknownargs): super(Window, self).__init__() diff --git a/src/utils/ipc_server.py b/src/utils/ipc_server.py index 2376170..662fc89 100644 --- a/src/utils/ipc_server.py +++ b/src/utils/ipc_server.py @@ -8,11 +8,11 @@ from multiprocessing.connection import Listener # Lib imports # Application imports +from .singleton import Singleton - -class IPCServer: +class IPCServer(Singleton): """ Create a listener so that other {app_name} instances send requests back to existing instance. """ def __init__(self, ipc_address: str = '127.0.0.1', conn_type: str = "socket"): self.is_ipc_alive = False @@ -77,6 +77,11 @@ class IPCServer: if file: event_system.emit("handle_file_from_ipc", file) + if "DIR|" in msg: + file = msg.split("DIR|")[1].strip() + if file: + event_system.emit("handle_dir_from_ipc", file) + conn.close() break diff --git a/src/utils/singleton.py b/src/utils/singleton.py index ee85368..23b7191 100644 --- a/src/utils/singleton.py +++ b/src/utils/singleton.py @@ -5,6 +5,7 @@ # Application imports + class SingletonError(Exception): pass