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.dom.minidom
14 from Screens.Setup import Setup, getSetupTitle
16 from Tools import XMLTools
18 # <item text="TV-Mode">self.setModeTV()</item>
19 # <item text="Radio-Mode">self.setModeRadio()</item>
20 # <item text="File-Mode">self.setModeFile()</item>
21 # <item text="Sleep Timer"></item>
25 menufile = file(resolveFilename(SCOPE_SKIN, 'menu.xml'), 'r')
26 mdom = xml.dom.minidom.parseString(menufile.read())
30 def __init__(self, fnc, *args):
38 self.updatedMenuItems = {}
40 def addMenuItem(self, id, pos, text, module, screen, weight):
41 if not self.updatedMenuAvailable(id):
42 self.updatedMenuItems[id] = []
43 self.updatedMenuItems[id].append([text, pos, module, screen, weight])
45 def delMenuItem(self, id, pos, text, module, screen, weight):
46 self.updatedMenuItems[id].remove([text, pos, module, screen, weight])
48 def updatedMenuAvailable(self, id):
49 return self.updatedMenuItems.has_key(id)
51 def getUpdatedMenu(self, id):
52 return self.updatedMenuItems[id]
54 menuupdater = MenuUpdater()
56 class MenuSummary(Screen):
58 <screen position="0,0" size="132,64">
59 <widget source="parent.title" render="Label" position="6,4" size="120,21" font="Regular;18" />
60 <widget source="parent.menu" render="Label" position="6,25" size="120,21" font="Regular;16">
61 <convert type="StringListSelection" />
63 <widget source="global.CurrentTime" render="Label" position="56,46" size="82,18" font="Regular;16" >
64 <convert type="ClockToText">WithSeconds</convert>
68 def __init__(self, session, parent):
69 Screen.__init__(self, session, parent)
75 def okbuttonClick(self):
77 selection = self["menu"].getCurrent()
78 if selection is not None:
81 def execText(self, text):
84 def runScreen(self, arg):
85 # arg[0] is the module (as string)
86 # arg[1] is Screen inside this module
87 # plus possible arguments, as
88 # string (as we want to reference
89 # stuff which is just imported)
92 exec "from " + arg[0] + " import *"
94 self.openDialog(*eval(arg[1]))
96 def nothing(self): #dummy
99 def openDialog(self, *dialog): # in every layer needed
100 self.session.openWithCallback(self.menuClosed, *dialog)
102 def openSetup(self, dialog):
103 self.session.openWithCallback(self.menuClosed, Setup, dialog)
105 def addMenu(self, destList, node):
106 requires = node.getAttribute("requires")
107 if requires and not SystemInfo.get(requires, False):
109 MenuTitle = _(node.getAttribute("text").encode("UTF-8") or "??")
110 entryID = node.getAttribute("entryID") or "undefined"
111 weight = node.getAttribute("weight") or 50
112 x = node.getAttribute("flushConfigOnClose")
114 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
116 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
117 #TODO add check if !empty(node.childNodes)
118 destList.append((MenuTitle, a, entryID, weight))
120 def menuClosedWithConfigFlush(self, *res):
122 self.menuClosed(*res)
124 def menuClosed(self, *res):
125 if len(res) and res[0]:
128 def addItem(self, destList, node):
129 requires = node.getAttribute("requires")
130 if requires and not SystemInfo.get(requires, False):
132 item_text = node.getAttribute("text").encode("UTF-8")
133 entryID = node.getAttribute("entryID") or "undefined"
134 weight = node.getAttribute("weight") or 50
135 for x in node.childNodes:
136 if x.nodeType != xml.dom.minidom.Element.nodeType:
138 elif x.tagName == 'screen':
139 module = x.getAttribute("module") or None
140 screen = x.getAttribute("screen") or None
147 module = "Screens." + module
151 # check for arguments. they will be appended to the
153 args = XMLTools.mergeText(x.childNodes)
154 screen += ", " + args
156 destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen)), entryID, weight))
158 elif x.tagName == 'code':
159 destList.append((_(item_text or "??"), boundFunction(self.execText, XMLTools.mergeText(x.childNodes)), entryID, weight))
161 elif x.tagName == 'setup':
162 id = x.getAttribute("id")
164 item_text = _(getSetupTitle(id)) + "..."
166 item_text = _(item_text)
167 destList.append((item_text, boundFunction(self.openSetup, id), entryID, weight))
169 destList.append((item_text, self.nothing, entryID, weight))
172 def __init__(self, session, parent, childNode):
173 Screen.__init__(self, session)
178 for x in childNode: #walk through the actual nodelist
179 if x.nodeType != xml.dom.minidom.Element.nodeType:
181 elif x.tagName == 'item':
182 item_level = int(x.getAttribute("level") or "0")
184 if item_level <= config.usage.setup_level.index:
185 self.addItem(list, x)
187 elif x.tagName == 'menu':
188 self.addMenu(list, x)
190 elif x.tagName == "id":
191 menuID = x.getAttribute("val")
194 if menuID is not None:
196 if menuupdater.updatedMenuAvailable(menuID):
197 for x in menuupdater.getUpdatedMenu(menuID):
199 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", ")), x[4]))
202 if menuID is not None:
204 for l in plugins.getPluginsForMenu(menuID):
205 # check if a plugin overrides an existing menu
208 if x[2] == plugin_menuid:
211 list.append((l[0], boundFunction(l[1], self.session), l[2], l[3] or 50))
213 # for the skin: first try a menu_<menuID>, then Menu
215 if menuID is not None:
216 self.skinName.append("menu_" + menuID)
217 self.skinName.append("Menu")
220 list.sort(key=lambda x: int(x[3]))
222 self["menu"] = List(list)
224 self["actions"] = NumberActionMap(["OkCancelActions", "MenuActions", "NumberActions"],
226 "ok": self.okbuttonClick,
227 "cancel": self.closeNonRecursive,
228 "menu": self.closeRecursive,
229 "1": self.keyNumberGlobal,
230 "2": self.keyNumberGlobal,
231 "3": self.keyNumberGlobal,
232 "4": self.keyNumberGlobal,
233 "5": self.keyNumberGlobal,
234 "6": self.keyNumberGlobal,
235 "7": self.keyNumberGlobal,
236 "8": self.keyNumberGlobal,
237 "9": self.keyNumberGlobal
240 a = parent.getAttribute("title").encode("UTF-8") or None
242 a = _(parent.getAttribute("text").encode("UTF-8"))
243 self["title"] = StaticText(a)
246 def keyNumberGlobal(self, number):
247 print "menu keyNumber:", number
251 if len(self["menu"].list) > number:
252 self["menu"].setIndex(number)
255 def closeNonRecursive(self):
258 def closeRecursive(self):
261 def createSummary(self):
264 class MainMenu(Menu):
265 #add file load functions for the xml-file
267 def __init__(self, *x):
268 self.skinName = "Menu"
269 Menu.__init__(self, *x)