×
Namespaces

Variants
Actions
Revision as of 08:15, 18 September 2012 by hamishwillee (Talk | contribs)

Archived:Dynamic Menus in PySymbian

From Nokia Developer Wiki
Jump to: navigation, search

This code snippet shows how to change menus dynamically in PySymbian.

Article Metadata
Tested with
Devices(s): Nokia N95, Nokia E90
Compatibility
Platform(s): S60 1st Edition, S60 2nd Edition, S60 3rd Edition
Platform Security
Capabilities: )
Article
Keywords: UI
Created: hurenkam (25 Aug 2008)
Last edited: hamishwillee (18 Sep 2012)

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]():
menu.append((i[1],i[2]))
if len(menu) > 0:
return tuple(menu)
else:
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 = []
self.UpdateMenu()

Note

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.

56 page views in the last 30 days.
×