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")
101 if requires[0] == '!':
102 if SystemInfo.get(requires[1:], False):
104 elif not SystemInfo.get(requires, False):
106 MenuTitle = _(node.get("text", "??").encode("UTF-8"))
107 entryID = node.get("entryID", "undefined")
108 weight = node.get("weight", 50)
109 x = node.get("flushConfigOnClose")
111 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node)
113 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node)
114 #TODO add check if !empty(node.childNodes)
115 destList.append((MenuTitle, a, entryID, weight))
117 def menuClosedWithConfigFlush(self, *res):
119 self.menuClosed(*res)
121 def menuClosed(self, *res):
125 def addItem(self, destList, node):
126 requires = node.get("requires")
128 if requires[0] == '!':
129 if SystemInfo.get(requires[1:], False):
131 elif not SystemInfo.get(requires, False):
133 item_text = node.get("text", "").encode("UTF-8")
134 entryID = node.get("entryID", "undefined")
135 weight = node.get("weight", 50)
137 if x.tag == 'screen':
138 module = x.get("module")
139 screen = x.get("screen")
146 module = "Screens." + module
150 # check for arguments. they will be appended to the
153 screen += ", " + args
155 destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen)), entryID, weight))
157 elif x.tag == 'code':
158 destList.append((_(item_text or "??"), boundFunction(self.execText, x.text), entryID, weight))
160 elif x.tag == 'setup':
163 item_text = _(getSetupTitle(id)) + "..."
165 item_text = _(item_text)
166 destList.append((item_text, boundFunction(self.openSetup, id), entryID, weight))
168 destList.append((item_text, self.nothing, entryID, weight))
171 def __init__(self, session, parent):
172 Screen.__init__(self, session)
177 for x in parent: #walk through the actual nodelist
179 item_level = int(x.get("level", 0))
180 if item_level <= config.usage.setup_level.index:
181 self.addItem(list, x)
183 elif x.tag == 'menu':
184 self.addMenu(list, x)
187 menuID = x.get("val")
190 if menuID is not None:
192 if menuupdater.updatedMenuAvailable(menuID):
193 for x in menuupdater.getUpdatedMenu(menuID):
195 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", ")), x[4]))
198 if menuID is not None:
200 for l in plugins.getPluginsForMenu(menuID):
201 # check if a plugin overrides an existing menu
204 if x[2] == plugin_menuid:
207 list.append((l[0], boundFunction(l[1], self.session), l[2], l[3] or 50))
209 # for the skin: first try a menu_<menuID>, then Menu
211 if menuID is not None:
212 self.skinName.append("menu_" + menuID)
213 self.skinName.append("Menu")
216 list.sort(key=lambda x: int(x[3]))
218 self["menu"] = List(list)
220 self["actions"] = NumberActionMap(["OkCancelActions", "MenuActions", "NumberActions"],
222 "ok": self.okbuttonClick,
223 "cancel": self.closeNonRecursive,
224 "menu": self.closeRecursive,
225 "1": self.keyNumberGlobal,
226 "2": self.keyNumberGlobal,
227 "3": self.keyNumberGlobal,
228 "4": self.keyNumberGlobal,
229 "5": self.keyNumberGlobal,
230 "6": self.keyNumberGlobal,
231 "7": self.keyNumberGlobal,
232 "8": self.keyNumberGlobal,
233 "9": self.keyNumberGlobal
236 a = parent.get("title", "").encode("UTF-8") or None
239 a = _(parent.get("text", "").encode("UTF-8"))
240 self["title"] = StaticText(a)
243 def keyNumberGlobal(self, number):
244 print "menu keyNumber:", number
248 if len(self["menu"].list) > number:
249 self["menu"].setIndex(number)
252 def closeNonRecursive(self):
255 def closeRecursive(self):
258 def createSummary(self):
261 class MainMenu(Menu):
262 #add file load functions for the xml-file
264 def __init__(self, *x):
265 self.skinName = "Menu"
266 Menu.__init__(self, *x)