dont use and show input power measurement (for rotor running detection),
[enigma2.git] / lib / python / Screens / Menu.py
index bba640403f1f892af06f871d980f4a1bb3806a7b..ce7f2ea6fe68523aed1fa32994634e58629fefb6 100644 (file)
@@ -1,9 +1,11 @@
 from Screen import Screen
 from Components.Sources.List import List
-from Components.ActionMap import ActionMap
+from Components.ActionMap import NumberActionMap
 from Components.Sources.StaticText import StaticText
 from Components.config import configfile
 from Components.PluginComponent import plugins
+from Components.config import config
+from Components.SystemInfo import SystemInfo
 
 from Tools.Directories import resolveFilename, SCOPE_SKIN
 
@@ -73,7 +75,8 @@ class Menu(Screen):
        def okbuttonClick(self):
                print "okbuttonClick"
                selection = self["menu"].getCurrent()
-               selection[1]()
+               if selection is not None:
+                       selection[1]()
 
        def execText(self, text):
                exec text
@@ -100,6 +103,9 @@ class Menu(Screen):
                self.session.openWithCallback(self.menuClosed, Setup, dialog)
 
        def addMenu(self, destList, node):
+               requires = node.getAttribute("requires")
+               if requires and not SystemInfo.get(requires, False):
+                       return
                MenuTitle = _(node.getAttribute("text").encode("UTF-8") or "??")
                entryID = node.getAttribute("entryID") or "undefined"
                weight = node.getAttribute("weight") or 50
@@ -120,6 +126,9 @@ class Menu(Screen):
                        self.close(True)
 
        def addItem(self, destList, node):
+               requires = node.getAttribute("requires")
+               if requires and not SystemInfo.get(requires, False):
+                       return
                item_text = node.getAttribute("text").encode("UTF-8")
                entryID = node.getAttribute("entryID") or "undefined"
                weight = node.getAttribute("weight") or 50
@@ -170,8 +179,11 @@ class Menu(Screen):
                        if x.nodeType != xml.dom.minidom.Element.nodeType:
                            continue
                        elif x.tagName == 'item':
-                               self.addItem(list, x)
-                               count += 1
+                               item_level = int(x.getAttribute("level") or "0")
+                               
+                               if item_level <= config.usage.setup_level.index:
+                                       self.addItem(list, x)
+                                       count += 1
                        elif x.tagName == 'menu':
                                self.addMenu(list, x)
                                count += 1
@@ -190,8 +202,13 @@ class Menu(Screen):
                if menuID is not None:
                        # plugins
                        for l in plugins.getPluginsForMenu(menuID):
+                               # check if a plugin overrides an existing menu
+                               plugin_menuid = l[2]
+                               for x in list:
+                                       if x[2] == plugin_menuid:
+                                               list.remove(x)
+                                               break
                                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 = [ ]
@@ -204,19 +221,37 @@ class Menu(Screen):
 
                self["menu"] = List(list)
 
-               self["actions"] = ActionMap(["OkCancelActions", "MenuActions"], 
+               self["actions"] = NumberActionMap(["OkCancelActions", "MenuActions", "NumberActions"],
                        {
                                "ok": self.okbuttonClick,
                                "cancel": self.closeNonRecursive,
-                               "menu": self.closeRecursive
+                               "menu": self.closeRecursive,
+                               "1": self.keyNumberGlobal,
+                               "2": self.keyNumberGlobal,
+                               "3": self.keyNumberGlobal,
+                               "4": self.keyNumberGlobal,
+                               "5": self.keyNumberGlobal,
+                               "6": self.keyNumberGlobal,
+                               "7": self.keyNumberGlobal,
+                               "8": self.keyNumberGlobal,
+                               "9": self.keyNumberGlobal
                        })
-               
+
                a = parent.getAttribute("title").encode("UTF-8") or None
                if a is None:
                        a = _(parent.getAttribute("text").encode("UTF-8"))
                self["title"] = StaticText(a)
                self.menu_title = a
 
+       def keyNumberGlobal(self, number):
+               print "menu keyNumber:", number
+               # Calculate index
+               number -= 1
+
+               if len(self["menu"].list) > number:
+                       self["menu"].setIndex(number)
+                       self.okbuttonClick()
+
        def closeNonRecursive(self):
                self.close(False)