How to watch camera events on Maemo or MeeGo using Python?
This article provides a code snippet showing how to watch for camera events using Python on the Maemo platform.
The N800 and N810 devices have a integrated camera that sends signals according to her events. These signals are sent to dbus, and can be watched by applications that watch it. For instance, the Maemo camera application displays a mirrored image ever that the camera is rotated to back, watching the "camera_turned_out/in" signals.
In this case, four camera signals can be watched:
- camera_out: when the camera is pulled-out
- camera_in: when the camera is pulled-in
- camera_turned_out: when the camera is targeted to back
- camera_turned_in: when the camera is targeted to front
The simple python example below shows how to watch the camera signals.
# function called when Maemo camera is closed
print "-- *camera out signal* received --"
# function called when Maemo camera is opened
print "-- *camera in signal* received --"
# function called when Maemo camera is turned out
print "-- *camera turned out signal* received --"
# function called when Maemo camera is turned in
print "-- *camera turned in signal* received --"
# setting dbus main loop (dbus requires a main loop)
from dbus.mainloop.glib import DBusGMainLoop
# getting bus
bus = dbus.SystemBus()
# Connecting the camera signals to callback functions
# Running the main loop
loop = gobject.MainLoop()