Using the Easy API
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.
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.
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.
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.
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")
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 = "email@example.com" >>> new_contact.nickname = "guido" >>> new_contact.gtalk = "firstname.lastname@example.org"
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 = "email@example.com" >>> 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)
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') >>> bluetooth.obex.sendfile(mac, channel, './hello.txt')
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)
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.
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