Documentation on using DBus with Python via GOI is rather thin. I have found this example in GJS, but when rewritten straight into Python it didn’t work.

Example in GJS:

const GLib = imports.gi.GLib;
const Gio = imports.gi.Gio;

const DBusDaemonIface = <interface name='org.freedesktop.DBus'>
    <method name='ListNames'>
            <arg type='as' direction='out'/>
    </method>
</interface>;

const DBusDaemonProxy = Gio.DBusProxy.makeProxyWrapper(DBusDaemonIface);

let main = function () {
    var gdbusProxy = new DBusDaemonProxy(Gio.DBus.session,
        'org.freedesktop.DBus', '/org/freedesktop/DBus');
    gdbusProxy.ListNamesRemote(function(result, error){
      print(result);
      main_loop.quit();
    });

    var main_loop = new GLib.MainLoop(null, true);
    main_loop.run();
};

main();

The answer which helped was looking into https://git.gnome.org/browse/pygobject/tree/tests/test_gdbus.py which is a way better example of using Gio.DBusProxy machinery.

Example in Python:

   1 from gi.repository import Gio
   2 
   3 
   4       bus = Gio.bus_get_sync(Gio.BusType.SESSION, None)
   5       proxy = Gio.DBusProxy.new_sync(bus, Gio.DBusProxyFlags.NONE, None,
   6                                      'org.freedesktop.DBus',
   7                                      '/org/freedesktop/DBus',
   8                                      'org.freedesktop.DBus', None)
   9       res = proxy.call_sync('ListNames', None, Gio.DBusCallFlags.NO_AUTO_START,
  10                             500, None)
  11       print(res)

HowDoI/GDBusPython (last edited 2014-09-17 16:26:11 by MatejCepl)