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

60 lines
1.5 KiB
Python
Raw Normal View History

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