1 from Screen import Screen
2 from Components.Sources.List import List
3 from Components.ActionMap import ActionMap
4 from Components.Header import Header
5 from Components.Button import Button
6 from Components.Label import Label
7 from Components.ProgressBar import ProgressBar
8 from Components.config import configfile
9 from Components.Sources.Clock import Clock
10 from Components.PluginComponent import plugins
12 from Tools.Directories import resolveFilename, SCOPE_SKIN
14 import xml.dom.minidom
15 from xml.dom import EMPTY_NAMESPACE
16 from skin import elementsWithTag
18 from Screens.Setup import Setup, getSetupTitle
20 from Tools import XMLTools
22 # <item text="TV-Mode">self.setModeTV()</item>
23 # <item text="Radio-Mode">self.setModeRadio()</item>
24 # <item text="File-Mode">self.setModeFile()</item>
25 # <item text="Sleep Timer"></item>
29 menufile = file(resolveFilename(SCOPE_SKIN, 'menu.xml'), 'r')
30 mdom = xml.dom.minidom.parseString(menufile.read())
34 def __init__(self, fnc, *args):
42 self.updatedMenuItems = {}
44 def addMenuItem(self, id, pos, text, module, screen):
45 if not self.updatedMenuAvailable(id):
46 self.updatedMenuItems[id] = []
47 self.updatedMenuItems[id].append([text, pos, module, screen])
49 def delMenuItem(self, id, pos, text, module, screen):
50 self.updatedMenuItems[id].remove([text, pos, module, screen])
52 def updatedMenuAvailable(self, id):
53 return self.updatedMenuItems.has_key(id)
55 def getUpdatedMenu(self, id):
56 return self.updatedMenuItems[id]
58 menuupdater = MenuUpdater()
60 class MenuSummary(Screen):
62 <screen position="0,0" size="132,64">
63 <widget name="MenuTitle" position="6,4" size="120,21" font="Regular;18" />
64 <widget name="MenuEntry" position="6,25" size="120,21" font="Regular;16" />
65 <widget source="CurrentTime" render="Label" position="56,46" size="82,18" font="Regular;16" >
66 <convert type="ClockToText">WithSeconds</convert>
70 def __init__(self, session, parent):
71 Screen.__init__(self, session)
72 self["MenuTitle"] = Label(parent.menu_title)
73 self["MenuEntry"] = Label("")
74 self["CurrentTime"] = Clock()
76 self.onShow.append(self.addWatcher)
77 self.onHide.append(self.removeWatcher)
80 self.parent["menu"].onSelectionChanged.append(self.selectionChanged)
81 self.selectionChanged()
83 def removeWatcher(self):
84 self.parent["menu"].onSelectionChanged.remove(self.selectionChanged)
86 def selectionChanged(self):
87 self["MenuEntry"].setText(self.parent["menu"].getCurrent()[0])
93 def okbuttonClick(self):
95 selection = self["menu"].getCurrent()
98 def execText(self, text):
101 def runScreen(self, arg):
102 # arg[0] is the module (as string)
103 # arg[1] is Screen inside this module
104 # plus possible arguments, as
105 # string (as we want to reference
106 # stuff which is just imported)
109 exec "from " + arg[0] + " import *"
111 self.openDialog(*eval(arg[1]))
113 def nothing(self): #dummy
116 def openDialog(self, *dialog): # in every layer needed
117 self.session.openWithCallback(self.menuClosed, *dialog)
119 def openSetup(self, dialog):
120 self.session.openWithCallback(self.menuClosed, Setup, dialog)
122 def addMenu(self, destList, node):
123 MenuTitle = _(node.getAttribute("text").encode("UTF-8") or "??")
124 x = node.getAttribute("flushConfigOnClose")
126 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
128 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
129 #TODO add check if !empty(node.childNodes)
130 destList.append((MenuTitle, a))
132 def menuClosedWithConfigFlush(self, *res):
134 self.menuClosed(*res)
136 def menuClosed(self, *res):
137 if len(res) and res[0]:
140 def addItem(self, destList, node):
141 item_text = node.getAttribute("text").encode("UTF-8")
142 for x in node.childNodes:
143 if x.nodeType != xml.dom.minidom.Element.nodeType:
145 elif x.tagName == 'screen':
146 module = x.getAttribute("module") or None
147 screen = x.getAttribute("screen") or None
154 module = "Screens." + module
158 # check for arguments. they will be appended to the
160 args = XMLTools.mergeText(x.childNodes)
161 screen += ", " + args
163 destList.append((_(item_text or "??"), boundFunction(self.runScreen, (module, screen))))
165 elif x.tagName == 'code':
166 destList.append((_(item_text or "??"), boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
168 elif x.tagName == 'setup':
169 id = x.getAttribute("id")
171 item_text = _(getSetupTitle(id)) + "..."
173 item_text = _(item_text)
174 destList.append((item_text, boundFunction(self.openSetup, id)))
177 destList.append((item_text,self.nothing))
180 def __init__(self, session, parent, childNode):
181 Screen.__init__(self, session)
186 for x in childNode: #walk through the actual nodelist
187 if x.nodeType != xml.dom.minidom.Element.nodeType:
189 elif x.tagName == 'item':
190 self.addItem(list, x)
192 elif x.tagName == 'menu':
193 self.addMenu(list, x)
195 elif x.tagName == "id":
196 menuID = x.getAttribute("val")
199 if menuID is not None:
201 if menuupdater.updatedMenuAvailable(menuID):
202 for x in menuupdater.getUpdatedMenu(menuID):
204 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
207 if menuID is not None:
209 for l in plugins.getPluginsForMenu(menuID):
210 list.append((l[0], boundFunction(l[1], self.session)))
212 self["menu"] = List(list)
214 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
216 "ok": self.okbuttonClick,
217 "cancel": self.closeNonRecursive,
218 "menu": self.closeRecursive
221 a = parent.getAttribute("title").encode("UTF-8") or None
223 a = _(parent.getAttribute("text").encode("UTF-8"))
224 self["title"] = Header(a)
227 def closeNonRecursive(self):
230 def closeRecursive(self):
233 def createSummary(self):
236 class MainMenu(Menu):
237 #add file load functions for the xml-file
239 def __init__(self, *x):
240 Menu.__init__(self, *x)
241 self.skinName = "Menu"