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

70 lines
1.8 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
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
# Break into a Python console upon SIGUSR1 (Linux) or SIGBREAK (Windows:
# CTRL+Pause/Break). To be included in all production code, just in case.
def debug_signal_handler(signal, frame):
del signal
del frame
try:
import rpdb2
logger.debug("\n\nStarting embedded RPDB2 debugger. Password is 'foobar'\n\n")
rpdb2.start_embedded_debugger("foobar", True, True)
rpdb2.setbreak(depth=1)
return
except StandardError:
pass
try:
import code
code.interact()
except StandardError as ex:
logger.debug(f"{ex}, returning to normal program flow...")
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.is_trace_debug():
2022-10-23 04:26:13 +00:00
try:
self.create_ipc_listener()
except Exception:
...
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
try:
signal.signal(
vars(signal).get("SIGBREAK") or vars(signal).get("SIGUSR1"),
debug_signal_handler
)
except ValueError:
# Typically: ValueError: signal only works in main thread
...
Window(args, unknownargs)