Namespaces

Variants
Actions

Please note that as of October 24, 2014, the Nokia Developer Wiki will no longer be accepting user contributions, including new entries, edits and comments, as we begin transitioning to our new home, in the Windows Phone Development Wiki. We plan to move over the majority of the existing entries over the next few weeks. Thanks for all your past and future contributions.

Archived:How to create menu with callback function that receives parameters

From Wiki
Jump to: navigation, search

Archived.pngAquivado: Este artigo foi arquivado, pois o conteúdo não é mais considerado relevante para se criar soluções comerciais atuais. Se você achar que este artigo ainda é importante, inclua o template {{ForArchiveReview|escreva a sua justificativa}}.

All PySymbian articles have been archived. PySymbian is no longer maintained by Nokia and is not guaranteed to work on more recent Symbian devices. It is not possible to submit apps to Nokia Store.

Article Metadata
Tested with
Devices(s): Nokia N96
Compatibility
Platform(s): S60 2nd Edition, S60 3rd Edition
Article
Keywords: appuifw, menu
Created: diegodobelo (14 Jan 2009)
Last edited: hamishwillee (31 May 2013)

Overview

The appuifw.app.menu receives a list of tuples.

Each tuple contains two elements.

  • The first element is a unicode that is the option name.
  • The second element is a function name that will be called when the option be selected.

The problem is that when passing parameters to a function, necessarily the function will be called and will return something (like None). In this case, when selecting an option, what will happen is this: something().


To solve the problem we need to create a function that receives parameters, creates an internal function (which uses the received parameters) and returns the internal function name. This is showed by the PySymbian code example below.

Code Snippet

#import modules
import appuifw, e32
 
#initial ball size
ball_size = 10
#define the menu callback function
def size(value):
#create an internal function which be returned
def internal_function():
global ball_size
ball_size += value
print ball_size
#return internal function name
return internal_function
 
#create the menu
appuifw.app.menu = []
#create menu items
option1 = (u"size up", size(2))
option2 = (u"size down", size(-2))
#append menu items to menu
appuifw.app.menu.append(option1)
appuifw.app.menu.append(option2)
 
#set up application exit
lock = e32.Ao_lock()
appuifw.app.exit_key_handler = lock.signal
lock.wait()

Postconditions

Following images show the outcome of above code.

Menu Items
Change in Ball Size
This page was last modified on 31 May 2013, at 01:03.
60 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×