Example clients for wiican-service
By wiican revision 77 we have now a dbus session service that can run on demand when a client requires it. This still being a dbus api draft for wiican but fully functional as i’ve showed in yesterday post.
A full example as been commited, but let me expose some minor examples.
Behold! the most simple client example:
import dbus if __name__ == '__main__': bus = dbus.SessionBus() wiican_iface = dbus.Interface(bus.get_object ('org.gnome.Wiican', '/org/gnome/Wiican'), 'org.gnome.Wiican') wiican_iface.ConnectWiimote('', False) print 'Press 1+2 to connect wiimote'
In wiican_iface we got the Wiican dbus service interface proxy so the ConnectWiimote method could be called. Behind, a wminput will be launched in a thread, in this case, the two args means no config_file (so default mapping will be loaded) and daemon-mode off.
# The status codes from wiican.service import WC_BLUEZ_PRESENT, WC_UINPUT_PRESENT, WC_WIIMOTE_DISCOVERING # Check the current wiimote connection status before trying to connect cur_status = wiican_iface.GetStatus() if not cur_status && WC_UINPUT_PRESENT: print 'Not uinput module present' elif not cur_status & WC_BLUEZ_PRESENT: print 'Not bluetooth adapter present' elif cur_status & WC_WIIMOTE_DISCOVERING: print 'Wiimote still in use!'
Here is a way to know the wiimote status on-demand. The status property contains a bitwise xor operation of the WC_* constants.
import gobject from dbus.mainloop.glib import DBusGMainLoop # A callback to receive wiimote connection status changes def status_cb(new_status): # Only check if wiimote it's disconnected if not new_status & WC_WIIMOTE_DISCOVERING: print 'Wiimote its disconnected' DBusGMainLoop(set_as_default=True) wiican_iface.connect_to_signal('StatusChanged', status_cb, dbus_interface='org.gnome.Wiican') gobject.MainLoop().run()
And finally you could be noticed of events about wiimote connection status by binding a callback function to the StatusChanged signal.
The dbus api still in hard development, so this examples can not be taked as final but a proof of concept. Maybe i’ll fill a blueprint describing it in Wiican Launchpad site.
Debian packages (0.3.3)