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 enigma import quitMainloop
11 import xml.dom.minidom
12 from xml.dom import EMPTY_NAMESPACE
13 from skin import elementsWithTag
15 from Screens.Setup import *
17 from Tools import XMLTools
21 screen["clock"] = Clock()
24 # <item text="TV-Mode">self.setModeTV()</item>
25 # <item text="Radio-Mode">self.setModeRadio()</item>
26 # <item text="File-Mode">self.setModeFile()</item>
27 # <item text="Scart">self.openDialog(ScartLoopThrough)</item>
28 # <item text="Sleep Timer"></item>
33 # first we search in the current path
34 menufile = file('data/menu.xml', 'r')
36 # if not found in the current path, we use the global datadir-path
37 menufile = file('/usr/share/enigma2/menu.xml', 'r')
38 mdom = xml.dom.minidom.parseString(menufile.read())
42 def getValbyAttr(x, attr):
43 for p in range(x.attributes.length):
44 a = x.attributes.item(p)
53 def __init__(self, fnc, *args):
61 self.updatedMenuItems = {}
63 def addMenuItem(self, id, text, module, screen):
64 if not self.updatedMenuAvailable(id):
65 self.updatedMenuItems[id] = []
66 self.updatedMenuItems[id].append([text, module, screen])
68 def delMenuItem(self, id, text, module, screen):
69 self.updatedMenuItems[id].remove([text, module, screen])
71 def updatedMenuAvailable(self, id):
72 return self.updatedMenuItems.has_key(id)
74 def getUpdatedMenu(self, id):
75 return self.updatedMenuItems[id]
77 menuupdater = MenuUpdater()
80 def okbuttonClick(self):
82 selection = self["menu"].getCurrent()
85 def execText(self, text):
88 def runScreen(self, arg):
89 # arg[0] is the module (as string)
90 # arg[1] is Screen inside this module
91 # plus possible arguments, as
92 # string (as we want to reference
93 # stuff which is just imported)
96 exec "from " + arg[0] + " import *"
98 self.openDialog(*eval(arg[1]))
100 def nothing(self): #dummy
103 def openDialog(self, *dialog): # in every layer needed
104 self.session.open(*dialog)
106 def openSetup(self, dialog):
107 self.session.open(Setup, dialog)
109 def addMenu(self, destList, node):
110 MenuTitle = _(getValbyAttr(node, "text"))
111 if MenuTitle != "": #check for title
112 a = boundFunction(self.session.open, Menu, node, node.childNodes)
113 #TODO add check if !empty(node.childNodes)
114 destList.append((MenuTitle, a))
116 def addItem(self, destList, node):
117 ItemText = _(getValbyAttr(node, "text"))
118 if ItemText != "": #check for name
119 for x in node.childNodes:
120 if x.nodeType != xml.dom.minidom.Element.nodeType:
122 elif x.tagName == 'screen':
123 module = "Screens." + getValbyAttr(x, "module")
124 screen = getValbyAttr(x, "screen")
129 # check for arguments. they will be appended to the
131 args = XMLTools.mergeText(x.childNodes)
132 screen += ", " + args
134 destList.append((ItemText, boundFunction(self.runScreen, (module, screen))))
136 elif x.tagName == 'code':
137 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
139 elif x.tagName == 'setup':
140 id = getValbyAttr(x, "id")
141 destList.append((ItemText, boundFunction(self.openSetup, id)))
144 destList.append((ItemText,self.nothing))
147 def __init__(self, session, parent, childNode):
148 Screen.__init__(self, session)
153 for x in childNode: #walk through the actual nodelist
154 if x.nodeType != xml.dom.minidom.Element.nodeType:
156 elif x.tagName == 'item':
157 self.addItem(list, x)
158 elif x.tagName == 'menu':
159 self.addMenu(list, x)
160 elif x.tagName == "id":
161 menuID = getValbyAttr(x, "val")
163 if menuupdater.updatedMenuAvailable(menuID):
164 for x in menuupdater.getUpdatedMenu(menuID):
165 list.append((x[0], boundFunction(self.runScreen, (x[1], x[2] + ", "))))
167 self["menu"] = MenuList(list)
169 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
171 "ok": self.okbuttonClick,
172 "cancel": self.close,
176 a = getValbyAttr(parent, "title")
177 if a == "": #if empty use name
178 a = _(getValbyAttr(parent, "text"))
179 self["title"] = Header(a)
181 class MainMenu(Menu):
182 #add file load functions for the xml-file
184 def __init__(self, *x):
185 Menu.__init__(self, *x)
186 self.skinName = "Menu"
188 def openDialog(self, dialog):
189 self.session.open(dialog)
191 def openSetup(self, dialog):
192 self.session.open(Setup, dialog)
195 print "set Mode to TV"
198 def setModeRadio(self):
199 print "set Mode to Radio"
202 def setModeFile(self):
203 print "set Mode to File"