2 from Components.MenuList import MenuList
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
10 from Tools.Directories import resolveFilename, SCOPE_SKIN
12 from enigma import quitMainloop
14 import xml.dom.minidom
15 from xml.dom import EMPTY_NAMESPACE
16 from skin import elementsWithTag
18 from Screens.Setup import *
20 from Tools import XMLTools
24 screen["clock"] = Clock()
27 # <item text="TV-Mode">self.setModeTV()</item>
28 # <item text="Radio-Mode">self.setModeRadio()</item>
29 # <item text="File-Mode">self.setModeFile()</item>
30 # <item text="Scart">self.openDialog(ScartLoopThrough)</item>
31 # <item text="Sleep Timer"></item>
35 menufile = file(resolveFilename(SCOPE_SKIN, 'menu.xml'), 'r')
36 mdom = xml.dom.minidom.parseString(menufile.read())
40 def getValbyAttr(x, attr):
41 for p in range(x.attributes.length):
42 a = x.attributes.item(p)
51 def __init__(self, fnc, *args):
59 self.updatedMenuItems = {}
61 def addMenuItem(self, id, pos, text, module, screen):
62 if not self.updatedMenuAvailable(id):
63 self.updatedMenuItems[id] = []
64 self.updatedMenuItems[id].append([text, pos, module, screen])
66 def delMenuItem(self, id, pos, text, module, screen):
67 self.updatedMenuItems[id].remove([text, pos, module, screen])
69 def updatedMenuAvailable(self, id):
70 return self.updatedMenuItems.has_key(id)
72 def getUpdatedMenu(self, id):
73 return self.updatedMenuItems[id]
75 menuupdater = MenuUpdater()
78 def okbuttonClick(self):
80 selection = self["menu"].getCurrent()
83 def execText(self, text):
86 def runScreen(self, arg):
87 # arg[0] is the module (as string)
88 # arg[1] is Screen inside this module
89 # plus possible arguments, as
90 # string (as we want to reference
91 # stuff which is just imported)
95 exec "from " + arg[0] + " import *"
97 self.openDialog(*eval(arg[1]))
99 def nothing(self): #dummy
102 def openDialog(self, *dialog): # in every layer needed
103 self.session.open(*dialog)
105 def openSetup(self, dialog):
106 self.session.openWithCallback(self.menuClosed, Setup, dialog)
108 def addMenu(self, destList, node):
109 MenuTitle = _(getValbyAttr(node, "text"))
110 if MenuTitle != "": #check for title
111 x = getValbyAttr(node, "flushConfigOnClose")
113 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
115 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
116 #TODO add check if !empty(node.childNodes)
117 destList.append((MenuTitle, a))
119 def menuClosedWithConfigFlush(self, *res):
121 self.menuClosed(*res)
123 def menuClosed(self, *res):
124 if len(res) and res[0]:
127 def addItem(self, destList, node):
128 ItemText = _(getValbyAttr(node, "text"))
129 if ItemText != "": #check for name
130 for x in node.childNodes:
131 if x.nodeType != xml.dom.minidom.Element.nodeType:
133 elif x.tagName == 'screen':
134 module = getValbyAttr(x, "module")
135 screen = getValbyAttr(x, "screen")
141 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((ItemText, boundFunction(self.runScreen, (module, screen))))
150 elif x.tagName == 'code':
151 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
153 elif x.tagName == 'setup':
154 id = getValbyAttr(x, "id")
155 destList.append((ItemText, boundFunction(self.openSetup, id)))
158 destList.append((ItemText,self.nothing))
161 def __init__(self, session, parent, childNode):
162 Screen.__init__(self, session)
168 for x in childNode: #walk through the actual nodelist
169 if x.nodeType != xml.dom.minidom.Element.nodeType:
171 elif x.tagName == 'item':
172 self.addItem(list, x)
174 elif x.tagName == 'menu':
175 self.addMenu(list, x)
177 elif x.tagName == "id":
178 menuID = getValbyAttr(x, "val")
181 if menuupdater.updatedMenuAvailable(menuID):
182 for x in menuupdater.getUpdatedMenu(menuID):
184 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
188 self["menu"] = MenuList(list)
190 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
192 "ok": self.okbuttonClick,
193 "cancel": self.closeNonRecursive,
194 "menu": self.closeRecursive
197 a = getValbyAttr(parent, "title")
198 if a == "": #if empty use name
199 a = _(getValbyAttr(parent, "text"))
200 self["title"] = Header(a)
202 def closeNonRecursive(self):
205 def closeRecursive(self):
208 class MainMenu(Menu):
209 #add file load functions for the xml-file
211 def __init__(self, *x):
212 Menu.__init__(self, *x)
213 self.skinName = "Menu"
215 def openDialog(self, dialog):
216 self.session.open(dialog)
218 def openSetup(self, dialog):
219 self.session.open(Setup, dialog)
222 print "set Mode to TV"
225 def setModeRadio(self):
226 print "set Mode to Radio"
229 def setModeFile(self):
230 print "set Mode to File"