1 from Screen import Screen
5 from Screens.HelpMenu import HelpableScreen
6 from Components.config import config
7 from Components.Label import Label
8 from Components.Slider import Slider
9 from Components.ActionMap import NumberActionMap
10 from Components.MenuList import MenuList
11 from Components.ConfigList import ConfigList
12 from Components.Sources.List import List
14 from enigma import eTimer
16 from xml.sax import make_parser
17 from xml.sax.handler import ContentHandler
19 class WizardSummary(Screen):
21 <screen position="0,0" size="132,64">
22 <widget name="text" position="6,4" size="120,42" font="Regular;14" transparent="1" />
23 <widget source="parent.list" render="Label" position="6,25" size="120,21" font="Regular;16">
24 <convert type="StringListSelection" />
28 def __init__(self, session, parent):
29 Screen.__init__(self, session, parent)
31 #names = parent.skinName
32 #if not isinstance(names, list):
35 #self.skinName = [x + "_summary" for x in names ]
36 #self.skinName.append("Wizard")
37 #print "*************+++++++++++++++++****************++++++++++******************* WizardSummary", self.skinName
39 self["text"] = Label("")
40 self.onShow.append(self.setCallback)
42 def setCallback(self):
43 self.parent.setLCDTextCallback(self.setText)
45 def setText(self, text):
46 self["text"].setText(text)
48 class Wizard(Screen, HelpableScreen):
50 class parseWizard(ContentHandler):
51 def __init__(self, wizard):
52 self.isPointsElement, self.isReboundsElement = 0, 0
57 def createSummary(self):
58 print "WizardCreateSummary"
61 def startElement(self, name, attrs):
62 print "startElement", name
63 self.currContent = name
66 if attrs.has_key('id'):
67 id = str(attrs.get('id'))
71 if attrs.has_key('nextstep'):
72 nextstep = str(attrs.get('nextstep'))
75 if attrs.has_key('timeout'):
76 timeout = int(attrs.get('timeout'))
79 if attrs.has_key('timeoutaction'):
80 timeoutaction = str(attrs.get('timeoutaction'))
82 timeoutaction = 'nextpage'
84 if attrs.has_key('timeoutstep'):
85 timeoutstep = str(attrs.get('timeoutstep'))
88 self.wizard[self.lastStep] = {"id": id, "condition": "", "text": "", "timeout": timeout, "timeoutaction": timeoutaction, "timeoutstep": timeoutstep, "list": [], "config": {"screen": None, "args": None, "type": "" }, "code": "", "codeafter": "", "nextstep": nextstep}
89 elif (name == "text"):
90 self.wizard[self.lastStep]["text"] = string.replace(str(attrs.get('value')), "\\n", "\n")
91 elif (name == "displaytext"):
92 self.wizard[self.lastStep]["displaytext"] = string.replace(str(attrs.get('value')), "\\n", "\n")
93 elif (name == "list"):
94 if (attrs.has_key('type')):
95 if attrs["type"] == "dynamic":
96 self.wizard[self.lastStep]["dynamiclist"] = attrs.get("source")
97 #self.wizard[self.lastStep]["list"].append(("Hallo", "test"))
98 if (attrs.has_key("evaluation")):
100 self.wizard[self.lastStep]["listevaluation"] = attrs.get("evaluation")
101 if (attrs.has_key("onselect")):
102 self.wizard[self.lastStep]["onselect"] = attrs.get("onselect")
103 elif (name == "listentry"):
104 self.wizard[self.lastStep]["list"].append((str(attrs.get('caption')), str(attrs.get('step'))))
105 elif (name == "config"):
106 exec "from Screens." + str(attrs.get('module')) + " import *"
107 self.wizard[self.lastStep]["config"]["screen"] = eval(str(attrs.get('screen')))
108 if (attrs.has_key('args')):
110 self.wizard[self.lastStep]["config"]["args"] = str(attrs.get('args'))
111 self.wizard[self.lastStep]["config"]["type"] = str(attrs.get('type'))
112 elif (name == "code"):
113 if attrs.has_key('pos') and str(attrs.get('pos')) == "after":
114 self.codeafter = True
116 self.codeafter = False
117 elif (name == "condition"):
119 def endElement(self, name):
120 self.currContent = ""
123 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"].strip()
125 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
126 elif name == 'condition':
127 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"].strip()
129 print "Step number", self.lastStep, ":", self.wizard[self.lastStep]
131 def characters(self, ch):
132 if self.currContent == "code":
134 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"] + ch
136 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
137 elif self.currContent == "condition":
138 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"] + ch
140 def __init__(self, session, showSteps = True, showStepSlider = True, showList = True, showConfig = True):
141 Screen.__init__(self, session)
142 HelpableScreen.__init__(self)
144 self.stepHistory = []
147 parser = make_parser()
148 print "Reading " + self.xmlfile
149 wizardHandler = self.parseWizard(self.wizard)
150 parser.setContentHandler(wizardHandler)
151 if self.xmlfile[0] != '/':
152 parser.parse('/usr/share/enigma2/' + self.xmlfile)
154 parser.parse(self.xmlfile)
156 self.showSteps = showSteps
157 self.showStepSlider = showStepSlider
158 self.showList = showList
159 self.showConfig = showConfig
161 self.numSteps = len(self.wizard)
164 self.timeoutTimer = eTimer()
165 self.timeoutTimer.callback.append(self.timeoutCounterFired)
167 self["text"] = Label()
170 self["config"] = ConfigList([])
173 self["step"] = Label()
175 if self.showStepSlider:
176 self["stepslider"] = Slider(1, self.numSteps)
180 self["list"] = List(self.list, enableWrapAround = True)
181 self["list"].onSelectionChanged.append(self.selChanged)
182 #self["list"] = MenuList(self.list, enableWrapAround = True)
184 self.onShown.append(self.updateValues)
186 self.configInstance = None
188 self.lcdCallbacks = []
190 self["actions"] = NumberActionMap(["WizardActions", "NumberActions"],
198 "1": self.keyNumberGlobal,
199 "2": self.keyNumberGlobal,
200 "3": self.keyNumberGlobal,
201 "4": self.keyNumberGlobal,
202 "5": self.keyNumberGlobal,
203 "6": self.keyNumberGlobal,
204 "7": self.keyNumberGlobal,
205 "8": self.keyNumberGlobal,
206 "9": self.keyNumberGlobal,
207 "0": self.keyNumberGlobal
210 def setLCDTextCallback(self, callback):
211 self.lcdCallbacks.append(callback)
214 print "getting back..."
215 print "stepHistory:", self.stepHistory
216 if len(self.stepHistory) > 1:
217 self.currStep = self.stepHistory[-2]
218 self.stepHistory = self.stepHistory[:-2]
219 if self.currStep < 1:
221 print "currStep:", self.currStep
222 print "new stepHistory:", self.stepHistory
224 print "after updateValues stepHistory:", self.stepHistory
229 def getStepWithID(self, id):
230 print "getStepWithID:", id
232 for x in self.wizard:
233 if self.wizard[x]["id"] == id:
234 print "result:", count
237 print "result: nothing"
240 def finished(self, gotoStep = None, *args, **kwargs):
242 currStep = self.currStep
244 if self.updateValues not in self.onShown:
245 self.onShown.append(self.updateValues)
248 if (len(self.wizard[currStep]["evaluatedlist"]) > 0):
249 print "current:", self["list"].current
250 nextStep = self["list"].current[1]
251 if (self.wizard[currStep].has_key("listevaluation")):
252 exec("self." + self.wizard[self.currStep]["listevaluation"] + "('" + nextStep + "')")
254 self.currStep = self.getStepWithID(nextStep)
256 if (currStep == self.numSteps): # wizard finished
260 self.runCode(self.wizard[currStep]["codeafter"])
261 if self.wizard[currStep]["nextstep"] is not None:
262 self.currStep = self.getStepWithID(self.wizard[currStep]["nextstep"])
263 if gotoStep is not None:
264 self.currStep = self.getStepWithID(gotoStep)
268 print "Now: " + str(self.currStep)
273 currStep = self.currStep
276 if (self.wizard[currStep]["config"]["screen"] != None):
277 # TODO: don't die, if no run() is available
278 # there was a try/except here, but i can't see a reason
279 # for this. If there is one, please do a more specific check
280 # and/or a comment in which situation there is no run()
281 if callable(getattr(self.configInstance, "runAsync", None)):
282 self.onShown.remove(self.updateValues)
283 self.configInstance.runAsync(self.finished)
286 self.configInstance.run()
289 def keyNumberGlobal(self, number):
290 if (self.wizard[self.currStep]["config"]["screen"] != None):
291 self.configInstance.keyNumberGlobal(number)
295 if (self.wizard[self.currStep]["config"]["screen"] != None):
296 self.configInstance.keyLeft()
301 if (self.wizard[self.currStep]["config"]["screen"] != None):
302 self.configInstance.keyRight()
307 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
308 self["config"].instance.moveSelection(self["config"].instance.moveUp)
309 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
310 self["list"].selectPrevious()
311 if self.wizard[self.currStep].has_key("onselect"):
312 print "current:", self["list"].current
313 self.selection = self["list"].current[1]
314 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
315 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
320 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
321 self["config"].instance.moveSelection(self["config"].instance.moveDown)
322 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
323 #self["list"].instance.moveSelection(self["list"].instance.moveDown)
324 self["list"].selectNext()
325 if self.wizard[self.currStep].has_key("onselect"):
326 print "current:", self["list"].current
327 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
328 #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
329 self.selection = self["list"].current[1]
330 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
331 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
334 def selChanged(self):
337 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
338 self["config"].instance.moveSelection(self["config"].instance.moveUp)
339 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
340 if self.wizard[self.currStep].has_key("onselect"):
341 self.selection = self["list"].current[1]
342 print "self.selection:", self.selection
343 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
345 def resetCounter(self):
346 self.timeoutCounter = self.wizard[self.currStep]["timeout"]
348 def runCode(self, code):
353 def updateText(self, firstset = False):
354 text = _(self.wizard[self.currStep]["text"])
355 if text.find("[timeout]") != -1:
356 text = text.replace("[timeout]", str(self.timeoutCounter))
357 self["text"].setText(text)
360 self["text"].setText(text)
362 def updateValues(self):
363 print "Updating values in step " + str(self.currStep)
364 self.timeoutTimer.stop()
366 if self.configInstance is not None:
367 del self.configInstance["config"]
368 self.configInstance.doClose()
369 self.configInstance = None
371 self.condition = True
372 exec (self.wizard[self.currStep]["condition"])
374 if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
375 self.stepHistory.append(self.currStep)
376 print "wizard step:", self.wizard[self.currStep]
379 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
380 if self.showStepSlider:
381 self["stepslider"].setValue(self.currStep)
383 if self.wizard[self.currStep]["timeout"] is not None:
385 self.timeoutTimer.start(1000)
387 print "wizard text", _(self.wizard[self.currStep]["text"])
388 self.updateText(firstset = True)
389 if self.wizard[self.currStep].has_key("displaytext"):
390 displaytext = self.wizard[self.currStep]["displaytext"]
392 for x in self.lcdCallbacks:
395 self.runCode(self.wizard[self.currStep]["code"])
398 print "showing list,", self.currStep
399 for renderer in self.renderer:
400 rootrenderer = renderer
401 while renderer.source is not None:
402 print "self.list:", self["list"]
403 if renderer.source is self["list"]:
405 rootrenderer.instance.setZPosition(1)
406 renderer = renderer.source
408 #self["list"].instance.setZPosition(1)
410 if (self.wizard[self.currStep].has_key("dynamiclist")):
411 print "dynamic list, calling", self.wizard[self.currStep]["dynamiclist"]
412 newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
413 #self.wizard[self.currStep]["evaluatedlist"] = []
414 for entry in newlist:
415 #self.wizard[self.currStep]["evaluatedlist"].append(entry)
416 self.list.append(entry)
417 #del self.wizard[self.currStep]["dynamiclist"]
418 if (len(self.wizard[self.currStep]["list"]) > 0):
419 #self["list"].instance.setZPosition(2)
420 for x in self.wizard[self.currStep]["list"]:
421 self.list.append((_(x[0]), x[1]))
422 self.wizard[self.currStep]["evaluatedlist"] = self.list
423 self["list"].list = self.list
424 self["list"].index = 0
429 self["config"].instance.setZPosition(1)
430 if (self.wizard[self.currStep]["config"]["screen"] != None):
431 if self.wizard[self.currStep]["config"]["type"] == "standalone":
432 print "Type is standalone"
433 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
435 self["config"].instance.setZPosition(2)
436 print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
437 if self.wizard[self.currStep]["config"]["args"] == None:
438 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
440 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
441 self["config"].l.setList(self.configInstance["config"].list)
442 self.configInstance["config"].destroy()
443 self.configInstance["config"] = self["config"]
445 self["config"].l.setList([])
447 self["config"].hide()
448 else: # condition false
452 def timeoutCounterFired(self):
453 self.timeoutCounter -= 1
454 print "timeoutCounter:", self.timeoutCounter
455 if self.timeoutCounter == 0:
456 if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
457 print "selection next item"
460 if self.wizard[self.currStep]["timeoutaction"] == "changestep":
461 self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
468 def registerWizard(self, wizard, precondition, priority = 0):
469 self.wizards.append((wizard, precondition, priority))
471 def getWizards(self):
473 for x in self.wizards:
474 if x[1] == 1: # precondition
475 list.append((x[2], x[0]))
478 wizardManager = WizardManager()