1 from Screen import Screen
5 from Screens.HelpMenu import HelpableScreen
6 from Components.config import config, KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT, KEY_NUMBERS
8 from Components.Label import Label
9 from Components.Slider import Slider
10 from Components.ActionMap import NumberActionMap
11 from Components.MenuList import MenuList
12 from Components.ConfigList import ConfigList
13 from Components.Sources.List import List
15 from enigma import eTimer
17 from xml.sax import make_parser
18 from xml.sax.handler import ContentHandler
20 class WizardSummary(Screen):
22 <screen position="0,0" size="132,64">
23 <widget name="text" position="6,4" size="120,42" font="Regular;14" transparent="1" />
24 <widget source="parent.list" render="Label" position="6,25" size="120,21" font="Regular;16">
25 <convert type="StringListSelection" />
29 def __init__(self, session, parent):
30 Screen.__init__(self, session, parent)
32 #names = parent.skinName
33 #if not isinstance(names, list):
36 #self.skinName = [x + "_summary" for x in names ]
37 #self.skinName.append("Wizard")
38 #print "*************+++++++++++++++++****************++++++++++******************* WizardSummary", self.skinName
40 self["text"] = Label("")
41 self.onShow.append(self.setCallback)
43 def setCallback(self):
44 self.parent.setLCDTextCallback(self.setText)
46 def setText(self, text):
47 self["text"].setText(text)
50 def createSummary(self):
51 print "WizardCreateSummary"
54 class parseWizard(ContentHandler):
55 def __init__(self, wizard):
56 self.isPointsElement, self.isReboundsElement = 0, 0
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": "", "code_async": "", "codeafter_async": "", "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 type = str(attrs.get('type'))
107 self.wizard[self.lastStep]["config"]["type"] = type
108 if type == "ConfigList" or type == "standalone":
110 exec "from Screens." + str(attrs.get('module')) + " import *"
112 exec "from " + str(attrs.get('module')) + " import *"
114 self.wizard[self.lastStep]["config"]["screen"] = eval(str(attrs.get('screen')))
115 if (attrs.has_key('args')):
117 self.wizard[self.lastStep]["config"]["args"] = str(attrs.get('args'))
118 elif type == "dynamic":
119 self.wizard[self.lastStep]["config"]["source"] = str(attrs.get('source'))
120 if (attrs.has_key('evaluation')):
121 self.wizard[self.lastStep]["config"]["evaluation"] = str(attrs.get('evaluation'))
122 elif (name == "code"):
123 self.async_code = attrs.has_key('async') and str(attrs.get('async')) == "yes"
124 if attrs.has_key('pos') and str(attrs.get('pos')) == "after":
125 self.codeafter = True
127 self.codeafter = False
128 elif (name == "condition"):
131 def endElement(self, name):
132 self.currContent = ""
136 self.wizard[self.lastStep]["codeafter_async"] = self.wizard[self.lastStep]["codeafter_async"].strip()
138 self.wizard[self.lastStep]["code_async"] = self.wizard[self.lastStep]["code_async"].strip()
141 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"].strip()
143 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
144 elif name == 'condition':
145 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"].strip()
147 #print "Step number", self.lastStep, ":", self.wizard[self.lastStep]
150 def characters(self, ch):
151 if self.currContent == "code":
154 self.wizard[self.lastStep]["codeafter_async"] = self.wizard[self.lastStep]["codeafter_async"] + ch
156 self.wizard[self.lastStep]["code_async"] = self.wizard[self.lastStep]["code_async"] + ch
159 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"] + ch
161 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
162 elif self.currContent == "condition":
163 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"] + ch
165 def __init__(self, session, showSteps = True, showStepSlider = True, showList = True, showConfig = True):
166 Screen.__init__(self, session)
168 self.stepHistory = []
171 parser = make_parser()
172 if not isinstance(self.xmlfile, list):
173 self.xmlfile = [self.xmlfile]
174 print "Reading ", self.xmlfile
175 wizardHandler = self.parseWizard(self.wizard)
176 parser.setContentHandler(wizardHandler)
177 for xmlfile in self.xmlfile:
178 if xmlfile[0] != '/':
179 parser.parse('/usr/share/enigma2/' + xmlfile)
181 parser.parse(xmlfile)
183 self.showSteps = showSteps
184 self.showStepSlider = showStepSlider
185 self.showList = showList
186 self.showConfig = showConfig
188 self.numSteps = len(self.wizard)
189 self.currStep = self.getStepWithID("start") + 1
191 self.timeoutTimer = eTimer()
192 self.timeoutTimer.callback.append(self.timeoutCounterFired)
194 self["text"] = Label()
197 self["config"] = ConfigList([], session = session)
200 self["step"] = Label()
202 if self.showStepSlider:
203 self["stepslider"] = Slider(1, self.numSteps)
207 self["list"] = List(self.list, enableWrapAround = True)
208 self["list"].onSelectionChanged.append(self.selChanged)
209 #self["list"] = MenuList(self.list, enableWrapAround = True)
211 self.onShown.append(self.updateValues)
213 self.configInstance = None
215 self.lcdCallbacks = []
217 self.disableKeys = False
219 self["actions"] = NumberActionMap(["WizardActions", "NumberActions", "ColorActions", "SetupActions", "InputAsciiActions"],
221 "gotAsciiCode": self.keyGotAscii,
230 "yellow": self.yellow,
232 "deleteBackward": self.deleteBackward,
233 "deleteForward": self.deleteForward,
234 "1": self.keyNumberGlobal,
235 "2": self.keyNumberGlobal,
236 "3": self.keyNumberGlobal,
237 "4": self.keyNumberGlobal,
238 "5": self.keyNumberGlobal,
239 "6": self.keyNumberGlobal,
240 "7": self.keyNumberGlobal,
241 "8": self.keyNumberGlobal,
242 "9": self.keyNumberGlobal,
243 "0": self.keyNumberGlobal
262 def deleteForward(self):
264 if (self.wizard[self.currStep]["config"]["screen"] != None):
265 self.configInstance.keyDelete()
266 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
267 self["config"].handleKey(KEY_DELETE)
268 print "deleteForward"
270 def deleteBackward(self):
272 if (self.wizard[self.currStep]["config"]["screen"] != None):
273 self.configInstance.keyBackspace()
274 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
275 self["config"].handleKey(KEY_BACKSPACE)
276 print "deleteBackward"
278 def setLCDTextCallback(self, callback):
279 self.lcdCallbacks.append(callback)
284 print "getting back..."
285 print "stepHistory:", self.stepHistory
286 if len(self.stepHistory) > 1:
287 self.currStep = self.stepHistory[-2]
288 self.stepHistory = self.stepHistory[:-2]
289 if self.currStep < 1:
291 print "currStep:", self.currStep
292 print "new stepHistory:", self.stepHistory
294 print "after updateValues stepHistory:", self.stepHistory
299 def getStepWithID(self, id):
300 print "getStepWithID:", id
302 for x in self.wizard.keys():
303 if self.wizard[x]["id"] == id:
304 print "result:", count
307 print "result: nothing"
310 def finished(self, gotoStep = None, *args, **kwargs):
312 currStep = self.currStep
314 if self.updateValues not in self.onShown:
315 self.onShown.append(self.updateValues)
318 if self.wizard[currStep]["config"]["type"] == "dynamic":
319 eval("self." + self.wizard[currStep]["config"]["evaluation"])()
322 if (len(self.wizard[currStep]["evaluatedlist"]) > 0):
323 print "current:", self["list"].current
324 nextStep = self["list"].current[1]
325 if (self.wizard[currStep].has_key("listevaluation")):
326 exec("self." + self.wizard[self.currStep]["listevaluation"] + "('" + nextStep + "')")
328 self.currStep = self.getStepWithID(nextStep)
331 if ((currStep == self.numSteps and self.wizard[currStep]["nextstep"] is None) or self.wizard[currStep]["id"] == "end"): # wizard finished
332 print "wizard finished"
336 self.codeafter = True
337 self.runCode(self.wizard[currStep]["codeafter"])
338 self.prevStep = currStep
339 self.gotoStep = gotoStep
340 if not self.runCode(self.wizard[currStep]["codeafter_async"]):
341 self.afterAsyncCode()
343 if self.updateValues in self.onShown:
344 self.onShown.remove(self.updateValues)
347 print "Now: " + str(self.currStep)
353 currStep = self.currStep
356 if (self.wizard[currStep]["config"]["screen"] != None):
357 # TODO: don't die, if no run() is available
358 # there was a try/except here, but i can't see a reason
359 # for this. If there is one, please do a more specific check
360 # and/or a comment in which situation there is no run()
361 if callable(getattr(self.configInstance, "runAsync", None)):
362 if self.updateValues in self.onShown:
363 self.onShown.remove(self.updateValues)
364 self.configInstance.runAsync(self.finished)
367 self.configInstance.run()
370 def keyNumberGlobal(self, number):
371 if (self.wizard[self.currStep]["config"]["screen"] != None):
372 self.configInstance.keyNumberGlobal(number)
374 def keyGotAscii(self):
375 if (self.wizard[self.currStep]["config"]["screen"] != None):
376 self["config"].handleKey(KEY_ASCII)
380 if (self.wizard[self.currStep]["config"]["screen"] != None):
381 self.configInstance.keyLeft()
382 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
383 self["config"].handleKey(KEY_LEFT)
388 if (self.wizard[self.currStep]["config"]["screen"] != None):
389 self.configInstance.keyRight()
390 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
391 self["config"].handleKey(KEY_RIGHT)
396 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
397 self["config"].instance.moveSelection(self["config"].instance.moveUp)
398 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
399 self["list"].selectPrevious()
400 if self.wizard[self.currStep].has_key("onselect"):
401 print "current:", self["list"].current
402 self.selection = self["list"].current[-1]
403 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
404 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
409 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
410 self["config"].instance.moveSelection(self["config"].instance.moveDown)
411 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
412 #self["list"].instance.moveSelection(self["list"].instance.moveDown)
413 self["list"].selectNext()
414 if self.wizard[self.currStep].has_key("onselect"):
415 print "current:", self["list"].current
416 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
417 #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
418 self.selection = self["list"].current[-1]
419 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
420 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
423 def selChanged(self):
426 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
427 self["config"].instance.moveSelection(self["config"].instance.moveUp)
428 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
429 if self.wizard[self.currStep].has_key("onselect"):
430 self.selection = self["list"].current[-1]
431 print "self.selection:", self.selection
432 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
434 def resetCounter(self):
435 self.timeoutCounter = self.wizard[self.currStep]["timeout"]
437 def runCode(self, code):
444 def getTranslation(self, text):
447 def updateText(self, firstset = False):
448 text = self.getTranslation(self.wizard[self.currStep]["text"])
449 if text.find("[timeout]") != -1:
450 text = text.replace("[timeout]", str(self.timeoutCounter))
451 self["text"].setText(text)
454 self["text"].setText(text)
456 def updateValues(self):
457 print "Updating values in step " + str(self.currStep)
458 # calling a step which doesn't exist can only happen if the condition in the last step is not fulfilled
459 # if a non-existing step is called, end the wizard
460 if self.currStep > len(self.wizard):
465 self.timeoutTimer.stop()
467 if self.configInstance is not None:
469 self.configInstance["config"].onSelectionChanged = []
470 del self.configInstance["config"]
471 self.configInstance.doClose()
472 self.configInstance = None
474 self.condition = True
475 exec (self.wizard[self.currStep]["condition"])
476 if not self.condition:
480 if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
481 self.stepHistory.append(self.currStep)
482 print "wizard step:", self.wizard[self.currStep]
485 self["step"].setText(self.getTranslation("Step ") + str(self.currStep) + "/" + str(self.numSteps))
486 if self.showStepSlider:
487 self["stepslider"].setValue(self.currStep)
489 if self.wizard[self.currStep]["timeout"] is not None:
491 self.timeoutTimer.start(1000)
493 print "wizard text", self.getTranslation(self.wizard[self.currStep]["text"])
494 self.updateText(firstset = True)
495 if self.wizard[self.currStep].has_key("displaytext"):
496 displaytext = self.wizard[self.currStep]["displaytext"]
498 for x in self.lcdCallbacks:
502 self.runCode(self.wizard[self.currStep]["code"])
503 if self.runCode(self.wizard[self.currStep]["code_async"]):
504 if self.updateValues in self.onShown:
505 self.onShown.remove(self.updateValues)
507 self.afterAsyncCode()
509 def afterAsyncCode(self):
510 if not self.updateValues in self.onShown:
511 self.onShown.append(self.updateValues)
514 if self.wizard[self.prevStep]["nextstep"] is not None:
515 self.currStep = self.getStepWithID(self.wizard[self.prevStep]["nextstep"])
516 if self.gotoStep is not None:
517 self.currStep = self.getStepWithID(self.gotoStep)
520 print "Now: " + str(self.currStep)
523 print "showing list,", self.currStep
524 for renderer in self.renderer:
525 rootrenderer = renderer
526 while renderer.source is not None:
527 print "self.list:", self["list"]
528 if renderer.source is self["list"]:
530 rootrenderer.instance.setZPosition(1)
531 renderer = renderer.source
533 #self["list"].instance.setZPosition(1)
535 if (self.wizard[self.currStep].has_key("dynamiclist")):
536 print "dynamic list, calling", self.wizard[self.currStep]["dynamiclist"]
537 newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
538 #self.wizard[self.currStep]["evaluatedlist"] = []
539 for entry in newlist:
540 #self.wizard[self.currStep]["evaluatedlist"].append(entry)
541 self.list.append(entry)
542 #del self.wizard[self.currStep]["dynamiclist"]
543 if (len(self.wizard[self.currStep]["list"]) > 0):
544 #self["list"].instance.setZPosition(2)
545 for x in self.wizard[self.currStep]["list"]:
546 self.list.append((self.getTranslation(x[0]), x[1]))
547 self.wizard[self.currStep]["evaluatedlist"] = self.list
548 self["list"].list = self.list
549 self["list"].index = 0
554 print "showing config"
555 self["config"].instance.setZPosition(1)
556 if self.wizard[self.currStep]["config"]["type"] == "dynamic":
557 print "config type is dynamic"
558 self["config"].instance.setZPosition(2)
559 self["config"].l.setList(eval("self." + self.wizard[self.currStep]["config"]["source"])())
560 elif (self.wizard[self.currStep]["config"]["screen"] != None):
561 if self.wizard[self.currStep]["config"]["type"] == "standalone":
562 print "Type is standalone"
563 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
565 self["config"].instance.setZPosition(2)
566 print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
567 if self.wizard[self.currStep]["config"]["args"] == None:
568 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
570 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
571 self["config"].l.setList(self.configInstance["config"].list)
572 callbacks = self.configInstance["config"].onSelectionChanged
573 self.configInstance["config"].destroy()
574 print "clearConfigList", self.configInstance["config"], self["config"]
575 self.configInstance["config"] = self["config"]
576 self.configInstance["config"].onSelectionChanged = callbacks
577 print "clearConfigList", self.configInstance["config"], self["config"]
579 self["config"].l.setList([])
581 if self.has_key("config"):
582 self["config"].hide()
584 def timeoutCounterFired(self):
585 self.timeoutCounter -= 1
586 print "timeoutCounter:", self.timeoutCounter
587 if self.timeoutCounter == 0:
588 if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
589 print "selection next item"
592 if self.wizard[self.currStep]["timeoutaction"] == "changestep":
593 self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
600 def registerWizard(self, wizard, precondition, priority = 0):
601 self.wizards.append((wizard, precondition, priority))
603 def getWizards(self):
605 for x in self.wizards:
606 if x[1] == 1: # precondition
607 list.append((x[2], x[0]))
610 wizardManager = WizardManager()