DBus Python Bindings

Simon McVittie smcv at collabora.com
Tue Jul 23 12:41:22 UTC 2019


On Tue, 23 Jul 2019 at 12:32:41 +0200, John Mercouris wrote:
> "To connect D-Bus to this main loop, call
> ``dbus.mainloop.qt.DBusQtMainLoop`` instead of
> ``dbus.mainloop.glib.DBusGMainLoop``. Otherwise the Qt loop is used in
> exactly the same way as the GLib loop."

"Exactly the same way" is not quite true: you also have to install
whatever package provides the main loop integration, which is built
by PyQt.

At the time the tutorial was written, you wouldn't have been able to
iterate the Qt main loop from Python without using PyQt *anyway*, so the
tutorial probably assumed that if you had any interest in Python and Qt,
you'd already be using PyQt. Since then, the alternative Python <-> Qt
binding pyside has become available. I don't think pyside offers
equivalent dbus-python main loop glue, but I might be wrong.

The tutorial was correct for when it was written, but the world has
moved on since then, and you should probably be using dbus.mainloop.pyqt5
(Qt 5) instead of dbus.mainloop.qt (Qt 4, or possibly even Qt 3).

For example, in Debian/Ubuntu, there is a
python{,3}-dbus.mainloop.pyqt5{,-dbg} package to link dbus-python to the
Qt 5 main loop, or python{,3}-qt4-dbus{,-dbg} for Qt 4.

The Python bindings for Enlightenment also have (or had) their own main
loop glue module.

In typical Linux distribution builds of Qt, Qt's main loop is implemented
using the GLib main loop, so dbus.mainloop.glib would also work
(see <https://bugs.debian.org/802659> for background).

Please note the warning in dbus-python's README, particularly the first
line:

    dbus-python might not be the best D-Bus binding for you to use.

See the README for more about why. You might want to consider using QtDBus
via PyQt or pyside (or GDBus via PyGI) instead, and ignoring dbus-python.

Pull requests to update the tutorial to this decade would be welcome.

    smcv


More information about the dbus mailing list