added timing
This commit is contained in:
+39
-1
@@ -2,10 +2,13 @@
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
from pathlib import Path
|
||||
import signal
|
||||
import sys
|
||||
|
||||
import pyqtgraph as pg
|
||||
from PyQt6.QtCore import QTimer
|
||||
from PyQt6.QtWidgets import QApplication
|
||||
|
||||
# Ensure imports are resolved when started as a script.
|
||||
@@ -17,6 +20,38 @@ from python_app.gui.app_window import AppWindow
|
||||
from python_app.gui.theme import apply_light_theme
|
||||
|
||||
|
||||
def _is_headless() -> bool:
|
||||
"""Return whether the launcher requested a non-interactive deployment."""
|
||||
return os.environ.get("RADAR_SYSTEM_HEADLESS", "").strip().lower() in {
|
||||
"1",
|
||||
"true",
|
||||
"yes",
|
||||
"on",
|
||||
}
|
||||
|
||||
|
||||
def _install_unix_signal_handlers(app: QApplication, window: AppWindow) -> None:
|
||||
"""Route SIGINT and SIGTERM through the Qt event loop into a clean shutdown.
|
||||
|
||||
`window.close()` runs `closeEvent`, which aborts any active capture and
|
||||
shuts down managed C++ processes; only then does the Qt loop exit. A
|
||||
short repeating timer keeps the Python interpreter pinned in the event
|
||||
loop just long enough to deliver pending signals.
|
||||
"""
|
||||
|
||||
def _request_shutdown(*_args: object) -> None:
|
||||
window.close()
|
||||
app.quit()
|
||||
|
||||
for sig in (signal.SIGINT, signal.SIGTERM):
|
||||
signal.signal(sig, _request_shutdown)
|
||||
|
||||
keepalive_timer = QTimer(app)
|
||||
keepalive_timer.setInterval(200)
|
||||
keepalive_timer.timeout.connect(lambda: None)
|
||||
keepalive_timer.start()
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""Run Qt event loop and show main radar control window."""
|
||||
app = QApplication(sys.argv)
|
||||
@@ -24,7 +59,10 @@ def main() -> int:
|
||||
# PyQtGraph foreground controls axis lines, tick text, labels, and titles.
|
||||
pg.setConfigOptions(antialias=True, background="#ffffff", foreground="#ffffff")
|
||||
window = AppWindow(PROJECT_ROOT)
|
||||
window.showMaximized()
|
||||
if _is_headless():
|
||||
_install_unix_signal_handlers(app, window)
|
||||
else:
|
||||
window.showMaximized()
|
||||
return app.exec()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user