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):
60 def okbuttonClick(self):
62 selection = self["menu"].getCurrent()
65 def execText(self, text):
68 def runScreen(self, arg):
69 # arg[0] is the module (as string)
70 # arg[1] is Screen inside this module
71 # plus possible arguments, as
72 # string (as we want to reference
73 # stuff which is just imported)
76 exec "from Screens." + arg[0] + " import *"
78 self.openDialog(*eval(arg[1]))
80 def nothing(self): #dummy
83 def openDialog(self, *dialog): # in every layer needed
84 self.session.open(*dialog)
86 def openSetup(self, dialog):
87 self.session.open(Setup, dialog)
89 def addMenu(self, destList, node):
90 MenuTitle = _(getValbyAttr(node, "text"))
91 if MenuTitle != "": #check for title
92 a = boundFunction(self.session.open, Menu, node, node.childNodes)
93 #TODO add check if !empty(node.childNodes)
94 destList.append((MenuTitle, a))
96 def addItem(self, destList, node):
97 ItemText = _(getValbyAttr(node, "text"))
98 if ItemText != "": #check for name
99 for x in node.childNodes:
100 if x.nodeType != xml.dom.minidom.Element.nodeType:
102 elif x.tagName == 'screen':
103 module = getValbyAttr(x, "module")
104 screen = getValbyAttr(x, "screen")
109 # check for arguments. they will be appended to the
111 args = XMLTools.mergeText(x.childNodes)
112 screen += ", " + args
114 destList.append((ItemText, boundFunction(self.runScreen, (module, screen))))
116 elif x.tagName == 'code':
117 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
119 elif x.tagName == 'setup':
120 id = getValbyAttr(x, "id")
121 destList.append((ItemText, boundFunction(self.openSetup, id)))
124 destList.append((ItemText,self.nothing))
127 def __init__(self, session, parent, childNode):
128 Screen.__init__(self, session)
132 for x in childNode: #walk through the actual nodelist
133 if x.nodeType != xml.dom.minidom.Element.nodeType:
135 elif x.tagName == 'item':
136 self.addItem(list, x)
137 elif x.tagName == 'menu':
138 self.addMenu(list, x)
140 self["menu"] = MenuList(list)
142 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
144 "ok": self.okbuttonClick,
145 "cancel": self.close,
149 a = getValbyAttr(parent, "title")
150 if a == "": #if empty use name
151 a = _(getValbyAttr(parent, "text"))
152 self["title"] = Header(a)
154 class MainMenu(Menu):
155 #add file load functions for the xml-file
157 def __init__(self, *x):
158 Menu.__init__(self, *x)
159 self.skinName = "Menu"
161 def openDialog(self, dialog):
162 self.session.open(dialog)
164 def openSetup(self, dialog):
165 self.session.open(Setup, dialog)
168 print "set Mode to TV"
171 def setModeRadio(self):
172 print "set Mode to Radio"
175 def setModeFile(self):
176 print "set Mode to File"