Files
Python-With-Gtk-Template/src/app.py

60 lines
1.5 KiB
Python
Raw Normal View History

2022-02-25 17:53:58 -06:00
# Python imports
import signal
import os
2022-02-25 17:53:58 -06:00
# Lib imports
# Application imports
2023-04-29 09:40:09 -05:00
from utils.debugging import debug_signal_handler
2022-09-05 18:01:39 -05:00
from utils.ipc_server import IPCServer
from core.window import Window
2022-02-25 17:53:58 -06:00
class AppLaunchException(Exception):
2022-09-05 18:01:39 -05:00
...
2022-02-25 17:53:58 -06:00
2022-09-05 18:01:39 -05:00
class Application(IPCServer):
2023-03-27 21:25:54 -05:00
""" docstring for Application. """
2022-02-25 17:53:58 -06:00
def __init__(self, args, unknownargs):
2022-09-05 18:01:39 -05:00
super(Application, self).__init__()
if not settings_manager.is_trace_debug():
2023-10-18 21:52:45 -05:00
self.socket_realization_check()
2022-09-05 18:01:39 -05:00
if not self.is_ipc_alive:
2022-10-22 23:26:13 -05:00
for arg in unknownargs + [args.new_tab,]:
2023-03-27 21:25:54 -05:00
if os.path.isfile(arg):
2022-10-22 23:26:13 -05:00
message = f"FILE|{arg}"
self.send_ipc_message(message)
2022-02-25 17:53:58 -06:00
2022-10-22 23:26:13 -05:00
raise AppLaunchException(f"{app_name} IPC Server Exists: Will send path(s) to it and close...")
2022-02-25 17:53:58 -06:00
self.setup_debug_hook()
Window(args, unknownargs)
def socket_realization_check(self):
2023-10-18 21:52:45 -05:00
try:
self.create_ipc_listener()
except Exception:
self.send_test_ipc_message()
try:
self.create_ipc_listener()
except Exception as e:
...
def setup_debug_hook(self):
try:
2023-04-29 09:40:09 -05:00
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
signal.signal(
2023-04-29 09:40:09 -05:00
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"),
debug_signal_handler
)
except ValueError:
# Typically: ValueError: signal only works in main thread
...