add 'weight' for menu entries (including plugins), so they can be sorted, patch by...
authorFelix Domke <tmbinc@elitedvb.net>
Sun, 7 Oct 2007 10:41:47 +0000 (10:41 +0000)
committerFelix Domke <tmbinc@elitedvb.net>
Sun, 7 Oct 2007 10:41:47 +0000 (10:41 +0000)
lib/python/Plugins/Extensions/MediaPlayer/plugin.py
lib/python/Plugins/Plugin.py
lib/python/Plugins/SystemPlugins/PositionerSetup/plugin.py
lib/python/Plugins/SystemPlugins/SatelliteEquipmentControl/plugin.py
lib/python/Plugins/SystemPlugins/Satfinder/plugin.py
lib/python/Plugins/SystemPlugins/SkinSelector/plugin.py
lib/python/Screens/Menu.py

index 7efd33e267198ec260f3fd47e8a836bc8cb89e82..019f2164d8e31acf27192e31d8a4ee7ce7bdc833 100644 (file)
@@ -707,7 +707,7 @@ def main(session, **kwargs):
 
 def menu(menuid, **kwargs):
        if menuid == "mainmenu":
-               return [(_("Media player"), main, "media_player")]
+               return [(_("Media player"), main, "media_player", None)]
        return []
 
 def filescan_open(list, session, **kwargs):
index b3886723e90e7c530a65b49113dc2cddaac91fa7..b01b9b8f5a879499881ea1dd5aa2aded9cdb0bb1 100644 (file)
@@ -22,7 +22,7 @@ class PluginDescriptor:
        WHERE_PLUGINMENU  = 2
        # argument: session, serviceref (currently selected)
        WHERE_MOVIELIST = 3
-       # argument: menuid. Fnc must return list with menuitems (3-tuple of name, fnc to call, entryid or None)
+       # argument: menuid. Fnc must return list with menuitems (4-tuple of name, fnc to call, entryid or None, weight or None)
        WHERE_MENU = 4
        
        # reason (0: start, 1: end)
index 457648104b95dca49ecd085d016f36a8ce1f850f..fccd2625b6d024ceb922d3e3f66c2fb90679878a 100644 (file)
@@ -569,7 +569,7 @@ def PositionerMain(session, **kwargs):
 
 def PositionerSetupStart(menuid, **kwargs):
        if menuid == "scan":
-               return [(_("Positioner setup"), PositionerMain, "positioner_setup")]
+               return [(_("Positioner setup"), PositionerMain, "positioner_setup", None)]
        else:
                return []
 
index 17f8fa2ebfeaad72f0643f5c656eba4ff4311eb7..6cf7c8fe9ba56284ac316012cd540a4513e0d66c 100644 (file)
@@ -61,7 +61,7 @@ def SecSetupStart(menuid):
        # only show if DVB-S frontends are available
        for slot in nimmgr.nim_slots:
                if slot.isCompatible("DVB-S"):
-                       return [(_("Satellite Equipment Setup"), SecSetupMain, "satellite_equipment_setup")]
+                       return [(_("Satellite Equipment Setup"), SecSetupMain, "satellite_equipment_setup", None)]
 
        return [ ]
 
index fc7855f8f3c57cde1e8dc082740a3615345c5d0c..50182a9e3b08c4528aaf42b30e93b5b14e6d3319 100644 (file)
@@ -272,7 +272,7 @@ def SatfinderMain(session, **kwargs):
 
 def SatfinderStart(menuid, **kwargs):
        if menuid == "scan":
-               return [(_("Satfinder"), SatfinderMain, "satfinder")]
+               return [(_("Satfinder"), SatfinderMain, "satfinder", None)]
        else:
                return []
 
index eeebf70498986f98699ff007d7d24364a9f0880c..5b29b0d534dce1e38529f3e057979170832230a1 100755 (executable)
@@ -131,7 +131,7 @@ def SkinSelMain(session, **kwargs):
 
 def SkinSelSetup(menuid, **kwargs):
        if menuid == "system":
-               return [("Skin...", SkinSelMain, "skin_selector")]
+               return [("Skin...", SkinSelMain, "skin_selector", None)]
        else:
                return []
 
