Author: | Simon McVittie |
---|---|
Contact: | simon.mcvittie@collabora.co.uk |
Organization: | Collabora Ltd |
Date: | 2006-11-23 |
The Byte constructor accepts either single-byte strings, or integers in the range 0 to 255.
There is no Variant type any more. Instead, the variant_level attribute on D-Bus types gives the number of variant wrappers in which it is contained; this is to remove ambiguity. For instance, calling this method:
@dbus.service.method('com.example', in_signature='v', out_signature='') def Print(self, variant): print repr(variant)
yields the following results:
# on the wire: Variant containing Int32 Int32(0, variant_level=1) # on the wire: Variant containing Variant containing Int32 Int32(0, variant_level=2)
Once an object of a D-Bus type has been constructed, its variant_level cannot be altered.
The D-Bus integer types (dbus.Int32, etc.) are properly range-checked.
The Array constructor takes arguments (iterable[, signature]) rather than (iterable[, type][, signature]); ditto for Dict.
Main loop handling is different - instead of the use_default_mainloop keyword argument to Bus and subclasses, there's now mainloop which takes an instance of dbus.mainloop.NativeMainLoop.
Alternatively, you can set a default main loop by calling dbus.set_default_main_loop() and passing it a NativeMainLoop, or by passing set_as_default=True to the factory function from which you obtained the native main loop.
The plan is that in a future version of dbus-python there will be an abstract base class dbus.mainloop.MainLoop (or something); when it's added, instances of its subclasses will be accepted wherever a NativeMainLoop instance is now. This will let you wrap main loops using a Python API. This will be used to implement SimpleMainLoop (a pure-Python main loop which can only do D-Bus) and a Twisted main-loop wrapper.
The only working mainloop implementation is (still) GLib; you can get a NativeMainLoop instance by:
from dbus.mainloop.glib import DBusGMainLoop my_native_main_loop = DBusGMainLoop(set_as_default=True)
The above is how the highly magical dbus.glib module is now implemented. At some point dbus.glib will be deprecated, since it's non-obvious, and pychecker will usually complain if you use it correctly!
At the moment the GLib main loop always uses the default main context; python-gobject will probably need to add some extra API before we can allow other main-contexts to be used.