Revision as of 11:46, 26 December 2008 by croozeus (Talk | contribs)

Archived:Dynamic Menus in PySymbian

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Nokia N95, Nokia E90
Platform(s): S60 1st Edition, S60 2nd Edition, S60 3rd Edition
Keywords: UI
Created: (25 Aug 2008)
Last edited: croozeus (26 Dec 2008)


The code below shows a method that can be used to change your menu dynamically in PyS60, depending on some preconditions that may change in your application in the course of its execution:

Code Snippet

Class Application:
def UpdateMenu(self):
def HasWaypoints():
return len(self.waypoints) > 0
def HasTracks():
return len(self.tracks) > 0
def HasOpenTracks():
return len(self.opentracks) > 0
def HasMaps():
return len(self.maps) > 0
def CreateMenu(items):
menu = []
for i in items:
if i[0]():
if len(menu) > 0:
return tuple(menu)
return None
items = [
( HasMaps, u'Open Map', self.OpenMap ),
( HasWaypoints, u'Monitor Waypoint', self.MonitorWaypoint ),
( HasTracks, u'Open Track', self.OpenTrack ),
( HasOpenTracks, u'Close Track', self.CloseTrack ),
menu = [
(u'About', self.About),
) ]
dyn_menu = CreateMenu(items)
if dyn_menu != None:
menu.append( (u'GPS', dyn_menu) )
appuifw.app.menu = menu
def CloseOpenTracks():
self.opentracks = []


Now whenever the precondition changes in the application, you can call UpdateMenu, and the menu is changed accordingly, as is demonstrated in the CloseOpenTracks method.

49 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.