Revision as of 13:54, 13 June 2012 by hamishwillee (Talk | contribs)

How to watch camera events on Maemo or MeeGo using Python?

From Nokia Developer Wiki
Jump to: navigation, search

This article provides a code snippet showing how to watch for camera events using Python on the Maemo platform.

Article Metadata
Created: hozano (29 Aug 2008)
Last edited: hamishwillee (13 Jun 2012)

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:

  1. camera_out: when the camera is pulled-out
  2. camera_in: when the camera is pulled-in
  3. camera_turned_out: when the camera is targeted to back
  4. 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    
def camera_out_cb(*args):
print "-- *camera out signal* received --"
# function called when Maemo camera is opened
def camera_in_cb(*args):
print "-- *camera in signal* received --"
# function called when Maemo camera is turned out
def camera_turned_out_cb(*args):
print "-- *camera turned out signal* received --"
# function called when Maemo camera is turned in
def camera_turned_in_cb(*args):
print "-- *camera turned in signal* received --"
# setting dbus main loop (dbus requires a main loop)
import dbus
from dbus.mainloop.glib import DBusGMainLoop
# getting bus
bus = dbus.SystemBus()
# Connecting the camera signals to callback functions
bus.add_signal_receiver(camera_out_cb, dbus_interface="com.nokia.ke_recv.camera_out")
bus.add_signal_receiver(camera_in_cb, dbus_interface="com.nokia.ke_recv.camera_in")
bus.add_signal_receiver(camera_turned_out_cb, dbus_interface="com.nokia.ke_recv.camera_turned_out")
bus.add_signal_receiver(camera_turned_in_cb, dbus_interface="com.nokia.ke_recv.camera_turned_in")
# Running the main loop
import gobject
loop = gobject.MainLoop()
17 page views in the last 30 days.