index 2b8ac05d27a09884010262a66b56a5c29a2622de..bba640403f1f892af06f871d980f4a1bb3806a7b 100644 (file)
@@ -35,13 +35,13 @@ class MenuUpdater:
        def __init__(self):
                self.updatedMenuItems = {}
        
-       def addMenuItem(self, id, pos, text, module, screen):
+       def addMenuItem(self, id, pos, text, module, screen, weight):
                if not self.updatedMenuAvailable(id):
                        self.updatedMenuItems[id] = []
-               self.updatedMenuItems[id].append([text, pos, module, screen])
+               self.updatedMenuItems[id].append([text, pos, module, screen, weight])
        
-       def delMenuItem(self, id, pos, text, module, screen):
-               self.updatedMenuItems[id].remove([text, pos, module, screen])
+       def delMenuItem(self, id, pos, text, module, screen, weight):
+               self.updatedMenuItems[id].remove([text, pos, module, screen, weight])
        
        def updatedMenuAvailable(self, id):
                return self.updatedMenuItems.has_key(id)
@@ -102,13 +102,14 @@ class Menu(Screen):
        def addMenu(self, destList, node):
                MenuTitle = _(node.getAttribute("text").encode("UTF-8") or "??")
                entryID = node.getAttribute("entryID") or "undefined"
+               weight = node.getAttribute("weight") or 50
                x = node.getAttribute("flushConfigOnClose")
                if x:
                        a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
                else:
                        a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
                #TODO add check if !empty(node.childNodes)
-               destList.append((MenuTitle, a, entryID))
+               destList.append((MenuTitle, a, entryID, weight))
 
        def menuClosedWithConfigFlush(self, *res):
                configfile.save()
@@ -121,6 +122,7 @@ class Menu(Screen):
        def addItem(self, destList, node):
                item_text = node.getAttribute("text").encode("UTF-8")
                entryID = node.getAttribute("entryID") or "undefined"
+               weight = node.getAttribute("weight") or 50
                for x in node.childNodes:
                        if x.nodeType != xml.dom.minidom.Element.nodeType:
                                continue
@@ -142,10 +144,10 @@ class Menu(Screen):
                                args = XMLTools.mergeText(x.childNodes)
                                screen += ", " + args
 
-                               destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen)), entryID))
+                               destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen)), entryID, weight))
                                return
                        elif x.tagName == 'code':
-                               destList.append((_(item_text or "??"), boundFunction(self.execText, XMLTools.mergeText(x.childNodes)), entryID))
+                               destList.append((_(item_text or "??"), boundFunction(self.execText, XMLTools.mergeText(x.childNodes)), entryID, weight))
                                return
                        elif x.tagName == 'setup':
                                id = x.getAttribute("id")
@@ -153,9 +155,9 @@ class Menu(Screen):
                                        item_text = _(getSetupTitle(id)) + "..."
                                else:
                                        item_text = _(item_text)
-                               destList.append((item_text, boundFunction(self.openSetup, id), entryID))
+                               destList.append((item_text, boundFunction(self.openSetup, id), entryID, weight))
                                return
-               destList.append((item_text, self.nothing, entryID))
+               destList.append((item_text, self.nothing, entryID, weight))
 
 
        def __init__(self, session, parent, childNode):
@@ -182,13 +184,14 @@ class Menu(Screen):
                                if menuupdater.updatedMenuAvailable(menuID):
                                        for x in menuupdater.getUpdatedMenu(menuID):
                                                if x[1] == count:
-                                                       list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
+                                                       list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", ")), x[4]))
                                                        count += 1
 
                if menuID is not None:
                        # plugins
                        for l in plugins.getPluginsForMenu(menuID):
-                               list.append((l[0], boundFunction(l[1], self.session), l[2]))
+                               list.append((l[0], boundFunction(l[1], self.session), l[2], l[3] or 50))
+                                       
 
                # for the skin: first try a menu_<menuID>, then Menu
                self.skinName = [ ]
@@ -196,6 +199,9 @@ class Menu(Screen):
                        self.skinName.append("menu_" + menuID)
                self.skinName.append("Menu")
 
+               # Sort by Weight
+               list.sort(key=lambda x: int(x[3]))
+
                self["menu"] = List(list)
 
                self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],