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
9 from Tools.Directories import resolveFilename, SCOPE_SKIN
11 import xml.dom.minidom
13 from Screens.Setup import Setup, getSetupTitle
15 from Tools import XMLTools
17 # <item text="TV-Mode">self.setModeTV()</item>
18 # <item text="Radio-Mode">self.setModeRadio()</item>
19 # <item text="File-Mode">self.setModeFile()</item>
20 # <item text="Sleep Timer"></item>
24 menufile = file(resolveFilename(SCOPE_SKIN, 'menu.xml'), 'r')
25 mdom = xml.dom.minidom.parseString(menufile.read())
29 def __init__(self, fnc, *args):
37 self.updatedMenuItems = {}
39 def addMenuItem(self, id, pos, text, module, screen, weight):
40 if not self.updatedMenuAvailable(id):
41 self.updatedMenuItems[id] = []
42 self.updatedMenuItems[id].append([text, pos, module, screen, weight])
44 def delMenuItem(self, id, pos, text, module, screen, weight):
45 self.updatedMenuItems[id].remove([text, pos, module, screen, weight])
47 def updatedMenuAvailable(self, id):
48 return self.updatedMenuItems.has_key(id)
50 def getUpdatedMenu(self, id):
51 return self.updatedMenuItems[id]
53 menuupdater = MenuUpdater()
55 class MenuSummary(Screen):
57 <screen position="0,0" size="132,64">
58 <widget source="parent.title" render="Label" position="6,4" size="120,21" font="Regular;18" />
59 <widget source="parent.menu" render="Label" position="6,25" size="120,21" font="Regular;16">
60 <convert type="StringListSelection" />
62 <widget source="global.CurrentTime" render="Label" position="56,46" size="82,18" font="Regular;16" >
63 <convert type="ClockToText">WithSeconds</convert>
67 def __init__(self, session, parent):
68 Screen.__init__(self, session, parent)
74 def okbuttonClick(self):
76 selection = self["menu"].getCurrent()
79 def execText(self, text):
82 def runScreen(self, arg):
83 # arg[0] is the module (as string)
84 # arg[1] is Screen inside this module
85 # plus possible arguments, as
86 # string (as we want to reference
87 # stuff which is just imported)
90 exec "from " + arg[0] + " import *"
92 self.openDialog(*eval(arg[1]))
94 def nothing(self): #dummy
97 def openDialog(self, *dialog): # in every layer needed
98 self.session.openWithCallback(self.menuClosed, *dialog)
100 def openSetup(self, dialog):
101 self.session.openWithCallback(self.menuClosed, Setup, dialog)
103 def addMenu(self, destList, node):
104 MenuTitle = _(node.getAttribute("text").encode("UTF-8") or "??")
105 entryID = node.getAttribute("entryID") or "undefined"
106 weight = node.getAttribute("weight") or 50
107 x = node.getAttribute("flushConfigOnClose")
109 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
111 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
112 #TODO add check if !empty(node.childNodes)
113 destList.append((MenuTitle, a, entryID, weight))
115 def menuClosedWithConfigFlush(self, *res):
117 self.menuClosed(*res)
119 def menuClosed(self, *res):
120 if len(res) and res[0]:
123 def addItem(self, destList, node):
124 item_text = node.getAttribute("text").encode("UTF-8")
125 entryID = node.getAttribute("entryID") or "undefined"
126 weight = node.getAttribute("weight") or 50
127 for x in node.childNodes:
128 if x.nodeType != xml.dom.minidom.Element.nodeType:
130 elif x.tagName == 'screen':
131 module = x.getAttribute("module") or None
132 screen = x.getAttribute("screen") or None
139 module = "Screens." + module
143 # check for arguments. they will be appended to the
145 args = XMLTools.mergeText(x.childNodes)
146 screen += ", " + args
148 destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen)), entryID, weight))
150 elif x.tagName == 'code':
151 destList.append((_(item_text or "??"), boundFunction(self.execText, XMLTools.mergeText(x.childNodes)), entryID, weight))
153 elif x.tagName == 'setup':
154 id = x.getAttribute("id")
156 item_text = _(getSetupTitle(id)) + "..."
158 item_text = _(item_text)
159 destList.append((item_text, boundFunction(self.openSetup, id), entryID, weight))
161 destList.append((item_text, self.nothing, entryID, weight))
164 def __init__(self, session, parent, childNode):
165 Screen.__init__(self, session)
170 for x in childNode: #walk through the actual nodelist
171 if x.nodeType != xml.dom.minidom.Element.nodeType:
173 elif x.tagName == 'item':
174 item_level = int(x.getAttribute("level") or "0")
175 if item_level <= config.usage.setup_level.index:
176 self.addItem(list, x)
178 elif x.tagName == 'menu':
179 self.addMenu(list, x)
181 elif x.tagName == "id":
182 menuID = x.getAttribute("val")
185 if menuID is not None:
187 if menuupdater.updatedMenuAvailable(menuID):
188 for x in menuupdater.getUpdatedMenu(menuID):
190 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", ")), x[4]))
193 if menuID is not None:
195 for l in plugins.getPluginsForMenu(menuID):
196 list.append((l[0], boundFunction(l[1], self.session), l[2], l[3] or 50))
199 # for the skin: first try a menu_<menuID>, then Menu
201 if menuID is not None:
202 self.skinName.append("menu_" + menuID)
203 self.skinName.append("Menu")
206 list.sort(key=lambda x: int(x[3]))
208 self["menu"] = List(list)
210 self["actions"] = NumberActionMap(["OkCancelActions", "MenuActions", "NumberActions"],
212 "ok": self.okbuttonClick,
213 "cancel": self.closeNonRecursive,
214 "menu": self.closeRecursive,
215 "1": self.keyNumberGlobal,
216 "2": self.keyNumberGlobal,
217 "3": self.keyNumberGlobal,
218 "4": self.keyNumberGlobal,
219 "5": self.keyNumberGlobal,
220 "6": self.keyNumberGlobal,
221 "7": self.keyNumberGlobal,
222 "8": self.keyNumberGlobal,
223 "9": self.keyNumberGlobal
226 a = parent.getAttribute("title").encode("UTF-8") or None
228 a = _(parent.getAttribute("text").encode("UTF-8"))
229 self["title"] = StaticText(a)
232 def keyNumberGlobal(self, number):
233 print "menu keyNumber:", number
237 if len(self["menu"].list) > number:
238 self["menu"].setIndex(number)
241 def closeNonRecursive(self):
244 def closeRecursive(self):
247 def createSummary(self):
250 class MainMenu(Menu):
251 #add file load functions for the xml-file
253 def __init__(self, *x):
254 self.skinName = "Menu"
255 Menu.__init__(self, *x)