Python
  Home arrow Python arrow Page 4 - Mobile Programming in Python using PyS60: UI Controls
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: UI Controls
By: A.P.Rajshekhar
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: starstarstarstarstar / 2
    2008-02-27


    Table of Contents:
  • Mobile Programming in Python using PyS60: UI Controls
  • UI Controls: Query and Notes
  • The Note Control
  • PyS60 in 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: UI Controls - PyS60 in Real World
    ( Page 4 of 4 )

    Let's see how these controls can be used within an application. The application that's going to be developed is a simple guessing game. It will perform the following tasks:

    1. Choose a random number. 
    2. Ask the user to enter his or her guess.
    3. Compare and show the result.
    4. Ask if he or she will like to continue.

    So let's start. First the imports:

    from appuifw import *

    As you already know, the above statement imports all the classes within the appuifw module. Next, the application has to choose a random number. However, since this will be a repeating process until the user chooses to stop, choosing the random number will be within a loop. The loop will terminate only when the user says he or she would like to stop. The code is as follows:

    from appuifw import *


    continue_guess=true


    while continue_guess:

    guess_no=random()

    The loop will continue until continue_guess becomes false. Next, the application needs to accept the user’s guess. To accept the value, the query function will be used. The message will be “Enter your guess,” the type will be number (since decimals will not be allowed), and no initial value will be displayed. The value will be saved in user_guess variable. Here is the code:

    from appuifw import *


    continue_guess=true


    while continue_guess:

    guess_no=random()

    user_guess=query(u”Enter your guess”, ‘number’)

    Next comes the comparison and displaying the result functionality. First, the user_guess will be checked for validity (i.e. if the user clicked cancel, it would be null). If it is not null, then it will be compared with the guess_no, and the appropriate number will be displayed. If the user pressed cancel, a “You opted out” will be shown and the continue_guess will be set to false. Here is the code:


    from appuifw import *


    continue_guess=true


    while continue_guess:

    guess_no=random()

    user_guess=query(u”Enter your guess”, ‘number’)

    if user_guess is Null:

    note(u”You have opted out”)

    continue_guess=false

    elif user_guess<guess_no:

    note(u”Your guess is lesser than the goal”)

    elif user_guess>guess_no:

    note(u”Your guess is higher than the goal”)

    else:

    note(u”Congrats for excellent guess”)


    Next comes the code that asks the user whether or not to continue. The query box is shown to the user with “Enter Y to continue and N quit.” If Y is entered, the loop is continued, otherwise the application is exited.


    from appuifw import *


    continue_guess=true


    while continue_guess:

    guess_no=random()

    user_guess=query(u”Enter your guess”, ‘number’)

    if user_guess is Null:

    note(u”You have opted out”)

    continue_guess=false

    elif user_guess<guess_no:

    note(u”Your guess is lesser than the goal”)

    elif user_guess>guess_no:

    note(u”Your guess is higher than the goal”)

    else:

    note(u”Congrats for excellent guess”)


    user_choice=query(u”Enter Y to continue or N to quit”)

     

    if user_choice is Null or user_choice==’N’:

    continue_guess=false

    else:

    continue_guess=true


    That completes the application. In this discussion, the focus was on simple UI controls. The next part will discuss complex UI controls, such as forms. Till then…



     
     
    >>> 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 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek