Using the Easy API
Article Metadata
Contents |
Using the Easy API
Easy is a Python-based API designed to ease the development of maemo applications. The goal of Easy is to wrap up the complexity of accessing multimedia, network and desktop services by providing a high level Python modular API. This will be done through python's bindings and an abstraction layer on top of the low level components, such as GStreamer, D-Bus, and other libraries. Easy also offer a framework for rapid GUI development using python and pygtk.
Installing Easy
The installation of Easy can be made using the single-click install support, following these steps:
- Access this page from maemo browser and click here.
- Follows the instructions in the device screen.
Easy architecture
Nowadays, Easy presents an architecture with seven modules: camera, audio, radio, e-mail, contacts, bluetooth,and UI. Such modules use Python bindings to access GStreamer, D-Bus, BlueZ, Evolution, and so on. The Easy architecture is illustrated with a brief description of each module as follows.
Some modules of Easy are detailed below.
Audio
The Audio module encapsulates a set of functions to record, and to reproduce audio files. It also providing functions to get file duration, get current time position, change volume, and seeking control.
The code below uses the audio module to record an audio file and reproduce it:
>>> from easy import audio
>>> audio.record("./hello_world.wav", 3)
>>> audio.play ("./hello_world.wav")
The first line imports the audio module from easy API. The second one records the audio captured from maemo microphone during 3s and stores it in a file named "hello_world.wav". Finally, line 3 plays the audio recorded previously.
Camera
This module provides functions to control the camera of the maemo device, including recording, playing videos and taking snapshots.
A brief example of the usage of camera module is detailed below. This example starts the camera and records a video during 30s. Then, it stores the video in a "movie.avi" file:
>>> from easy import camera
>>> camera.start()
>>> camera.record("./movie.avi", 30)
The following code is another example in which the camera module is used to take a snapshot:
>>> from easy import camera
>>> camera.click("picture.jpg")
Contacts
This modules allows management of contacts stored in maemo. The example below describes how to create a contact and how to set its attributes.
>>> from easy import contact >>> new_contact = contact.create_contact() >>> new_contact.name = "Guido" >>> new_contact.family_name = "Rossum" >>> new_contact.email = "guido@python.org" >>> new_contact.nickname = "guido" >>> new_contact.gtalk = "guido@gmail.com"
Email module uses the smptlib to send e-mails. This module requires a SMTP server authentication. The example below describes how to send an email with attachments.
>>> from easy import e_mail
>>> my_email = e_mail.create_email()
>>> my_email.to = "guido@python.org"
>>> my_email.subject = "Easy released!"
>>> my_email.message = "Easy is up!"
>>> my_email.add_attachment("./easy.tar.gz")
>>> e_mail.connect("login", "password", "smtp_server")
>>> e_mail.send_mail(my_email)
Bluetooth
This module conceives functions to easily manipulate bluetooth using the LightBlue library. The example below sends a single file (hello.txt) to a bluetooth device found in the network.
>>> from easy import bluetooth
>>> bluetooth.finddevices()
[('00:11:9F:02:94:29', u'John', 14373378), ('00:12:62:F3:44:08', u'Smith', 9392130)]
>>> mac, channel, service = bluetooth.findservices('00:11:9F:02:94:29',
u'OBEX Object Push')[0]
>>> bluetooth.obex.sendfile(mac, channel, './hello.txt')
Radio
The Radio module provides a set of functions to reproduce broadcasted FM radios. These functions allow to tune a specific station and to search for available stations. The code example below starts the Radio module and tunes it to 93.1MHz frequency.
>>> from easy import radio >>> radio.start() >>> radio.tune(93100)
UI
The UI module encapsulates the Eagle project, creating an abstraction layer on top of GTK+. Thus, it is possible to create GTK-based graphical interfaces using high level widgets provided by Eagle. The code example below presents a small application with a graphical interface using the UI module, with two widgets: Entry and Button.
from easy.eagle import *
def user_input( app, wid, text ):
print app, wid, text
def set_text( app, wid ):
app[ "entry" ] = "some text"
App(
title="Type something or press the button",
center=(
Entry( id="entry", label="Input:", callback=user_input ),
Button( id="button", label="Change Text", callback=set_text ),
)
)
run()
The figure above illustrates the graphical interface with the Entry and Button widgets provided by Eagle.
Links
Some useful links to develop Easy applications are showed below:
- http://easy.garage.maemo.org - Easy project page, with tutorials and examples of Easy applications
- http://easy.garage.maemo.org/doc/index.html - Easy - API specification
- http://pymaemo.garage.maemo.org - Python for maemo (PyMaemo) project page
- http://gustavobarbieri.com.br/eagle/docs/eagle.html - Eagle project page




17 Sep
2009
This article provides the basic level of API knowledge of the Maemo platform. Easy is a python based API designed for the development of Maemo applications. Basically, it provides high level Python modular API.
Before studying this article, installation of Easy and Python for Maemo are required. A basic knowledge of the maemo and PySymbian are pre-requisite for developers to study this article.
In the article, the author has explained an architecture of Easy which contains seven modules:camera,audio,radio, e-mail,contacts,blue tooth and UI. In the article,the Easy architecture is illustrated with a brief description of each modules with code snippet.
The article is useful to the developers who wants to develop Maemo application using Python API.