Talk:Dbus
From Navit's Wiki
I tried to make up some working minimal example in python to access navit via python.
#!/usr/bin/env python import dbus # 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.navit_project.navit", # Connection name "/org/navit_project/navit/default_navit" ) # Object's path # Introspection returns an XML document containing information # about the methods supported by an interface. print "Introspection data:" print remote_object.Introspect() iface = dbus.Interface(remote_object, dbus_interface="org.navit_project.navit") iter = iface.attr_iter() path = remote_object.get_attr_wi("navit",iter) navit = bus.get_object('org.navit_project.navit', path[1]) iface.attr_iter_destroy(iter) print "Zoom to Berlin, Germany" navit.set_center_by_string("geo: 13.383333 52.516667") iface2 = dbus.Interface(remote_object, dbus_interface="org.navit_project.navit.navit") iface2.set_attr("zoom", 1024)
This works but questions remain:
- Why is iface2 needed and navit.set_attr doesn't work ?
- The beginning is taken from https://wiki.python.org/moin/DbusExamples - is threading necessary ?
- How can be tested if an instance of navit is running ?
After the questions are answered I would find it useful to put this example on the page itself or is there a better place or a directory in the source tree with such examples ?
--C holtermann (talk) 18:40, 9 November 2013 (CET)