Argparse update and IPC events
This commit is contained in:
parent
35cf150fbc
commit
9f1da21127
|
@ -1,5 +1,5 @@
|
|||
# Python imports
|
||||
import inspect, time
|
||||
import os, inspect, time
|
||||
|
||||
# Gtk imports
|
||||
|
||||
|
@ -10,19 +10,27 @@ from __builtins__ import Builtins
|
|||
|
||||
|
||||
class Main(Builtins):
|
||||
def __init__(self, args):
|
||||
def __init__(self, args, unknownargs):
|
||||
event_system.create_ipc_server()
|
||||
time.sleep(0.5)
|
||||
if not event_system.is_ipc_alive:
|
||||
if args.new_tab:
|
||||
if unknownargs:
|
||||
for arg in unknownargs:
|
||||
if os.path.isdir(arg):
|
||||
message = f"FILE|{arg}"
|
||||
event_system.send_ipc_message(message)
|
||||
|
||||
if args.new_tab and os.path.isdir(args.new_tab):
|
||||
message = f"FILE|{args.new_tab}"
|
||||
event_system.send_ipc_message(message)
|
||||
raise Exception("IPC Server Exists: Will send message to it and close...")
|
||||
|
||||
raise Exception("IPC Server Exists: Will send path(s) to it and close...")
|
||||
|
||||
|
||||
settings = Settings()
|
||||
settings.createWindow()
|
||||
|
||||
signals = Signals(args, settings)
|
||||
signals = Signals(args, unknownargs, settings)
|
||||
if not signals:
|
||||
raise Exception("Signals exited...")
|
||||
|
||||
|
@ -39,4 +47,3 @@ class Main(Builtins):
|
|||
pass
|
||||
|
||||
settings.builder.connect_signals(handlers)
|
||||
window = settings.createWindow()
|
||||
|
|
|
@ -24,12 +24,13 @@ if __name__ == "__main__":
|
|||
faulthandler.enable() # For better debug info
|
||||
parser = argparse.ArgumentParser()
|
||||
# Add long and short arguments
|
||||
parser.add_argument("--new-tab", "-t", help="Open a file into new tab.")
|
||||
parser.add_argument("--new-window", "-w", help="Open a file into a new window.")
|
||||
parser.add_argument("--new-tab", "-t", default="", help="Open a file into new tab.")
|
||||
parser.add_argument("--new-window", "-w", default="", help="Open a file into a new window.")
|
||||
|
||||
# Read arguments (If any...)
|
||||
args = parser.parse_args()
|
||||
Main(args)
|
||||
args, unknownargs = parser.parse_known_args()
|
||||
|
||||
Main(args, unknownargs)
|
||||
Gtk.main()
|
||||
except Exception as e:
|
||||
event_system.keep_ipc_alive = False
|
||||
|
|
|
@ -24,11 +24,14 @@ class DBusControllerMixin:
|
|||
print(f"New Connection: {listener.last_accepted}")
|
||||
while True:
|
||||
msg = conn.recv()
|
||||
if debug:
|
||||
print(msg)
|
||||
|
||||
if "FILE|" in msg:
|
||||
file = msg.split("FILE|")[1].strip()
|
||||
if file:
|
||||
event_system.push_gui_event(["create_tab_from_ipc", None, file])
|
||||
|
||||
conn.close()
|
||||
break
|
||||
|
||||
|
|
|
@ -21,7 +21,7 @@ def threaded(fn):
|
|||
|
||||
|
||||
class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
|
||||
def __init__(self, args, settings):
|
||||
def __init__(self, args, unknownargs, settings):
|
||||
self.settings = settings
|
||||
self.builder = self.settings.builder
|
||||
self.logger = self.settings.logger
|
||||
|
@ -30,10 +30,10 @@ class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
|
|||
self.state = self.window_controller.load_state()
|
||||
|
||||
self.window = self.settings.getMainWindow()
|
||||
self.window1 = self.builder.get_object("window1")
|
||||
self.window2 = self.builder.get_object("window2")
|
||||
self.window3 = self.builder.get_object("window3")
|
||||
self.window4 = self.builder.get_object("window4")
|
||||
self.window1 = self.builder.get_object("window_1")
|
||||
self.window2 = self.builder.get_object("window_2")
|
||||
self.window3 = self.builder.get_object("window_3")
|
||||
self.window4 = self.builder.get_object("window_4")
|
||||
self.notebooks = [self.window1, self.window2, self.window3, self.window4]
|
||||
self.selected_files = []
|
||||
self.to_copy_files = []
|
||||
|
@ -56,10 +56,21 @@ class Signals(WidgetFileActionMixin, PaneMixin, WindowMixin):
|
|||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT, self.tear_down)
|
||||
self.gui_event_observer()
|
||||
|
||||
if unknownargs:
|
||||
for arg in unknownargs:
|
||||
if os.path.isdir(arg):
|
||||
message = f"FILE|{arg}"
|
||||
event_system.send_ipc_message(message)
|
||||
|
||||
if args.new_tab and os.path.isdir(args.new_tab):
|
||||
message = f"FILE|{args.new_tab}"
|
||||
event_system.send_ipc_message(message)
|
||||
|
||||
|
||||
def tear_down(self, widget=None, eve=None):
|
||||
self.window_controller.save_state()
|
||||
event_system.send_ipc_message("close server")
|
||||
event_system.monitor_events = False
|
||||
event_system.send_ipc_message("close server")
|
||||
time.sleep(event_sleep_time)
|
||||
Gtk.main_quit()
|
||||
|
||||
|
|
|
@ -11,8 +11,14 @@ class TabMixin(WidgetMixin):
|
|||
|
||||
def create_tab_from_ipc(data):
|
||||
self, path = data
|
||||
wid, tid = self.window_controller.get_active_data()
|
||||
self.create_tab(wid, path)
|
||||
if not self.is_pane1_hidden:
|
||||
self.create_tab(1, path)
|
||||
elif not self.is_pane2_hidden:
|
||||
self.create_tab(2, path)
|
||||
elif not self.is_pane3_hidden:
|
||||
self.create_tab(3, path)
|
||||
elif not self.is_pane4_hidden:
|
||||
self.create_tab(4, path)
|
||||
|
||||
|
||||
def create_tab(self, wid, path=None):
|
||||
|
|
Loading…
Reference in New Issue