Today I tried a different implementation, and I got a a bit further.
The minimal example below successfully registers as Response signal in DBUS, and it is actually called, when the screenshot dialog is confirmed. But the response argument is always empty, which is no surprise, as the signal doesn't have a type signature. But if I try to set the (correct?) signature Response = QtCore.Signal(int, list), the signal is not triggered anymore.
Any ideas how to go on from here?
from PySide6 import QtDBus, QtWidgets, QtCore
class OrgFreedesktopPortalRequestInterface(QtDBus.QDBusAbstractInterface):
Response = QtCore.Signal()
def __init__(self, path, connection, parent):
super().__init__(
"org.freedesktop.portal.Desktop",
path,
"org.freedesktop.portal.Request",
connection,
parent,
)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self):
super().__init__()
self.setWindowTitle("DBUS Test")
bus = QtDBus.QDBusConnection.sessionBus()
base = bus.baseService()[1:].replace(".", "_")
token = "myapp"
object_path = f"/org/freedesktop/portal/desktop/request/{base}/{token}"
request = OrgFreedesktopPortalRequestInterface(object_path, bus, self)
request.Response.connect(self.gotSignal)
interface = QtDBus.QDBusInterface(
"org.freedesktop.portal.Desktop",
"/org/freedesktop/portal/desktop",
"org.freedesktop.portal.Screenshot",
)
reply = interface.call(
"Screenshot", "", {"interactive": False, "handle_token": token}
)
print("Interface call result:", reply)
def gotSignal(self, *args):
print("Signal received:", args)
if __name__ == "__main__":
app = QtWidgets.QApplication([])
window = MainWindow()
window.show()
app.exec()