Differences between revisions 1 and 2
Revision 1 as of 2006-09-07 19:41:00
Size: 1941
Comment:
Revision 2 as of 2006-09-07 19:42:11
Size: 1889
Comment:
Deletions are marked like this. Additions are marked like this.
Line 31: Line 31:
print remote_object.Introspect(dbus_interface="org.freedesktop.DBus.Introspectable") print remote_object.Introspect()

The [http://www.freedesktop.org/wiki/Software_2fdbus D-Bus library] is a messaging library used by the GNOME desktop for interprocess communication.

There's a Python binding for it, but documentation is non-existent so I've collected these examples in hopes that they'll be useful and that people will update them as needed.

Warning: the D-Bus APIs change a lot, breaking code. These examples were run with version 0.60 of the Python interface (0.60-6ubuntu8, on Ubuntu Dapper); they probably won't run on other versions.

This [http://thaiopensource.org/development/suriyan/wiki/DbusNotes draft tutorial] is the clearest introduction to D-Bus that I've seen.

Introspection

# You must initialize the gobject/dbus support for threading
# before doing anything.
import gobject
gobject.threads_init()

from dbus import glib
glib.init_threads()

# Create a session bus.
import dbus
bus = dbus.SessionBus()

# Create an object that will proxy for a particular remote object.
remote_object = bus.get_object("org.freedesktop.DBus",
                               "/org/freedesktop/DBus")

# Introspection returns an XML document containing information
# about the methods supported by an interface.
print ("Introspection data:\n")
print remote_object.Introspect()

Output: {{{Introspection data:

<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd"> <node>

  • <interface name="org.freedesktop.DBus.Introspectable">

    • <method name="Introspect">

      • <arg name="data" direction="out" type="s"/>

      </method>

    </interface> <interface name="org.freedesktop.DBus">

    • <method name="RequestName">

      • <arg direction="in" type="s"/> <arg direction="in" type="u"/> <arg direction="out" type="u"/>

      </method>

  • ..

}}}

DbusExamples (last edited 2024-02-19 18:33:59 by Igo95862)

Unable to edit the page? See the FrontPage for instructions.