polychromatic thoughts……………..

September 6, 2008

MOBIVISION WRKSHOP DAY2-PYTHON

Filed under: linux — maniacmind @ 4:10 AM

Sorry guys for the delay in uploading the documentation…so without any further delay lets get started…………before that all the scripts done in class are uploaded on
http://www.esnips.com/web/shane2418sStuff
DAY 2
the day started with a brief revison and then we started with the following stuff…. firstly we started with pop up menu…..

import appuifw

# create a list with the content in []
L = [u"Python", u"Symbian", u"Mlab"]

# create the pop-up menu including the list of content
#and a label
# syntax--> appuifw.popup_menu(list , label)
test = appuifw.popup_menu(L, u"Select + press OK:")

# the variable test holds the indicator which list item (position in the list)
# has been selected
# trigger some action (here we print something)
if test == 0 :
    appuifw.note(u"Python, yeah", "info")
elif test == 1 :
    appuifw.note(u"Symbian, ok", "info")
elif test == 2 :
    appuifw.note(u"Mlab, cool students", "info")



well we hae seen single query earlier lets now see multiple query....
# This script creates 2 text input fields on one screen
# It uses the multi_query function of the appuifw module

import appuifw

# syntax-->  appuifw.multi_query(label1, label2)
data1,data2 = appuifw.multi_query(u"Type your first name:",u"Type your surname:")

# print the reuslts on the screen
  print data1
  print data2

Now lets move to the selection list…i.e a list from which we select single item

# This script executes a dialog  that allows the users to select an item
#in a list and returns the index (of the list) of the chosen item
#syntax --> appuifw.selection_list(choices=list , search_field=0 or 1)


import appuifw

# define the list of items (items must written in unicode! )
L = [u'cakewalk', u'com-port', u'computer', u'bluetooth', u'mobile', u'screen', u'camera', u'keys']

# create the selection list
index = appuifw.selection_list(choices=L , search_field=1)

# use the result of the selection to do some action
#(here we just print something)
if index == 0:
    print "cakewalk was selected"
else:
    print "thanks for choosing"

# the search_field=1 (set to 1) enables a search  for
# looking up items in the list. i.e to activate the find pane
# if search_field=0 no search pane is enabled.
selection list

selection list

After the selection list lets move on to other list called the multi -selection list there is two types of multi-selection lists:- i) with checkbox ii)with check mark

# 1. with checkbox:

import appuifw

# define the list of items (items must written in unicode!)

L = [u’cakewalk’, u’com-port’, u’computer’, u’bluetooth’, u’mobile’, u’screen’, u’keys’]

# create the multi-selection list with checkbox

index = appuifw.multi_selection_list(L , style=’checkbox’, search_field=1)

# create a new list (Lnew) that inlcudes only the selected items and print the new list (Lnew)

Lnew = index print Lnew

2.with check mark i

mport appuifw

# define the list of items (items must written in unicode!)

L = [u’cakewalk’, u’com-port’, u’computer’, u’bluetooth’, u’mobile’, u’screen’, u’camera’, u’keys’]

# create the multi-selection list

tuple = appuifw.multi_selection_list(L , style=’checkmark’, search_field=1)

# create a new list (Lnew) that inlcudes only the selected items and print the new list (Lnew)

Lnew = tuple print Lnew After that we moved on to the functions…i.e HOW TO DEFINE A FUNCTION AND HOW TO CALL IT

# defining a function :lets take an example here.....

import appuifw
function

function .eg+comments

Before moving on further i wou
ld like to explain about the exit key handler.. The exitkey handler gets activated when you press the right (exit) softkey. By assigning an extra function to the .exit_key_handler you can define what shall happen when it is pressed.

import appuifw
def quit():
     print "exit key pressed"
     app_lock.signal()
appuifw.app.exit_key_handler = quit
appuifw.app.title = u"First App!"
appuifw.note(u"Application is now running")
app_lock = e32.Ao_lock()
app_lock.wait()
print "Application exits"

Besides importing the familiar appuifw module, we also need a module named e32. This module offers many useful low-level utility objects and functions related to Symbian OS functionalities. Here we
need the object e32.Ao lock(). We define a new function, quit(), that takes care of shutting down
the application when the user presses the Exit key. Since we could have a number of functions to perform various tasks, we need to tell Python which function is dedicated to handling the Exit events.
This is done by assigning the function name (not its value) to the special appuifw.app.exit key handler variable. When the user presses the Exit key, the function that this variable refers to is called by
the UI framework. In many situations, Python expects you to provide a function name that is used to call the corresponding function when some event has occurred. Functions of this kind are called callback functions.

now lets see a python script
—————————————————————————————————————————————-

import appuifw
import e32 #importing e32 module

def exit_key_handler():
     app_lock.signal()    # stops the scheduler 

round = appuifw.Text()
round.set(u'hello')

# put the application screen size to full screen
appuifw.app.screen='full' #(a full screen)

# other options:
#appuifw.app.screen='normal' #(a normal screen with title pane and softkeys)
#appuifw.app.screen='large' #(only softkeys visible)

app_lock = e32.Ao_lock()  # create an instance of the active object 

appuifw.app.body = round

appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()   # starts a scheduler -> the script processes events (e.g. from the UI) until lock.signal() is  callled.

——————————————————————————————————————————————
here is another python script covered just try to understand it……….try to figure it out what’s happening i m not telling u…..(for any doubts leave a comment or mail me on 1988.shashank@gmail.com…)

import appuifw
import e32

appuifw.app.screen='large'

# create your application logic ...

def item1():
print "hello"

def subitem1():
print "aha"

def subitem2():
print "good"
#creating a menu and submenu
appuifw.app.menu = [(u"item 1", item1),
(u"Submenu 1", ((u"sub item 1", subitem1), (u"sub item 2", subitem2)))]

def exit_key_handler():
app_lock.signal()

appuifw.app.title = u"drawing"    #gives the title of the page

app_lock = e32.Ao_lock()

appuifw.app.body = ...

appuifw.app.exit_key_handler = exit_key_handler
app_lock.wait()

——————————————————————————————————————————————–
i think all the stuff till the second day is covered here if anything is missing please notify me remember

to error is human

will cover rest of the portion by sunday (7th sept,08please bear patience)

1 Comment »

  1. Thats great now just post this under tutorial section in Wiki.

    Comment by shubhendra — September 6, 2008 @ 7:42 AM | Reply


RSS feed for comments on this post. TrackBack URI

Leave a comment

Blog at WordPress.com.