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)
94 exec "from " + arg[0] + " import *"
96 self.openDialog(*eval(arg[1]))
98 def nothing(self): #dummy
101 def openDialog(self, *dialog): # in every layer needed
102 self.session.open(*dialog)
104 def openSetup(self, dialog):
105 self.session.openWithCallback(self.menuClosed, Setup, dialog)
107 def addMenu(self, destList, node):
108 MenuTitle = _(getValbyAttr(node, "text"))
109 if MenuTitle != "": #check for title
110 x = getValbyAttr(node, "flushConfigOnClose")
112 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
114 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
115 #TODO add check if !empty(node.childNodes)
116 destList.append((MenuTitle, a))
118 def menuClosedWithConfigFlush(self, *res):
120 self.menuClosed(*res)
122 def menuClosed(self, *res):
123 if len(res) and res[0]:
126 def addItem(self, destList, node):
127 ItemText = _(getValbyAttr(node, "text"))
128 if ItemText != "": #check for name
129 for x in node.childNodes:
130 if x.nodeType != xml.dom.minidom.Element.nodeType:
132 elif x.tagName == 'screen':
133 module = getValbyAttr(x, "module")
134 screen = getValbyAttr(x, "screen")
140 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((ItemText, boundFunction(self.runScreen, (module, screen))))
149 elif x.tagName == 'code':
150 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
152 elif x.tagName == 'setup':
153 id = getValbyAttr(x, "id")
154 destList.append((ItemText, boundFunction(self.openSetup, id)))
157 destList.append((ItemText,self.nothing))
160 def __init__(self, session, parent, childNode):
161 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 = getValbyAttr(x, "val")
180 if menuupdater.updatedMenuAvailable(menuID):
181 for x in menuupdater.getUpdatedMenu(menuID):
183 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
187 self["menu"] = MenuList(list)
189 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
191 "ok": self.okbuttonClick,
192 "cancel": self.closeNonRecursive,
193 "menu": self.closeRecursive
196 a = getValbyAttr(parent, "title")
197 if a == "": #if empty use name
198 a = _(getValbyAttr(parent, "text"))
199 self["title"] = Header(a)
201 def closeNonRecursive(self):
204 def closeRecursive(self):
207 class MainMenu(Menu):
208 #add file load functions for the xml-file
210 def __init__(self, *x):
211 Menu.__init__(self, *x)
212 self.skinName = "Menu"
214 def openDialog(self, dialog):
215 self.session.open(dialog)
217 def openSetup(self, dialog):
218 self.session.open(Setup, dialog)
221 print "set Mode to TV"
224 def setModeRadio(self):
225 print "set Mode to Radio"
228 def setModeFile(self):
229 print "set Mode to File"