Join Now
Quality Rating:
  • Currently 0.0 / 5
(0.0 / 5 - 0 votes cast)
This page was last modified 07:21, 27 August 2008.

Dynamic Menus in PyS60

From Forum Nokia Wiki

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:

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()

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.

Related Discussions
Thread Thread Starter Forum Replies Last Post
Dynamic Setting List bernie31 General Symbian C++ 3 2005-07-21 10:21
Amora 1.0: new release savago Python 7 2008-04-27 01:42
Memories ~ Dbms, SyExpat, and ReAllocL? series60nubee General Symbian C++ 3 2006-04-03 21:50
translate app w/o source? davidmaxwaterman General Symbian C++ 4 2007-12-23 01:28
Push registry register problem oscarm Mobile Java General 4 2008-01-28 07:57
 
Powered by MediaWiki
RDF Facets: qfnZtopicQUqfnTopicZpythonQ qfnZtopicQUqfnTopicZseriesE5f60Q qfnZtypeQUqfnTypeZCommunityContentQ qfnZtypeQUqfnTypeZWebpageQ qfnZtypeQUqfnTypeZWikiContentQ qmarsZlanguageQUxhttpE3aE2fE2fswE2enokiaE2ecomE2flanguageE2d1E2fenX