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):
49 def createSummary(self):
50 print "WizardCreateSummary"
53 class parseWizard(ContentHandler):
54 def __init__(self, wizard):
55 self.isPointsElement, self.isReboundsElement = 0, 0
62 def startElement(self, name, attrs):
63 print "startElement", name
64 self.currContent = name
67 if attrs.has_key('id'):
68 id = str(attrs.get('id'))
72 if attrs.has_key('nextstep'):
73 nextstep = str(attrs.get('nextstep'))
76 if attrs.has_key('timeout'):
77 timeout = int(attrs.get('timeout'))
80 if attrs.has_key('timeoutaction'):
81 timeoutaction = str(attrs.get('timeoutaction'))
83 timeoutaction = 'nextpage'
85 if attrs.has_key('timeoutstep'):
86 timeoutstep = str(attrs.get('timeoutstep'))
89 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}
90 elif (name == "text"):
91 self.wizard[self.lastStep]["text"] = string.replace(str(attrs.get('value')), "\\n", "\n")
92 elif (name == "displaytext"):
93 self.wizard[self.lastStep]["displaytext"] = string.replace(str(attrs.get('value')), "\\n", "\n")
94 elif (name == "list"):
95 if (attrs.has_key('type')):
96 if attrs["type"] == "dynamic":
97 self.wizard[self.lastStep]["dynamiclist"] = attrs.get("source")
98 #self.wizard[self.lastStep]["list"].append(("Hallo", "test"))
99 if (attrs.has_key("evaluation")):
101 self.wizard[self.lastStep]["listevaluation"] = attrs.get("evaluation")
102 if (attrs.has_key("onselect")):
103 self.wizard[self.lastStep]["onselect"] = attrs.get("onselect")
104 elif (name == "listentry"):
105 self.wizard[self.lastStep]["list"].append((str(attrs.get('caption')), str(attrs.get('step'))))
106 elif (name == "config"):
107 exec "from Screens." + str(attrs.get('module')) + " import *"
108 self.wizard[self.lastStep]["config"]["screen"] = eval(str(attrs.get('screen')))
109 if (attrs.has_key('args')):
111 self.wizard[self.lastStep]["config"]["args"] = str(attrs.get('args'))
112 self.wizard[self.lastStep]["config"]["type"] = str(attrs.get('type'))
113 elif (name == "code"):
114 if attrs.has_key('pos') and str(attrs.get('pos')) == "after":
115 self.codeafter = True
117 self.codeafter = False
118 elif (name == "condition"):
120 def endElement(self, name):
121 self.currContent = ""
124 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"].strip()
126 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
127 elif name == 'condition':
128 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"].strip()
130 print "Step number", self.lastStep, ":", self.wizard[self.lastStep]
132 def characters(self, ch):
133 if self.currContent == "code":
135 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"] + ch
137 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
138 elif self.currContent == "condition":
139 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"] + ch
141 def __init__(self, session, showSteps = True, showStepSlider = True, showList = True, showConfig = True):
142 Screen.__init__(self, session)
143 HelpableScreen.__init__(self)
145 self.stepHistory = []
148 parser = make_parser()
149 print "Reading " + self.xmlfile
150 wizardHandler = self.parseWizard(self.wizard)
151 parser.setContentHandler(wizardHandler)
152 if self.xmlfile[0] != '/':
153 parser.parse('/usr/share/enigma2/' + self.xmlfile)
155 parser.parse(self.xmlfile)
157 self.showSteps = showSteps
158 self.showStepSlider = showStepSlider
159 self.showList = showList
160 self.showConfig = showConfig
162 self.numSteps = len(self.wizard)
165 self.timeoutTimer = eTimer()
166 self.timeoutTimer.callback.append(self.timeoutCounterFired)
168 self["text"] = Label()
171 self["config"] = ConfigList([])
174 self["step"] = Label()
176 if self.showStepSlider:
177 self["stepslider"] = Slider(1, self.numSteps)
181 self["list"] = List(self.list, enableWrapAround = True)
182 self["list"].onSelectionChanged.append(self.selChanged)
183 #self["list"] = MenuList(self.list, enableWrapAround = True)
185 self.onShown.append(self.updateValues)
187 self.configInstance = None
189 self.lcdCallbacks = []
191 self["actions"] = NumberActionMap(["WizardActions", "NumberActions", "ColorActions"],
201 "yellow": self.yellow,
203 "1": self.keyNumberGlobal,
204 "2": self.keyNumberGlobal,
205 "3": self.keyNumberGlobal,
206 "4": self.keyNumberGlobal,
207 "5": self.keyNumberGlobal,
208 "6": self.keyNumberGlobal,
209 "7": self.keyNumberGlobal,
210 "8": self.keyNumberGlobal,
211 "9": self.keyNumberGlobal,
212 "0": self.keyNumberGlobal
231 def setLCDTextCallback(self, callback):
232 self.lcdCallbacks.append(callback)
235 print "getting back..."
236 print "stepHistory:", self.stepHistory
237 if len(self.stepHistory) > 1:
238 self.currStep = self.stepHistory[-2]
239 self.stepHistory = self.stepHistory[:-2]
240 if self.currStep < 1:
242 print "currStep:", self.currStep
243 print "new stepHistory:", self.stepHistory
245 print "after updateValues stepHistory:", self.stepHistory
250 def getStepWithID(self, id):
251 print "getStepWithID:", id
253 for x in self.wizard:
254 if self.wizard[x]["id"] == id:
255 print "result:", count
258 print "result: nothing"
261 def finished(self, gotoStep = None, *args, **kwargs):
263 currStep = self.currStep
265 if self.updateValues not in self.onShown:
266 self.onShown.append(self.updateValues)
269 if (len(self.wizard[currStep]["evaluatedlist"]) > 0):
270 print "current:", self["list"].current
271 nextStep = self["list"].current[1]
272 if (self.wizard[currStep].has_key("listevaluation")):
273 exec("self." + self.wizard[self.currStep]["listevaluation"] + "('" + nextStep + "')")
275 self.currStep = self.getStepWithID(nextStep)
277 if (currStep == self.numSteps): # wizard finished
281 self.runCode(self.wizard[currStep]["codeafter"])
282 if self.wizard[currStep]["nextstep"] is not None:
283 self.currStep = self.getStepWithID(self.wizard[currStep]["nextstep"])
284 if gotoStep is not None:
285 self.currStep = self.getStepWithID(gotoStep)
289 print "Now: " + str(self.currStep)
294 currStep = self.currStep
297 if (self.wizard[currStep]["config"]["screen"] != None):
298 # TODO: don't die, if no run() is available
299 # there was a try/except here, but i can't see a reason
300 # for this. If there is one, please do a more specific check
301 # and/or a comment in which situation there is no run()
302 if callable(getattr(self.configInstance, "runAsync", None)):
303 self.onShown.remove(self.updateValues)
304 self.configInstance.runAsync(self.finished)
307 self.configInstance.run()
310 def keyNumberGlobal(self, number):
311 if (self.wizard[self.currStep]["config"]["screen"] != None):
312 self.configInstance.keyNumberGlobal(number)
316 if (self.wizard[self.currStep]["config"]["screen"] != None):
317 self.configInstance.keyLeft()
322 if (self.wizard[self.currStep]["config"]["screen"] != None):
323 self.configInstance.keyRight()
328 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
329 self["config"].instance.moveSelection(self["config"].instance.moveUp)
330 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
331 self["list"].selectPrevious()
332 if self.wizard[self.currStep].has_key("onselect"):
333 print "current:", self["list"].current
334 self.selection = self["list"].current[-1]
335 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
336 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
341 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
342 self["config"].instance.moveSelection(self["config"].instance.moveDown)
343 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
344 #self["list"].instance.moveSelection(self["list"].instance.moveDown)
345 self["list"].selectNext()
346 if self.wizard[self.currStep].has_key("onselect"):
347 print "current:", self["list"].current
348 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
349 #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
350 self.selection = self["list"].current[-1]
351 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
352 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
355 def selChanged(self):
358 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
359 self["config"].instance.moveSelection(self["config"].instance.moveUp)
360 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
361 if self.wizard[self.currStep].has_key("onselect"):
362 self.selection = self["list"].current[-1]
363 print "self.selection:", self.selection
364 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
366 def resetCounter(self):
367 self.timeoutCounter = self.wizard[self.currStep]["timeout"]
369 def runCode(self, code):
374 def updateText(self, firstset = False):
375 text = _(self.wizard[self.currStep]["text"])
376 if text.find("[timeout]") != -1:
377 text = text.replace("[timeout]", str(self.timeoutCounter))
378 self["text"].setText(text)
381 self["text"].setText(text)
383 def updateValues(self):
384 print "Updating values in step " + str(self.currStep)
385 self.timeoutTimer.stop()
387 if self.configInstance is not None:
388 del self.configInstance["config"]
389 self.configInstance.doClose()
390 self.configInstance = None
392 self.condition = True
393 exec (self.wizard[self.currStep]["condition"])
395 if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
396 self.stepHistory.append(self.currStep)
397 print "wizard step:", self.wizard[self.currStep]
400 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
401 if self.showStepSlider:
402 self["stepslider"].setValue(self.currStep)
404 if self.wizard[self.currStep]["timeout"] is not None:
406 self.timeoutTimer.start(1000)
408 print "wizard text", _(self.wizard[self.currStep]["text"])
409 self.updateText(firstset = True)
410 if self.wizard[self.currStep].has_key("displaytext"):
411 displaytext = self.wizard[self.currStep]["displaytext"]
413 for x in self.lcdCallbacks:
416 self.runCode(self.wizard[self.currStep]["code"])
419 print "showing list,", self.currStep
420 for renderer in self.renderer:
421 rootrenderer = renderer
422 while renderer.source is not None:
423 print "self.list:", self["list"]
424 if renderer.source is self["list"]:
426 rootrenderer.instance.setZPosition(1)
427 renderer = renderer.source
429 #self["list"].instance.setZPosition(1)
431 if (self.wizard[self.currStep].has_key("dynamiclist")):
432 print "dynamic list, calling", self.wizard[self.currStep]["dynamiclist"]
433 newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
434 #self.wizard[self.currStep]["evaluatedlist"] = []
435 for entry in newlist:
436 #self.wizard[self.currStep]["evaluatedlist"].append(entry)
437 self.list.append(entry)
438 #del self.wizard[self.currStep]["dynamiclist"]
439 if (len(self.wizard[self.currStep]["list"]) > 0):
440 #self["list"].instance.setZPosition(2)
441 for x in self.wizard[self.currStep]["list"]:
442 self.list.append((_(x[0]), x[1]))
443 self.wizard[self.currStep]["evaluatedlist"] = self.list
444 self["list"].list = self.list
445 self["list"].index = 0
450 self["config"].instance.setZPosition(1)
451 if (self.wizard[self.currStep]["config"]["screen"] != None):
452 if self.wizard[self.currStep]["config"]["type"] == "standalone":
453 print "Type is standalone"
454 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
456 self["config"].instance.setZPosition(2)
457 print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
458 if self.wizard[self.currStep]["config"]["args"] == None:
459 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
461 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
462 self["config"].l.setList(self.configInstance["config"].list)
463 self.configInstance["config"].destroy()
464 self.configInstance["config"] = self["config"]
466 self["config"].l.setList([])
468 if self.has_key("config"):
469 self["config"].hide()
470 else: # condition false
474 def timeoutCounterFired(self):
475 self.timeoutCounter -= 1
476 print "timeoutCounter:", self.timeoutCounter
477 if self.timeoutCounter == 0:
478 if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
479 print "selection next item"
482 if self.wizard[self.currStep]["timeoutaction"] == "changestep":
483 self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
490 def registerWizard(self, wizard, precondition, priority = 0):
491 self.wizards.append((wizard, precondition, priority))
493 def getWizards(self):
495 for x in self.wizards:
496 if x[1] == 1: # precondition
497 list.append((x[2], x[0]))
500 wizardManager = WizardManager()