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.open(Setup, dialog)
107 def addMenu(self, destList, node):
108 MenuTitle = _(getValbyAttr(node, "text"))
109 if MenuTitle != "": #check for title
110 a = boundFunction(self.session.open, Menu, node, node.childNodes)
111 #TODO add check if !empty(node.childNodes)
112 destList.append((MenuTitle, a))
114 def addItem(self, destList, node):
115 ItemText = _(getValbyAttr(node, "text"))
116 if ItemText != "": #check for name
117 for x in node.childNodes:
118 if x.nodeType != xml.dom.minidom.Element.nodeType:
120 elif x.tagName == 'screen':
121 module = getValbyAttr(x, "module")
122 screen = getValbyAttr(x, "screen")
128 module = "Screens." + module
130 # check for arguments. they will be appended to the
132 args = XMLTools.mergeText(x.childNodes)
133 screen += ", " + args
135 destList.append((ItemText, boundFunction(self.runScreen, (module, screen))))
137 elif x.tagName == 'code':
138 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
140 elif x.tagName == 'setup':
141 id = getValbyAttr(x, "id")
142 destList.append((ItemText, boundFunction(self.openSetup, id)))
145 destList.append((ItemText,self.nothing))
148 def __init__(self, session, parent, childNode):
149 Screen.__init__(self, session)
155 for x in childNode: #walk through the actual nodelist
156 if x.nodeType != xml.dom.minidom.Element.nodeType:
158 elif x.tagName == 'item':
159 self.addItem(list, x)
161 elif x.tagName == 'menu':
162 self.addMenu(list, x)
164 elif x.tagName == "id":
165 menuID = getValbyAttr(x, "val")
168 if menuupdater.updatedMenuAvailable(menuID):
169 for x in menuupdater.getUpdatedMenu(menuID):
171 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
175 self["menu"] = MenuList(list)
177 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
179 "ok": self.okbuttonClick,
180 "cancel": self.close,
184 a = getValbyAttr(parent, "title")
185 if a == "": #if empty use name
186 a = _(getValbyAttr(parent, "text"))
187 self["title"] = Header(a)
189 class MainMenu(Menu):
190 #add file load functions for the xml-file
192 def __init__(self, *x):
193 Menu.__init__(self, *x)
194 self.skinName = "Menu"
196 def openDialog(self, dialog):
197 self.session.open(dialog)
199 def openSetup(self, dialog):
200 self.session.open(Setup, dialog)
203 print "set Mode to TV"
206 def setModeRadio(self):
207 print "set Mode to Radio"
210 def setModeFile(self):
211 print "set Mode to File"