Python
  Home arrow Python arrow Page 3 - Mobile Programming in Python using PyS60: Getting Started
Dev Shed Forums  
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Smartphone Development  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Mobile Linux  
App Generation ROI  
IBM® developerWorks  
Forums Sitemap  
E-Commerce Hosting  
Linux Web Hosting  
Managed Hosting  
Small Business Hosting  
VPS Hosting  
Weekly Newsletter

 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid  
Request Media Kit
Contact Us  
Site Map  
Privacy Policy  
Support  
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
Google.com  
PYTHON

Mobile Programming in Python using PyS60: Getting Started
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 11
    2007-10-17


    Table of Contents:
  • Mobile Programming in Python using PyS60: Getting Started
  • Dynamically loadable libraries or extensions
  • Accessing Services, Step By Step
  • PyS60 Programming in the Real World

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      error-file:tidyout.log Del.ici.ous error-file:tidyout.log Digg
      error-file:tidyout.log Blink error-file:tidyout.log Simpy
      error-file:tidyout.log Google error-file:tidyout.log Spurl
      error-file:tidyout.log Y! MyWeb error-file:tidyout.log Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article

     
     
    ADVERTISEMENT


    Mobile Programming in Python using PyS60: Getting Started - Accessing Services, Step By Step
    ( Page 3 of 4 )

    The ease of programming using Python reduces the steps required to access the different services. However, there are three steps that are always required. They are:

      1. Instantiating the object of the service.

      2. Setting the required properties.

      3. Calling the methods to access the required functionality.

    These steps are generic to not only the S60 platform but also to any mobile platform, including embedded Linux, which is another mobile platform. I will use the sound module as an example for all the steps.

    Instantiating the object of the service

    Most of the time this is the first step in accessing the service. This step is essential when working with built-in extensions. However, for most of the dynamically loadable extensions, objects are not required as their functionalities can be directly accessed. The reason for this is that the methods of the dynamically loadable modules are static. For example, to create a text field (the name of text field component is query) the statements would be

    input= query(u”Enter Text”,”Text”)

    On the other hand, to use sound module to load a file, one must simply call the open method of the Sound class. The open method is a static, so the object of the Sound class is not required. The following statement opens a .wav file named test.wav.

    Sound.open(“test.wav”)

     Setting the required attributes

    The next step is to set up the attributes of the object instantiated. If the service can be accessed through static methods, then attributes can also be set or accessed through static mutators (setters) or accessors (getters). As with all the classes of Python, the attributes can be set at the time of instantiating the object. For example, selection_list can be used to show a list of items to the user, from which he or she can make his or her choice. The option to show a search field can be set at instantiation. The following statements display a list of fonts available on the device and let the user select one of the available fonts.

    li =available_fonts()

    sl=selection_list(li,1)

    However, to set the volume of the Sound object one may simply call the set_volume() method, which is again a static method. The following statement sets the volume to 10.

    Sound.set_volume(10)


    Calling the methods to access the required functionality

    The last step is to call the required methods on the objects to access the services. If the object is a UI component then the ‘service’ will either be displaying some value to the user or getting some value from the user. If it were a device-based service such as Sound, then accessing the functionality would mean requesting the platform to either play or stop the audio file. For example, the query component returns the value entered by the user after initialization. Therefore, the instantiation returns the value entered by the user. The returned value can be displayed using note object. The following statements accept a string from the user and display it to the user

    data=entry(u”Enter your message:”, “text”)

    note(u”Your message was: “+data, “info”)

    If one needs to access the play service provided by Sound module, he or she has to just call the play() method of Sound class. The following statement just does that: 

    Sound.play()

    That completes the steps required to work with PyS60. One point to keep in mind is that the string being passed to the methods and constructors needs to be Unicode i.e. the string should be prefixed with “u” otherwise the string may not be displayed correctly. Next, I am going to develop a small application that would accept a path to a .wav file and then play it.



     
     
    >>> More Python Articles          >>> More By A.P.Rajshekhar
     

       

    PYTHON ARTICLES

    - Tuples and Other Python Object Types
    - The Dictionary Python Object Type
    - String and List Python Object Types
    - Introducing Python Object Types
    - Mobile Programming using PyS60: Advanced UI ...
    - Nested Functions in Python
    - Python Parameters, Functions and Arguments
    - Python Statements and Functions
    - Statements and Iterators in Python
    - Sequences and Sets in Python
    - Python Expressions and Operators
    - Dictionaries, Variables and Statements in Py...
    - Data Types in Python
    - The Python Language
    - SSH with Twisted





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek