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

64 lines
1.7 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
class Application:
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():
self.load_ipc(args, unknownargs)
2022-02-25 23:53:58 +00:00
self.setup_debug_hook()
Window(args, unknownargs).main()
2024-01-09 02:01:14 +00:00
def load_ipc(self, args, unknownargs):
ipc_server = IPCServer()
self.ipc_realization_check(ipc_server)
if not ipc_server.is_ipc_alive:
for arg in unknownargs + [args.new_tab,]:
if os.path.isfile(arg):
message = f"FILE|{arg}"
ipc_server.send_ipc_message(message)
raise AppLaunchException(f"{app_name} IPC Server Exists: Have sent path(s) to it and closing...")
def ipc_realization_check(self, ipc_server):
2023-10-19 02:52:45 +00:00
try:
ipc_server.create_ipc_listener()
2023-10-19 02:52:45 +00:00
except Exception:
ipc_server.send_test_ipc_message()
2023-10-19 02:52:45 +00:00
try:
ipc_server.create_ipc_listener()
2023-10-19 02:52:45 +00:00
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
...