Newton_Editor/src/app.py

60 lines
1.5 KiB
Python
Raw Normal View History

2023-03-18 04:17:38 +00:00
# Python imports
import signal
2023-03-18 04:17:38 +00:00
import os
# Lib imports
# Application imports
from utils.debugging import debug_signal_handler
2023-03-18 04:17:38 +00:00
from utils.ipc_server import IPCServer
from core.window import Window
2023-03-18 04:17:38 +00:00
class AppLaunchException(Exception):
...
class Application(IPCServer):
""" docstring for Application. """
2023-03-18 04:17:38 +00:00
def __init__(self, args, unknownargs):
super(Application, self).__init__()
if not settings_manager.is_trace_debug():
2023-10-19 02:53:28 +00:00
self.socket_realization_check()
2023-03-18 04:17:38 +00:00
if not self.is_ipc_alive:
for arg in unknownargs + [args.new_tab,]:
if os.path.isfile(arg):
2023-03-18 04:17:38 +00:00
message = f"FILE|{arg}"
self.send_ipc_message(message)
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
2023-03-18 04:17:38 +00:00
self.setup_debug_hook()
Window(args, unknownargs)
def socket_realization_check(self):
2023-10-19 02:53:28 +00: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:
# kill -SIGUSR2 <pid> from Linux/Unix or SIGBREAK signal from Windows
signal.signal(
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"),
debug_signal_handler
)
except ValueError:
# Typically: ValueError: signal only works in main thread
...