1 from Screen import Screen
2 from Components.Sources.List import List
3 from Components.ActionMap import ActionMap
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):
39 if not self.updatedMenuAvailable(id):
40 self.updatedMenuItems[id] = []
41 self.updatedMenuItems[id].append([text, pos, module, screen])
43 def delMenuItem(self, id, pos, text, module, screen):
44 self.updatedMenuItems[id].remove([text, pos, module, screen])
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 x = node.getAttribute("flushConfigOnClose")
107 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
109 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
110 #TODO add check if !empty(node.childNodes)
111 destList.append((MenuTitle, a, entryID))
113 def menuClosedWithConfigFlush(self, *res):
115 self.menuClosed(*res)
117 def menuClosed(self, *res):
118 if len(res) and res[0]:
121 def addItem(self, destList, node):
122 item_text = node.getAttribute("text").encode("UTF-8")
123 entryID = node.getAttribute("entryID") or "undefined"
124 for x in node.childNodes:
125 if x.nodeType != xml.dom.minidom.Element.nodeType:
127 elif x.tagName == 'screen':
128 module = x.getAttribute("module") or None
129 screen = x.getAttribute("screen") or None
136 module = "Screens." + module
140 # check for arguments. they will be appended to the
142 args = XMLTools.mergeText(x.childNodes)
143 screen += ", " + args
145 destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen)), entryID))
147 elif x.tagName == 'code':
148 destList.append((_(item_text or "??"), boundFunction(self.execText, XMLTools.mergeText(x.childNodes)), entryID))
150 elif x.tagName == 'setup':
151 id = x.getAttribute("id")
153 item_text = _(getSetupTitle(id)) + "..."
155 item_text = _(item_text)
156 destList.append((item_text, boundFunction(self.openSetup, id), entryID))
158 destList.append((item_text, self.nothing, entryID))
161 def __init__(self, session, parent, childNode):
162 Screen.__init__(self, session)
167 for x in childNode: #walk through the actual nodelist
168 if x.nodeType != xml.dom.minidom.Element.nodeType:
170 elif x.tagName == 'item':
171 self.addItem(list, x)
173 elif x.tagName == 'menu':
174 self.addMenu(list, x)
176 elif x.tagName == "id":
177 menuID = x.getAttribute("val")
180 if menuID is not None:
182 if menuupdater.updatedMenuAvailable(menuID):
183 for x in menuupdater.getUpdatedMenu(menuID):
185 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
188 if menuID is not None:
190 for l in plugins.getPluginsForMenu(menuID):
191 list.append((l[0], boundFunction(l[1], self.session)))
193 # for the skin: first try a menu_<menuID>, then Menu
195 if menuID is not None:
196 self.skinName.append("menu_" + menuID)
197 self.skinName.append("Menu")
199 self["menu"] = List(list)
201 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
203 "ok": self.okbuttonClick,
204 "cancel": self.closeNonRecursive,
205 "menu": self.closeRecursive
208 a = parent.getAttribute("title").encode("UTF-8") or None
210 a = _(parent.getAttribute("text").encode("UTF-8"))
211 self["title"] = StaticText(a)
214 def closeNonRecursive(self):
217 def closeRecursive(self):
220 def createSummary(self):
223 class MainMenu(Menu):
224 #add file load functions for the xml-file
226 def __init__(self, *x):
227 self.skinName = "Menu"
228 Menu.__init__(self, *x)