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
8 from Tools.Directories import resolveFilename, SCOPE_SKIN
10 import xml.dom.minidom
12 from Screens.Setup import Setup, getSetupTitle
14 from Tools import XMLTools
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 menufile = file(resolveFilename(SCOPE_SKIN, 'menu.xml'), 'r')
24 mdom = xml.dom.minidom.parseString(menufile.read())
28 def __init__(self, fnc, *args):
36 self.updatedMenuItems = {}
38 def addMenuItem(self, id, pos, text, module, screen, weight):
39 if not self.updatedMenuAvailable(id):
40 self.updatedMenuItems[id] = []
41 self.updatedMenuItems[id].append([text, pos, module, screen, weight])
43 def delMenuItem(self, id, pos, text, module, screen, weight):
44 self.updatedMenuItems[id].remove([text, pos, module, screen, weight])
46 def updatedMenuAvailable(self, id):
47 return self.updatedMenuItems.has_key(id)
49 def getUpdatedMenu(self, id):
50 return self.updatedMenuItems[id]
52 menuupdater = MenuUpdater()
54 class MenuSummary(Screen):
56 <screen position="0,0" size="132,64">
57 <widget source="parent.title" render="Label" position="6,4" size="120,21" font="Regular;18" />
58 <widget source="parent.menu" render="Label" position="6,25" size="120,21" font="Regular;16">
59 <convert type="StringListSelection" />
61 <widget source="global.CurrentTime" render="Label" position="56,46" size="82,18" font="Regular;16" >
62 <convert type="ClockToText">WithSeconds</convert>
66 def __init__(self, session, parent):
67 Screen.__init__(self, session, parent)
73 def okbuttonClick(self):
75 selection = self["menu"].getCurrent()
78 def execText(self, text):
81 def runScreen(self, arg):
82 # arg[0] is the module (as string)
83 # arg[1] is Screen inside this module
84 # plus possible arguments, as
85 # string (as we want to reference
86 # stuff which is just imported)
89 exec "from " + arg[0] + " import *"
91 self.openDialog(*eval(arg[1]))
93 def nothing(self): #dummy
96 def openDialog(self, *dialog): # in every layer needed
97 self.session.openWithCallback(self.menuClosed, *dialog)
99 def openSetup(self, dialog):
100 self.session.openWithCallback(self.menuClosed, Setup, dialog)
102 def addMenu(self, destList, node):
103 MenuTitle = _(node.getAttribute("text").encode("UTF-8") or "??")
104 entryID = node.getAttribute("entryID") or "undefined"
105 weight = node.getAttribute("weight") or 50
106 x = node.getAttribute("flushConfigOnClose")
108 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
110 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
111 #TODO add check if !empty(node.childNodes)
112 destList.append((MenuTitle, a, entryID, weight))
114 def menuClosedWithConfigFlush(self, *res):
116 self.menuClosed(*res)
118 def menuClosed(self, *res):
119 if len(res) and res[0]:
122 def addItem(self, destList, node):
123 item_text = node.getAttribute("text").encode("UTF-8")
124 entryID = node.getAttribute("entryID") or "undefined"
125 weight = node.getAttribute("weight") or 50
126 for x in node.childNodes:
127 if x.nodeType != xml.dom.minidom.Element.nodeType:
129 elif x.tagName == 'screen':
130 module = x.getAttribute("module") or None
131 screen = x.getAttribute("screen") or None
138 module = "Screens." + module
142 # check for arguments. they will be appended to the
144 args = XMLTools.mergeText(x.childNodes)
145 screen += ", " + args
147 destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen)), entryID, weight))
149 elif x.tagName == 'code':
150 destList.append((_(item_text or "??"), boundFunction(self.execText, XMLTools.mergeText(x.childNodes)), entryID, weight))
152 elif x.tagName == 'setup':
153 id = x.getAttribute("id")
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, childNode):
164 Screen.__init__(self, session)
169 for x in childNode: #walk through the actual nodelist
170 if x.nodeType != xml.dom.minidom.Element.nodeType:
172 elif x.tagName == 'item':
173 self.addItem(list, x)
175 elif x.tagName == 'menu':
176 self.addMenu(list, x)
178 elif x.tagName == "id":
179 menuID = x.getAttribute("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 list.append((l[0], boundFunction(l[1], self.session), l[2], l[3] or 50))
196 # for the skin: first try a menu_<menuID>, then Menu
198 if menuID is not None:
199 self.skinName.append("menu_" + menuID)
200 self.skinName.append("Menu")
203 list.sort(key=lambda x: int(x[3]))
205 self["menu"] = List(list)
207 self["actions"] = NumberActionMap(["OkCancelActions", "MenuActions", "NumberActions"],
209 "ok": self.okbuttonClick,
210 "cancel": self.closeNonRecursive,
211 "menu": self.closeRecursive,
212 "1": self.keyNumberGlobal,
213 "2": self.keyNumberGlobal,
214 "3": self.keyNumberGlobal,
215 "4": self.keyNumberGlobal,
216 "5": self.keyNumberGlobal,
217 "6": self.keyNumberGlobal,
218 "7": self.keyNumberGlobal,
219 "8": self.keyNumberGlobal,
220 "9": self.keyNumberGlobal
223 a = parent.getAttribute("title").encode("UTF-8") or None
225 a = _(parent.getAttribute("text").encode("UTF-8"))
226 self["title"] = StaticText(a)
229 def keyNumberGlobal(self, number):
230 print "menu keyNumber:", number
234 if len(self["menu"].list) > number:
235 self["menu"].setIndex(number)
238 def closeNonRecursive(self):
241 def closeRecursive(self):
244 def createSummary(self):
247 class MainMenu(Menu):
248 #add file load functions for the xml-file
250 def __init__(self, *x):
251 self.skinName = "Menu"
252 Menu.__init__(self, *x)