1 from Screen import Screen
2 from Components.Sources.List import List
3 from Components.ActionMap import NumberActionMap
4 from Components.Sources.StaticText import StaticText
5 from Components.config import configfile
6 from Components.PluginComponent import plugins
7 from Components.config import config
8 from Components.SystemInfo import SystemInfo
10 from Tools.Directories import resolveFilename, SCOPE_SKIN
12 import xml.etree.cElementTree
14 from Screens.Setup import Setup, getSetupTitle
16 # <item text="TV-Mode">self.setModeTV()</item>
17 # <item text="Radio-Mode">self.setModeRadio()</item>
18 # <item text="File-Mode">self.setModeFile()</item>
19 # <item text="Sleep Timer"></item>
23 mdom = xml.etree.cElementTree.parse(resolveFilename(SCOPE_SKIN, 'menu.xml'))
26 def __init__(self, fnc, *args):
34 self.updatedMenuItems = {}
36 def addMenuItem(self, id, pos, text, module, screen, weight):
37 if not self.updatedMenuAvailable(id):
38 self.updatedMenuItems[id] = []
39 self.updatedMenuItems[id].append([text, pos, module, screen, weight])
41 def delMenuItem(self, id, pos, text, module, screen, weight):
42 self.updatedMenuItems[id].remove([text, pos, module, screen, weight])
44 def updatedMenuAvailable(self, id):
45 return self.updatedMenuItems.has_key(id)
47 def getUpdatedMenu(self, id):
48 return self.updatedMenuItems[id]
50 menuupdater = MenuUpdater()
52 class MenuSummary(Screen):
54 <screen position="0,0" size="132,64">
55 <widget source="parent.title" render="Label" position="6,4" size="120,21" font="Regular;18" />
56 <widget source="parent.menu" render="Label" position="6,25" size="120,21" font="Regular;16">
57 <convert type="StringListSelection" />
59 <widget source="global.CurrentTime" render="Label" position="56,46" size="82,18" font="Regular;16" >
60 <convert type="ClockToText">WithSeconds</convert>
68 def okbuttonClick(self):
70 selection = self["menu"].getCurrent()
71 if selection is not None:
74 def execText(self, text):
77 def runScreen(self, arg):
78 # arg[0] is the module (as string)
79 # arg[1] is Screen inside this module
80 # plus possible arguments, as
81 # string (as we want to reference
82 # stuff which is just imported)
85 exec "from " + arg[0] + " import *"
87 self.openDialog(*eval(arg[1]))
89 def nothing(self): #dummy
92 def openDialog(self, *dialog): # in every layer needed
93 self.session.openWithCallback(self.menuClosed, *dialog)
95 def openSetup(self, dialog):
96 self.session.openWithCallback(self.menuClosed, Setup, dialog)
98 def addMenu(self, destList, node):
99 requires = node.get("requires")
100 if requires and not SystemInfo.get(requires, False):
102 MenuTitle = _(node.get("text", "??").encode("UTF-8"))
103 entryID = node.get("entryID", "undefined")
104 weight = node.get("weight", 50)
105 x = node.get("flushConfigOnClose")
107 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node)
109 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node)
110 #TODO add check if !empty(node.childNodes)
111 destList.append((MenuTitle, a, entryID, weight))
113 def menuClosedWithConfigFlush(self, *res):
115 self.menuClosed(*res)
117 def menuClosed(self, *res):
121 def addItem(self, destList, node):
122 requires = node.get("requires")
123 if requires and not SystemInfo.get(requires, False):
125 item_text = node.get("text", "").encode("UTF-8")
126 entryID = node.get("entryID", "undefined")
127 weight = node.get("weight", 50)
129 if x.tag == 'screen':
130 module = x.get("module")
131 screen = x.get("screen")
138 module = "Screens." + module
142 # check for arguments. they will be appended to the
145 screen += ", " + args
147 destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen)), entryID, weight))
149 elif x.tag == 'code':
150 destList.append((_(item_text or "??"), boundFunction(self.execText, x.text), entryID, weight))
152 elif x.tag == 'setup':
155 item_text = _(getSetupTitle(id)) + "..."
157 item_text = _(item_text)
158 destList.append((item_text, boundFunction(self.openSetup, id), entryID, weight))
160 destList.append((item_text, self.nothing, entryID, weight))
163 def __init__(self, session, parent):
164 Screen.__init__(self, session)
169 for x in parent: #walk through the actual nodelist
171 item_level = int(x.get("level", 0))
172 if item_level <= config.usage.setup_level.index:
173 self.addItem(list, x)
175 elif x.tag == 'menu':
176 self.addMenu(list, x)
179 menuID = x.get("val")
182 if menuID is not None:
184 if menuupdater.updatedMenuAvailable(menuID):
185 for x in menuupdater.getUpdatedMenu(menuID):
187 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", ")), x[4]))
190 if menuID is not None:
192 for l in plugins.getPluginsForMenu(menuID):
193 # check if a plugin overrides an existing menu
196 if x[2] == plugin_menuid:
199 list.append((l[0], boundFunction(l[1], self.session), l[2], l[3] or 50))
201 # for the skin: first try a menu_<menuID>, then Menu
203 if menuID is not None:
204 self.skinName.append("menu_" + menuID)
205 self.skinName.append("Menu")
208 list.sort(key=lambda x: int(x[3]))
210 self["menu"] = List(list)
212 self["actions"] = NumberActionMap(["OkCancelActions", "MenuActions", "NumberActions"],
214 "ok": self.okbuttonClick,
215 "cancel": self.closeNonRecursive,
216 "menu": self.closeRecursive,
217 "1": self.keyNumberGlobal,
218 "2": self.keyNumberGlobal,
219 "3": self.keyNumberGlobal,
220 "4": self.keyNumberGlobal,
221 "5": self.keyNumberGlobal,
222 "6": self.keyNumberGlobal,
223 "7": self.keyNumberGlobal,
224 "8": self.keyNumberGlobal,
225 "9": self.keyNumberGlobal
228 a = parent.get("title", "").encode("UTF-8") or None
231 a = _(parent.get("text", "").encode("UTF-8"))
232 self["title"] = StaticText(a)
235 def keyNumberGlobal(self, number):
236 print "menu keyNumber:", number
240 if len(self["menu"].list) > number:
241 self["menu"].setIndex(number)
244 def closeNonRecursive(self):
247 def closeRecursive(self):
250 def createSummary(self):
253 class MainMenu(Menu):
254 #add file load functions for the xml-file
256 def __init__(self, *x):
257 self.skinName = "Menu"
258 Menu.__init__(self, *x)