Python
  Home arrow Python arrow Page 3 - Mobile Programming in Python using PyS...
Dev Shed Forums 
Administration  
AJAX  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Sun Developer Network 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Actuate Whitepapers 
VeriSign Whitepapers 
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? 
PYTHON

Mobile Programming in Python using PyS60: Getting Started
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 8
    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:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb 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

    Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here

    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


       · in this discussion I have introduced the basic concepts of PyS60 programming. Please...
       · Good article and a nice kick start for programming with PyS60. Waiting for this for...
       · Dear Sir: This is Raghu from E-security team , C-DAC .. Nice to see ur...
     

       

    PYTHON ARTICLES

    - SSH with Twisted
    - Mobile Programming in Python using PyS60: UI...
    - Python: Count on It
    - Python Strings: Spinning Yarns
    - Python: More Fun with Strings
    - Python: Stringing You Along
    - Python Operators
    - Bluetooth Programming in Python: Network Pro...
    - Python Sets
    - Python Conditionals, Lists, Dictionaries, an...
    - Python: Input and Variables
    - Introduction to Python Programming
    - Mobile Programming in Python using PyS60: Ge...
    - Bluetooth Programming using Python
    - Finishing the PyMailGUI Client: User Help To...





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway