I could get it to work by converting the dict to a string, send it through dbus, then convert it back to a dict. Is there a better way to do this?
#!/usr/bin/python3 from PyQt5 import QtCore, QtDBus from PyQt5.QtCore import QObject, pyqtSlot import argparse import dbus import ast import sys class QDBusServer(QObject): def __init__(self): QObject.__init__(self) self.__dbusAdaptor = QDBusServerAdapter(self) class QDBusServerAdapter(QtDBus.QDBusAbstractAdaptor): QtCore.Q_CLASSINFO("D-Bus Interface", "com.qtpad.dbus") QtCore.Q_CLASSINFO("D-Bus Introspection", ' <interface name="com.qtpad.dbus">\n' ' <property name="name" type="s" access="read"/>\n' ' <method name="parse">\n' ' <arg direction="in" type="s" name="cmd"/>\n' ' </method>\n' ' </interface>\n') def __init__(self, parent): super().__init__(parent) @pyqtSlot(str, result=str) def parse(self, cmd): parseCli(cmd) def parseCli(args): # Convert the string back to a dict args = ast.literal_eval(args) for key in args: if args[key]: print(key + "=" + str(args[key])) if __name__ == '__main__': # Handle command line input parser = argparse.ArgumentParser() parser.add_argument("-a", "--action", help="execute one of the predefined action, as shown in the preferences menu", metavar='') args = parser.parse_args() # Convert namespace to dict, then dict to string cmd = vars(args) cmd = str(cmd) # Verify if an instance is already running try: bus = dbus.SessionBus().get_object("com.qtpad.dbus", "/cli") busIO = dbus.Interface(bus, "com.qtpad.dbus") # Send the command to the running instance, then quit busIO.parse(cmd) sys.exit(0) except dbus.exceptions.DBusException: print("Init of a new instance") # Start a new instance app = QtCore.QCoreApplication([]) bus = QtDBus.QDBusConnection.sessionBus() server = QDBusServer() bus.registerObject('/cli', server) bus.registerService('com.qtpad.dbus') parseCli(cmd) app.exec()