Custom Search

Sunday, January 3, 2010

PyS60 Tutorial - Menus, Application's menu, Popup menu, Simple selection, list Multiselection list

PyS60 Tutorial - Menus, Application's menu, Popup menu, Simple selection, list Multiselection list

Menus

----------

Application's menu

Popup menu

Simple selection list

Multiselection list

# There are several kinds of menus in PyS60:

# The application's menu, triggered by pressing the left softkey

# A popup menu somewhat similar in aspect to the application's menu

# Selection lists, which can be simple or multiple and have the ability to search for items; useful if you have many items to put in the list

/************ Complete Source Code Start *************/

import appuifw, e32

def quit():

app_lock.signal()

appuifw.app.exit_key_handler=quit

def callback_A():print "A"

def callback_B():print "B"

def callback_C():print "C"

def callback_D():print "D"

#The application's menu

appuifw.app.menu=[(u"Item_A", callback_A), (u"Item_B", ((u"Item_C", callback_C), (u"Item_D", callback_D)))]

#Popup menu

i = appuifw.popup_menu([u"Item1", u"Item2"])

#Simple selection list

i =appuifw.selection_list([u"Item1", u"Item2"])

#Multiselection list

i = appuifw.multi_selection_list([u"Item1", u"Item2"], style='checkbox', search_field=1)

app_lock=e32.Ao_lock()

app_lock.wait()

/************ Complete Source Code End *************/

/*********** Description Start *************/

import appuifw, e32

# Define the exit function

def quit():

app_lock.signal()

appuifw.app.exit_key_handler=quit

# Defining fumctions callback_A, callback_B, callback_C and callback_D.

def callback_A():print "A"

def callback_B():print "B"

def callback_C():print "C"

def callback_D():print "D"

# The application's menu.

# Here we can select Item_A, or select Item_B in which case a list with Item_C and Item_D is shown.

# Here menu "Item_B" has submenus Item_C and Item_D.

# When we selecting the menu "Item_A" it call the callable object or function "callback_A()"

# When we selecting the menu "Item_B" it shows the menu Item_C and Item_D.

# Setting attribute "menu" of the "Application" type object "app".

appuifw.app.menu=[(u"Item_A", callback_A), (u"Item_B", ((u"Item_C", callback_C), (u"Item_D", callback_D)))]

# Popup menu

# Stores the index of the selected option in the variable i ; 0 for Item1, 1 for Item2 etc.

# calling the free function "popup_menu" of "appuifw" module.

i = appuifw.popup_menu([u"Item1", u"Item2"])

# Simple selection list

# Stores the index of the selected option in the variable i ; 0 for Item1, 1 for Item2 etc.

# calling the free function "selection_list" of "appuifw" module.

i=appuifw.selection_list([u"Item1", u"Item2"])

# Multiselection list

# Shows a list from which you can select multiple items, selected ones being marked; here you can also enable a search field.

# Returns a tuple of indexes (a pair of Unicode strings) of the chosenitems, or None if the selection is cancelled by the users.

# calling the free function "multi_selection_list" of "appuifw" module.

i=appuifw.multi_selection_list([u"Item1", u"Item2"], style='checkbox', search_field=1)

app_lock=e32.Ao_lock()

app_lock.wait()

/*********** Description End *************/

/*********** Note Start *************/

---------------------------------------------------

Menu can be:

# a list of (title, callback) pairs, where each pair describes an item in the application’s menu bar, or

# a list of (title, ((title, callback),...)) pairs, where the tuple of Unicode strings ((title, callback),...) creates a submenu.

title (Unicode) is the name of the item and callback the associated callable object(similar to function). The maximum

allowed number of items in a menu, or items in a submenu, or submenus in a menu is 30.

Example:

appuifw.app.menu = [(u"item 1", item1),

(u"Submenu 1", ((u"sub item 1", subitem1),

(u"sub item 2", subitem2) ))

]

----------------------------------------------------------

index popup_menu(list [, label])

A pop-up menu style dialog. list representing the menu contents can be a list of Unicode strings or a list of Unicode string

pairs (tuples). The resulting dialog list is then a single-style or a double-style list. A single-style list is shown in full; whereas

a double-style list shows the items one at a time. Returns None if the users cancel the operation. Return index of chosen menu.

----------------------------------------------------------

index selection_list(choices=list [, search_field=0])

Executes a dialog that allows the users to select a list item and returns the index of the chosen item, or None

if the selection is cancelled by the users. (choices=list [, search_field=0]) consists of keywords and values, where

# choices is a list of Unicode strings.

# search_field is 0 (disabled) by default and is optional. Setting it to 1 enables a search field (find pane) that facilitates

searching for items in long lists. If enabled, the search field appears after you press a letter key.

----------------------------------------------------------

(indexes) multi_selection_list(choices=list [, style='checkbox', search_field=0])

Executes a dialog that allows the users to select multiple list items. Returns a tuple of indexes (a pair of Unicode strings) of the chosen

items, or None if the selection is cancelled by the users. (choices=list [, style='checkmark', search_field=0])

consists of keywords and values, where

# choices is a list of Unicode strings.

# style is an optional string; the default value being 'checkbox'. If 'checkbox' is given, the list will be a checkbox list, where

empty checkboxes indicate what items can be marked. The other possible value that can be set for style is 'checkmark'.

If 'checkmark' is given, the list will be a markable list, which lists items but does not indicate specifically that items can be selected.

To select items on a markable list, use the Navigation key to browse the list and the Edit key to select an item. For example views on

checkbox and markable lists.

# search_field is 0 (disabled) by default and is optional. Setting it to 1 enables a search field (find pane) that facilitates searching

for items in long lists. If enabled, the search field is always visible with checkbox lists; with markable lists it appears by pressing a letter key.

Example:

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

----------------------------------------------------------

Here popup_menu, selection_list, multi_selection_list is a free functions functions that do not belong

to any class − are defined in the appuifw module.So we can directly call these functions using module name "appuifw".

----------------------------------------------------------

/*********** Note End *************/

No comments:

Post a Comment