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
9 from Tools.Directories import resolveFilename, SCOPE_SKIN
11 from enigma import quitMainloop
13 import xml.dom.minidom
14 from xml.dom import EMPTY_NAMESPACE
15 from skin import elementsWithTag
17 from Screens.Setup import *
19 from Tools import XMLTools
23 screen["clock"] = Clock()
26 # <item text="TV-Mode">self.setModeTV()</item>
27 # <item text="Radio-Mode">self.setModeRadio()</item>
28 # <item text="File-Mode">self.setModeFile()</item>
29 # <item text="Scart">self.openDialog(ScartLoopThrough)</item>
30 # <item text="Sleep Timer"></item>
34 menufile = file(resolveFilename(SCOPE_SKIN, 'menu.xml'), 'r')
35 mdom = xml.dom.minidom.parseString(menufile.read())
39 def getValbyAttr(x, attr):
40 for p in range(x.attributes.length):
41 a = x.attributes.item(p)
50 def __init__(self, fnc, *args):
58 self.updatedMenuItems = {}
60 def addMenuItem(self, id, pos, text, module, screen):
61 if not self.updatedMenuAvailable(id):
62 self.updatedMenuItems[id] = []
63 self.updatedMenuItems[id].append([text, pos, module, screen])
65 def delMenuItem(self, id, pos, text, module, screen):
66 self.updatedMenuItems[id].remove([text, pos, module, screen])
68 def updatedMenuAvailable(self, id):
69 return self.updatedMenuItems.has_key(id)
71 def getUpdatedMenu(self, id):
72 return self.updatedMenuItems[id]
74 menuupdater = MenuUpdater()
77 def okbuttonClick(self):
79 selection = self["menu"].getCurrent()
82 def execText(self, text):
85 def runScreen(self, arg):
86 # arg[0] is the module (as string)
87 # arg[1] is Screen inside this module
88 # plus possible arguments, as
89 # string (as we want to reference
90 # 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 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
111 #TODO add check if !empty(node.childNodes)
112 destList.append((MenuTitle, a))
114 def menuClosed(self, *res):
115 if len(res) and res[0]:
118 def addItem(self, destList, node):
119 ItemText = _(getValbyAttr(node, "text"))
120 if ItemText != "": #check for name
121 for x in node.childNodes:
122 if x.nodeType != xml.dom.minidom.Element.nodeType:
124 elif x.tagName == 'screen':
125 module = getValbyAttr(x, "module")
126 screen = getValbyAttr(x, "screen")
132 module = "Screens." + module
134 # check for arguments. they will be appended to the
136 args = XMLTools.mergeText(x.childNodes)
137 screen += ", " + args
139 destList.append((ItemText, boundFunction(self.runScreen, (module, screen))))
141 elif x.tagName == 'code':
142 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
144 elif x.tagName == 'setup':
145 id = getValbyAttr(x, "id")
146 destList.append((ItemText, boundFunction(self.openSetup, id)))
149 destList.append((ItemText,self.nothing))
152 def __init__(self, session, parent, childNode):
153 Screen.__init__(self, session)
159 for x in childNode: #walk through the actual nodelist
160 if x.nodeType != xml.dom.minidom.Element.nodeType:
162 elif x.tagName == 'item':
163 self.addItem(list, x)
165 elif x.tagName == 'menu':
166 self.addMenu(list, x)
168 elif x.tagName == "id":
169 menuID = getValbyAttr(x, "val")
172 if menuupdater.updatedMenuAvailable(menuID):
173 for x in menuupdater.getUpdatedMenu(menuID):
175 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
179 self["menu"] = MenuList(list)
181 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
183 "ok": self.okbuttonClick,
184 "cancel": self.closeNonRecursive,
185 "menu": self.closeRecursive
188 a = getValbyAttr(parent, "title")
189 if a == "": #if empty use name
190 a = _(getValbyAttr(parent, "text"))
191 self["title"] = Header(a)
193 def closeNonRecursive(self):
196 def closeRecursive(self):
199 class MainMenu(Menu):
200 #add file load functions for the xml-file
202 def __init__(self, *x):
203 Menu.__init__(self, *x)
204 self.skinName = "Menu"
206 def openDialog(self, dialog):
207 self.session.open(dialog)
209 def openSetup(self, dialog):
210 self.session.open(Setup, dialog)
213 print "set Mode to TV"
216 def setModeRadio(self):
217 print "set Mode to Radio"
220 def setModeFile(self):
221 print "set Mode to File"