From f6228dad5a4f572eb9af6a76e71d6a7e7d51ff6c Mon Sep 17 00:00:00 2001 From: martinappleby Date: Fri, 7 Nov 2025 14:01:45 +0100 Subject: [PATCH] GUI: added more verbose error handling to JFJochDbusClient --- gui/src/aaregui/threads/jfjoch_viewer.py | 30 +++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/gui/src/aaregui/threads/jfjoch_viewer.py b/gui/src/aaregui/threads/jfjoch_viewer.py index bddc43ba..404396b4 100644 --- a/gui/src/aaregui/threads/jfjoch_viewer.py +++ b/gui/src/aaregui/threads/jfjoch_viewer.py @@ -7,14 +7,26 @@ class JFJochDBusClient(QObject): self.__session_bus = QDBusConnection.sessionBus() self.__interface = None + self.__dbus_available = False - if not self.__session_bus.isConnected(): - print("Failed to connect to session bus") - return + try: + self.__session_bus = QDBusConnection.sessionBus() + if self.__session_bus.isConnected(): + self.__dbus_available = True + print("D-Bus session bus connected") + else: + print("D-Bus not available") + + except Exception as e: + print(f"D-Bus not available: {e}.") def _ensure_interface(self): """Ensure we have a valid interface, creating one if needed.""" + if not self.__dbus_available: + print("D-Bus not available, cannot connect to JFJoch viewer") + return False + if self.__interface is None or not self.__interface.isValid(): if not self.__session_bus.isConnected(): print("Session bus not connected") @@ -35,6 +47,10 @@ class JFJochDBusClient(QObject): #TODO tidy up load functions @Slot(str) def load_file(self, name: str): + if not self.__dbus_available: + print("D-Bus not available, cannot load file in JFJoch viewer") + return + if name.startswith("http://"): path = name else: @@ -45,6 +61,10 @@ class JFJochDBusClient(QObject): @Slot(str, int) def load_image(self, name: str, number: int): + if not self.__dbus_available: + print("D-Bus not available, cannot load image in JFJoch viewer") + return + if name.startswith("http://"): path = name else: @@ -55,6 +75,10 @@ class JFJochDBusClient(QObject): @Slot() def load_online(self): + if not self.__dbus_available: + print("D-Bus not available, cannot load online data in JFJoch viewer") + return + if self._ensure_interface(): reply = self.__interface.call("LoadFile", "http://sls-gpu-001:8080", -1, 1)