1 from Screen import Screen
2 from Components.Sources.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.Sources.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
23 # <item text="TV-Mode">self.setModeTV()</item>
24 # <item text="Radio-Mode">self.setModeRadio()</item>
25 # <item text="File-Mode">self.setModeFile()</item>
26 # <item text="Scart">self.openDialog(ScartLoopThrough)</item>
27 # <item text="Sleep Timer"></item>
31 menufile = file(resolveFilename(SCOPE_SKIN, 'menu.xml'), 'r')
32 mdom = xml.dom.minidom.parseString(menufile.read())
36 def getValbyAttr(x, attr):
37 for p in range(x.attributes.length):
38 a = x.attributes.item(p)
47 def __init__(self, fnc, *args):
55 self.updatedMenuItems = {}
57 def addMenuItem(self, id, pos, text, module, screen):
58 if not self.updatedMenuAvailable(id):
59 self.updatedMenuItems[id] = []
60 self.updatedMenuItems[id].append([text, pos, module, screen])
62 def delMenuItem(self, id, pos, text, module, screen):
63 self.updatedMenuItems[id].remove([text, pos, module, screen])
65 def updatedMenuAvailable(self, id):
66 return self.updatedMenuItems.has_key(id)
68 def getUpdatedMenu(self, id):
69 return self.updatedMenuItems[id]
71 menuupdater = MenuUpdater()
73 class MenuSummary(Screen):
75 <screen position="0,0" size="132,64">
76 <widget name="MenuTitle" position="0,4" size="132,21" font="Regular;18" />
77 <widget name="MenuEntry" position="0,25" size="132,21" font="Regular;16" />
78 <widget source="CurrentTime" render="Label" position="50,46" size="82,18" font="Regular;16" >
79 <convert type="ClockToText">WithSeconds</convert>
83 def __init__(self, session, parent):
84 Screen.__init__(self, session)
85 self["MenuTitle"] = Label(parent.menu_title)
86 self["MenuEntry"] = Label("")
87 self["CurrentTime"] = Clock()
89 self.onShow.append(self.addWatcher)
90 self.onHide.append(self.removeWatcher)
93 self.parent["menu"].onSelectionChanged.append(self.selectionChanged)
94 self.selectionChanged()
96 def removeWatcher(self):
97 self.parent["menu"].onSelectionChanged.remove(self.selectionChanged)
99 def selectionChanged(self):
100 self["MenuEntry"].setText(self.parent["menu"].getCurrent()[0])
103 def okbuttonClick(self):
104 print "okbuttonClick"
105 selection = self["menu"].getCurrent()
108 def execText(self, text):
111 def runScreen(self, arg):
112 # arg[0] is the module (as string)
113 # arg[1] is Screen inside this module
114 # plus possible arguments, as
115 # string (as we want to reference
116 # stuff which is just imported)
119 exec "from " + arg[0] + " import *"
121 self.openDialog(*eval(arg[1]))
123 def nothing(self): #dummy
126 def openDialog(self, *dialog): # in every layer needed
127 self.session.open(*dialog)
129 def openSetup(self, dialog):
130 self.session.openWithCallback(self.menuClosed, Setup, dialog)
132 def addMenu(self, destList, node):
133 MenuTitle = _(getValbyAttr(node, "text"))
134 if MenuTitle != "": #check for title
135 x = getValbyAttr(node, "flushConfigOnClose")
137 a = boundFunction(self.session.openWithCallback, self.menuClosedWithConfigFlush, Menu, node, node.childNodes)
139 a = boundFunction(self.session.openWithCallback, self.menuClosed, Menu, node, node.childNodes)
140 #TODO add check if !empty(node.childNodes)
141 destList.append((MenuTitle, a))
143 def menuClosedWithConfigFlush(self, *res):
145 self.menuClosed(*res)
147 def menuClosed(self, *res):
148 if len(res) and res[0]:
151 def addItem(self, destList, node):
152 ItemText = _(getValbyAttr(node, "text"))
153 if ItemText != "": #check for name
154 for x in node.childNodes:
155 if x.nodeType != xml.dom.minidom.Element.nodeType:
157 elif x.tagName == 'screen':
158 module = getValbyAttr(x, "module")
159 screen = getValbyAttr(x, "screen")
165 module = "Screens." + module
167 # check for arguments. they will be appended to the
169 args = XMLTools.mergeText(x.childNodes)
170 screen += ", " + args
172 destList.append((ItemText, boundFunction(self.runScreen, (module, screen))))
174 elif x.tagName == 'code':
175 destList.append((ItemText, boundFunction(self.execText, XMLTools.mergeText(x.childNodes))))
177 elif x.tagName == 'setup':
178 id = getValbyAttr(x, "id")
179 destList.append((ItemText, boundFunction(self.openSetup, id)))
182 destList.append((ItemText,self.nothing))
185 def __init__(self, session, parent, childNode):
186 Screen.__init__(self, session)
192 for x in childNode: #walk through the actual nodelist
193 if x.nodeType != xml.dom.minidom.Element.nodeType:
195 elif x.tagName == 'item':
196 self.addItem(list, x)
198 elif x.tagName == 'menu':
199 self.addMenu(list, x)
201 elif x.tagName == "id":
202 menuID = getValbyAttr(x, "val")
205 if menuupdater.updatedMenuAvailable(menuID):
206 for x in menuupdater.getUpdatedMenu(menuID):
208 list.append((x[0], boundFunction(self.runScreen, (x[2], x[3] + ", "))))
212 self["menu"] = MenuList(list)
214 self["actions"] = ActionMap(["OkCancelActions", "MenuActions"],
216 "ok": self.okbuttonClick,
217 "cancel": self.closeNonRecursive,
218 "menu": self.closeRecursive
221 a = getValbyAttr(parent, "title")
222 if a == "": #if empty use name
223 a = _(getValbyAttr(parent, "text"))
224 self["title"] = Header(a)
227 def closeNonRecursive(self):
230 def closeRecursive(self):
233 def createSummary(self):
236 class MainMenu(Menu):
237 #add file load functions for the xml-file
239 def __init__(self, *x):
240 Menu.__init__(self, *x)
241 self.skinName = "Menu"
243 def openDialog(self, dialog):
244 self.session.open(dialog)
246 def openSetup(self, dialog):
247 self.session.open(Setup, dialog)
250 print "set Mode to TV"
253 def setModeRadio(self):
254 print "set Mode to Radio"
257 def setModeFile(self):
258 print "set Mode to File"