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)
97 exec "from " + arg[0] + " import *"
99 self.openDialog(*eval(arg[1]))
101 def nothing(self): #dummy
104 def openDialog(self, *dialog): # in every layer needed
105 self.session.open(*dialog)
107 def openSetup(self, dialog):
108 self.session.open(Setup, dialog)
110 def addMenu(self, destList, node):
111 MenuTitle = _(getValbyAttr(node, "text"))
112 if MenuTitle != "": #check for title
113 a = boundFunction(self.session.open, Menu, node, node.childNodes)
114 #TODO add check if !empty(node.childNodes)
115 destList.append((MenuTitle, a))
117 def addItem(self, destList, node):
118 ItemText = _(getValbyAttr(node, "text"))
119 if ItemText != "": #check for name
120 for x in node.childNodes:
121 if x.nodeType != xml.dom.minidom.Element.nodeType:
123 elif x.tagName == 'screen':
124 module = getValbyAttr(x, "module")
125 screen = getValbyAttr(x, "screen")
131 module = "Screens." + module
133 # check for arguments. they will be appended to the
135 args = XMLTools.mergeText(x.childNodes)
136 screen += ", " + args
138 destList.append((ItemText, boundFunction(self.runScreen, (module, screen))))
140 elif x.tagName == 'code':
141 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
143 elif x.tagName == 'setup':
144 id = getValbyAttr(x, "id")
145 destList.append((ItemText, boundFunction(self.openSetup, id)))
148 destList.append((ItemText,self.nothing))
151 def __init__(self, session, parent, childNode):
152 Screen.__init__(self, session)
157 for x in childNode: #walk through the actual nodelist
158 if x.nodeType != xml.dom.minidom.Element.nodeType:
160 elif x.tagName == 'item':
161 self.addItem(list, x)
162 elif x.tagName == 'menu':
163 self.addMenu(list, x)
164 elif x.tagName == "id":
165 menuID = getValbyAttr(x, "val")
167 if menuupdater.updatedMenuAvailable(menuID):
168 for x in menuupdater.getUpdatedMenu(menuID):
169 list.append((x[0], boundFunction(self.runScreen, (x[1], x[2] + ", "))))
171 self["menu"] = MenuList(list)
173 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
175 "ok": self.okbuttonClick,
176 "cancel": self.close,
180 a = getValbyAttr(parent, "title")
181 if a == "": #if empty use name
182 a = _(getValbyAttr(parent, "text"))
183 self["title"] = Header(a)
185 class MainMenu(Menu):
186 #add file load functions for the xml-file
188 def __init__(self, *x):
189 Menu.__init__(self, *x)
190 self.skinName = "Menu"
192 def openDialog(self, dialog):
193 self.session.open(dialog)
195 def openSetup(self, dialog):
196 self.session.open(Setup, dialog)
199 print "set Mode to TV"
202 def setModeRadio(self):
203 print "set Mode to Radio"
206 def setModeFile(self):
207 print "set Mode to File"