GUI: added more verbose error handling to JFJochDbusClient
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user