From 07a800f61a3282bdb25dd9b8e8a36337ed2ece46 Mon Sep 17 00:00:00 2001 From: aquintan Date: Thu, 12 Nov 2026 10:53:38 +0100 Subject: [PATCH 1/2] Refresh and fit rqt graphs automatically - Refresh node graph and TF tree once ROS discovery has settled - Fit both graphs again when the browser panel is resized --- .../manager/launcher/launcher_rqt.py | 7 ++- .../manager/launcher/rqt_autorefresh.py | 55 +++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) create mode 100644 robotics_application_manager/manager/launcher/rqt_autorefresh.py diff --git a/robotics_application_manager/manager/launcher/launcher_rqt.py b/robotics_application_manager/manager/launcher/launcher_rqt.py index b0b9562..a6d113f 100644 --- a/robotics_application_manager/manager/launcher/launcher_rqt.py +++ b/robotics_application_manager/manager/launcher/launcher_rqt.py @@ -12,6 +12,7 @@ from robotics_application_manager.manager.vnc import Vnc_server from robotics_application_manager import LogManager from typing import List, Any +import os import subprocess @@ -39,7 +40,9 @@ def run(self, config_file, callback): if config_file is None: config_file = "/opt/jderobot/Launchers/rqt/default.perspective" - config = f"rqt --perspective-file {config_file}" + # Keep the graph plugins refreshed and fitted to the browser panel + autorefresh = os.path.join(os.path.dirname(__file__), "rqt_autorefresh.py") + config = f"python3 {autorefresh} --perspective-file {config_file}" if ACCELERATION_ENABLED: self.vnc.start_vnc_gpu( @@ -76,7 +79,7 @@ def terminate(self): thread.terminate() # rqt ignores SIGTERM so join would block forever subprocess.call( - "pkill -9 -f 'bin/rqt --perspective-file'", + "pkill -9 -f rqt_autorefresh.py", shell=True, stdout=subprocess.PIPE, bufsize=1024, diff --git a/robotics_application_manager/manager/launcher/rqt_autorefresh.py b/robotics_application_manager/manager/launcher/rqt_autorefresh.py new file mode 100644 index 0000000..3471467 --- /dev/null +++ b/robotics_application_manager/manager/launcher/rqt_autorefresh.py @@ -0,0 +1,55 @@ +""" +Start rqt keeping its graph plugins readable inside the web VNC viewer. + +rqt_graph and rqt_tf_tree query the ROS graph only once at startup, before +their node has discovered the rest of the system, so they open empty. They +also fit the graph to the view only when it is drawn, while noVNC resizes +the screen every time the browser panel changes size. + +Run by LauncherRqt as a script inside the Robotics Backend, not imported. +""" + +import sys + +from python_qt_binding.QtCore import QEvent, QObject, QTimer +from python_qt_binding.QtWidgets import QApplication, QGraphicsView, QPushButton +from rqt_gui.main import Main + +# Both plugins name their buttons the same way +REFRESH_BUTTON = "refresh_graph_push_button" +FIT_BUTTON = "fit_in_view_push_button" +REFRESH_DELAYS_MS = [3000, 8000] +FIT_DEBOUNCE_MS = 300 + + +def click_buttons(name): + for widget in QApplication.allWidgets(): + if isinstance(widget, QPushButton) and widget.objectName() == name: + widget.click() + + +class FitOnResize(QObject): + def __init__(self): + super().__init__() + self.timer = QTimer() + self.timer.setSingleShot(True) + self.timer.timeout.connect(lambda: click_buttons(FIT_BUTTON)) + + def eventFilter(self, obj, event): + if event.type() == QEvent.Resize and isinstance(obj, QGraphicsView): + self.timer.start(FIT_DEBOUNCE_MS) + return False + + +class AutoRefreshMain(Main): + def create_application(self, argv): + app = super().create_application(argv) + for delay in REFRESH_DELAYS_MS: + QTimer.singleShot(delay, lambda: click_buttons(REFRESH_BUTTON)) + self.fit_on_resize = FitOnResize() + app.installEventFilter(self.fit_on_resize) + return app + + +if __name__ == "__main__": + sys.exit(AutoRefreshMain().main()) From 7ddcde95427bc58f004d676e2c2497c7cc9b0115 Mon Sep 17 00:00:00 2001 From: Javier Izquierdo Hernandez Date: Fri, 13 Nov 2026 11:18:29 +0100 Subject: [PATCH 2/2] Removing pkill --- .../manager/launcher/launcher_rqt.py | 8 -------- .../manager/launcher/rqt_autorefresh.py | 6 ++++++ 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/robotics_application_manager/manager/launcher/launcher_rqt.py b/robotics_application_manager/manager/launcher/launcher_rqt.py index a6d113f..1264f6d 100644 --- a/robotics_application_manager/manager/launcher/launcher_rqt.py +++ b/robotics_application_manager/manager/launcher/launcher_rqt.py @@ -77,14 +77,6 @@ def terminate(self): for thread in self.threads[:]: if thread.is_alive(): thread.terminate() - # rqt ignores SIGTERM so join would block forever - subprocess.call( - "pkill -9 -f rqt_autorefresh.py", - shell=True, - stdout=subprocess.PIPE, - bufsize=1024, - universal_newlines=True, - ) thread.join() self.threads.remove(thread) self.running = False diff --git a/robotics_application_manager/manager/launcher/rqt_autorefresh.py b/robotics_application_manager/manager/launcher/rqt_autorefresh.py index 3471467..164042b 100644 --- a/robotics_application_manager/manager/launcher/rqt_autorefresh.py +++ b/robotics_application_manager/manager/launcher/rqt_autorefresh.py @@ -10,6 +10,7 @@ """ import sys +import signal from python_qt_binding.QtCore import QEvent, QObject, QTimer from python_qt_binding.QtWidgets import QApplication, QGraphicsView, QPushButton @@ -51,5 +52,10 @@ def create_application(self, argv): return app +def sigterm_handler(_signo, _stack_frame): + sys.exit(0) + + if __name__ == "__main__": + signal.signal(signal.SIGTERM, sigterm_handler) sys.exit(AutoRefreshMain().main())