Tue 19 Apr 2005
I started on the rewrite of the python bindings this weekend. Well it is not a total rewrite since I am using the old code as a basis and just changing the interface quite a bit. I think once things are done the code is going to be a lot cleaner and using it will be a lot more fluid (though it is currently easy to use already). I’ve gotten rid of some useless objects to make the binding of dbus object a bit more terse and I have also implemented the dbus.Interface object as well as defaulting to no interfaces for default objects. A big change has been the addition of async calls to the highlevel API. My next step is to implement the Introspectable interface so that objects can export introspection data. Then it is off to parsing the introspection data so that clients can send data in the correct format and provide documentation of the interfaces. I also need to get together with David and add back some of the functionality I initially chopped like ObjectTree. None of this is in CVS yet since I want to finish it up before I commit. Rest assured there has been a version tuple added so programmers can do checks in their code. The initial release will point dbus.version to (0, 40, 0). In the meantime here is some test code to give you an idea of what it will be like working with the new API’s:
import dbus
import gtk
bus = dbus.Bus.get_system()
#bind the /org/freedesktop/DBus from the org.freedesktop.DBus service name
#this object does not have an interface so all methods are available
obj = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
#wrap the object in the org.freedesktop.DBus interface
#only methods from this interface are available
iface = dbus.Interface(obj, 'org.freedesktop.DBus')
#call ListNames on the org.freedesktop.DBus interface
print iface.ListNames()
#switch to the org.freedesktop.DBus interface for this call only
print obj.ListNames(dbus_interface='org.freedesktop.DBus')
#call ListNames on the object without an interface
#if two interfaces both implement ListNames the behavior is undefined
print obj.ListNames()
#examples of calls being made wich takes arguments
#in these cases the org.freedesktop.DBus name is being passed in
print iface.NameHasOwner('org.freedesktop.DBus')
#see you can still use the built in keywords even when passing arguments
print obj.NameHasOwner('org.freedesktop.DBus', dbus_interface='org.freedesktop.DBus')
#define a couple of callbacks
def print_list(list):
print 'Here is your async reply:'
print list
def async_error_handler(e):
print 'There was an async error:'
print e
#examples of async calls
#these should succeed
obj.ListNames(reply_handler=print_list, error_handler=async_error_handler)
obj.ListNames(reply_handler=print_list, error_handler=async_error_handler, dbus_interface='org.freedesktop.DBus')
#this will error out
obj.Fail(reply_handler=print_list, error_handler=async_error_handler)
gtk.main()
[read this post in: ar de es fr it ja ko pt ru zh-CN ]