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
8 from Components.config import configfile
9 from Components.Clock import Clock
11 from Tools.Directories import resolveFilename, SCOPE_SKIN
13 from enigma import quitMainloop
15 import xml.dom.minidom
16 from xml.dom import EMPTY_NAMESPACE
17 from skin import elementsWithTag
19 from Screens.Setup import *
21 from Tools import XMLTools
25 screen["clock"] = Clock()
28 # <item text="TV-Mode">self.setModeTV()</item>
29 # <item text="Radio-Mode">self.setModeRadio()</item>
30 # <item text="File-Mode">self.setModeFile()</item>
31 # <item text="Scart">self.openDialog(ScartLoopThrough)</item>
32 # <item text="Sleep Timer"></item>
36 menufile = file(resolveFilename(SCOPE_SKIN, 'menu.xml'), 'r')
37 mdom = xml.dom.minidom.parseString(menufile.read())
41 def getValbyAttr(x, attr):
42 for p in range(x.attributes.length):
43 a = x.attributes.item(p)
52 def __init__(self, fnc, *args):
60 self.updatedMenuItems = {}
62 def addMenuItem(self, id, pos, text, module, screen):
63 if not self.updatedMenuAvailable(id):
64 self.updatedMenuItems[id] = []
65 self.updatedMenuItems[id].append([text, pos, module, screen])
67 def delMenuItem(self, id, pos, text, module, screen):
68 self.updatedMenuItems[id].remove([text, pos, module, screen])
70 def updatedMenuAvailable(self, id):
71 return self.updatedMenuItems.has_key(id)
73 def getUpdatedMenu(self, id):
74 return self.updatedMenuItems[id]
76 menuupdater = MenuUpdater()
78 class MenuSummary(Screen):
80 <screen position="0,0" size="132,64">
81 <widget name="MenuTitle" position="0,4" size="132,21" font="Regular;18" />
82 <widget name="MenuEntry" position="0,25" size="132,21" font="Regular;16" />
83 <widget name="Clock" position="50,46" size="82,18" font="Regular;16" />
86 def __init__(self, session, parent):
87 Screen.__init__(self, session)
88 self["MenuTitle"] = Label(parent.menu_title)
89 self["MenuEntry"] = Label("")
90 self["Clock"] = Clock()
92 self.onShow.append(self.addWatcher)
93 self.onHide.append(self.removeWatcher)
96 self.parent["menu"].onSelectionChanged.append(self.selectionChanged)
97 self.selectionChanged()
99 def removeWatcher(self):
100 self.parent["menu"].onSelectionChanged.remove(self.selectionChanged)
102 def selectionChanged(self):
103 self["MenuEntry"].setText(self.parent["menu"].getCurrent()[0])
106 def okbuttonClick(self):
107 print "okbuttonClick"
108 selection = self["menu"].getCurrent()
111 def execText(self, text):
114 def runScreen(self, arg):
115 # arg[0] is the module (as string)
116 # arg[1] is Screen inside this module
117 # plus possible arguments, as
118 # string (as we want to reference
119 # stuff which is just imported)
122 exec "from " + arg[0] + " import *"
124 self.openDialog(*eval(arg[1]))
126 def nothing(self): #dummy
129 def openDialog(self, *dialog): # in every layer needed
130 self.session.open(*dialog)
132 def openSetup(self, dialog):
133 self.session.openWithCallback(self.menuClosed, Setup, dialog)
135 def addMenu(self, destList, node):
136 MenuTitle = _(getValbyAttr(node, "text"))
137 if MenuTitle != "": #check for title
138 x = getValbyAttr(node, "flushConfigOnClose")
140 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
142 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
143 #TODO add check if !empty(node.childNodes)
144 destList.append((MenuTitle, a))
146 def menuClosedWithConfigFlush(self, *res):
148 self.menuClosed(*res)
150 def menuClosed(self, *res):
151 if len(res) and res[0]:
154 def addItem(self, destList, node):
155 ItemText = _(getValbyAttr(node, "text"))
156 if ItemText != "": #check for name
157 for x in node.childNodes:
158 if x.nodeType != xml.dom.minidom.Element.nodeType:
160 elif x.tagName == 'screen':
161 module = getValbyAttr(x, "module")
162 screen = getValbyAttr(x, "screen")
168 module = "Screens." + module
170 # check for arguments. they will be appended to the
172 args = XMLTools.mergeText(x.childNodes)
173 screen += ", " + args
175 destList.append((ItemText, boundFunction(self.runScreen, (module, screen))))
177 elif x.tagName == 'code':
178 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
180 elif x.tagName == 'setup':
181 id = getValbyAttr(x, "id")
182 destList.append((ItemText, boundFunction(self.openSetup, id)))
185 destList.append((ItemText,self.nothing))
188 def __init__(self, session, parent, childNode):
189 Screen.__init__(self, session)
195 for x in childNode: #walk through the actual nodelist
196 if x.nodeType != xml.dom.minidom.Element.nodeType:
198 elif x.tagName == 'item':
199 self.addItem(list, x)
201 elif x.tagName == 'menu':
202 self.addMenu(list, x)
204 elif x.tagName == "id":
205 menuID = getValbyAttr(x, "val")
208 if menuupdater.updatedMenuAvailable(menuID):
209 for x in menuupdater.getUpdatedMenu(menuID):
211 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
215 self["menu"] = MenuList(list)
217 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
219 "ok": self.okbuttonClick,
220 "cancel": self.closeNonRecursive,
221 "menu": self.closeRecursive
224 a = getValbyAttr(parent, "title")
225 if a == "": #if empty use name
226 a = _(getValbyAttr(parent, "text"))
227 self["title"] = Header(a)
230 def closeNonRecursive(self):
233 def closeRecursive(self):
236 def createSummary(self):
239 class MainMenu(Menu):
240 #add file load functions for the xml-file
242 def __init__(self, *x):
243 Menu.__init__(self, *x)
244 self.skinName = "Menu"
246 def openDialog(self, dialog):
247 self.session.open(dialog)
249 def openSetup(self, dialog):
250 self.session.open(Setup, dialog)
253 print "set Mode to TV"
256 def setModeRadio(self):
257 print "set Mode to Radio"
260 def setModeFile(self):
261 print "set Mode to File"