1 from Screen import Screen
2 from Screens.HelpMenu import HelpableScreen
3 from Screens.MessageBox import MessageBox
4 from Components.config import config, ConfigText, ConfigPassword, KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT, KEY_NUMBERS
6 from Components.Label import Label
7 from Components.Sources.StaticText import StaticText
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
13 from enigma import eTimer
15 from xml.sax import make_parser
16 from xml.sax.handler import ContentHandler
18 class WizardSummary(Screen):
20 <screen position="0,0" size="132,64">
21 <widget source="text" render="Label" position="6,0" size="120,16" font="Regular;16" transparent="1" />
22 <widget source="parent.list" render="Label" position="6,18" size="120,46" font="Regular;12">
23 <convert type="StringListSelection" />
27 def __init__(self, session, parent):
28 Screen.__init__(self, session, parent)
30 #names = parent.skinName
31 #if not isinstance(names, list):
34 #self.skinName = [x + "_summary" for x in names ]
35 #self.skinName.append("Wizard")
36 #print "*************+++++++++++++++++****************++++++++++******************* WizardSummary", self.skinName
38 self["text"] = StaticText("")
39 self.onShow.append(self.setCallback)
41 def setCallback(self):
42 self.parent.setLCDTextCallback(self.setText)
44 def setText(self, text):
45 self["text"].setText(text)
48 def createSummary(self):
49 print "WizardCreateSummary"
52 class parseWizard(ContentHandler):
53 def __init__(self, wizard):
54 self.isPointsElement, self.isReboundsElement = 0, 0
59 def startElement(self, name, attrs):
60 #print "startElement", name
61 self.currContent = name
64 if attrs.has_key('id'):
65 id = str(attrs.get('id'))
69 if attrs.has_key('nextstep'):
70 nextstep = str(attrs.get('nextstep'))
73 if attrs.has_key('timeout'):
74 timeout = int(attrs.get('timeout'))
77 if attrs.has_key('timeoutaction'):
78 timeoutaction = str(attrs.get('timeoutaction'))
80 timeoutaction = 'nextpage'
82 if attrs.has_key('timeoutstep'):
83 timeoutstep = str(attrs.get('timeoutstep'))
86 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}
87 if attrs.has_key('laststep'):
88 self.wizard[self.lastStep]["laststep"] = str(attrs.get('laststep'))
89 elif (name == "text"):
90 self.wizard[self.lastStep]["text"] = str(attrs.get('value')).replace("\\n", "\n")
91 elif (name == "displaytext"):
92 self.wizard[self.lastStep]["displaytext"] = str(attrs.get('value')).replace("\\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.isLastWizard = False # can be used to skip a "goodbye"-screen in a wizard
170 self.stepHistory = []
173 parser = make_parser()
174 if not isinstance(self.xmlfile, list):
175 self.xmlfile = [self.xmlfile]
176 print "Reading ", self.xmlfile
177 wizardHandler = self.parseWizard(self.wizard)
178 parser.setContentHandler(wizardHandler)
179 for xmlfile in self.xmlfile:
180 if xmlfile[0] != '/':
181 parser.parse('/usr/share/enigma2/' + xmlfile)
183 parser.parse(xmlfile)
185 self.showSteps = showSteps
186 self.showStepSlider = showStepSlider
187 self.showList = showList
188 self.showConfig = showConfig
190 self.numSteps = len(self.wizard)
191 self.currStep = self.getStepWithID("start") + 1
193 self.timeoutTimer = eTimer()
194 self.timeoutTimer.callback.append(self.timeoutCounterFired)
196 self["text"] = Label()
199 self["config"] = ConfigList([], session = session)
202 self["step"] = Label()
204 if self.showStepSlider:
205 self["stepslider"] = Slider(1, self.numSteps)
209 self["list"] = List(self.list, enableWrapAround = True)
210 self["list"].onSelectionChanged.append(self.selChanged)
211 #self["list"] = MenuList(self.list, enableWrapAround = True)
213 self.onShown.append(self.updateValues)
215 self.configInstance = None
216 self.currentConfigIndex = None
218 self.lcdCallbacks = []
220 self.disableKeys = False
222 self["actions"] = NumberActionMap(["WizardActions", "NumberActions", "ColorActions", "SetupActions", "InputAsciiActions", "KeyboardInputActions"],
224 "gotAsciiCode": self.keyGotAscii,
233 "yellow": self.yellow,
235 "deleteBackward": self.deleteBackward,
236 "deleteForward": self.deleteForward,
237 "1": self.keyNumberGlobal,
238 "2": self.keyNumberGlobal,
239 "3": self.keyNumberGlobal,
240 "4": self.keyNumberGlobal,
241 "5": self.keyNumberGlobal,
242 "6": self.keyNumberGlobal,
243 "7": self.keyNumberGlobal,
244 "8": self.keyNumberGlobal,
245 "9": self.keyNumberGlobal,
246 "0": self.keyNumberGlobal
249 self["VirtualKB"] = NumberActionMap(["VirtualKeyboardActions"],
251 "showVirtualKeyboard": self.KeyText,
254 self["VirtualKB"].setEnabled(False)
272 def deleteForward(self):
274 if (self.wizard[self.currStep]["config"]["screen"] != None):
275 self.configInstance.keyDelete()
276 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
277 self["config"].handleKey(KEY_DELETE)
278 print "deleteForward"
280 def deleteBackward(self):
282 if (self.wizard[self.currStep]["config"]["screen"] != None):
283 self.configInstance.keyBackspace()
284 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
285 self["config"].handleKey(KEY_BACKSPACE)
286 print "deleteBackward"
288 def setLCDTextCallback(self, callback):
289 self.lcdCallbacks.append(callback)
294 print "getting back..."
295 print "stepHistory:", self.stepHistory
296 if len(self.stepHistory) > 1:
297 self.currStep = self.stepHistory[-2]
298 self.stepHistory = self.stepHistory[:-2]
300 self.session.openWithCallback(self.exitWizardQuestion, MessageBox, (_("Are you sure you want to exit this wizard?") ) )
301 if self.currStep < 1:
303 print "currStep:", self.currStep
304 print "new stepHistory:", self.stepHistory
306 print "after updateValues stepHistory:", self.stepHistory
308 def exitWizardQuestion(self, ret = False):
316 def getStepWithID(self, id):
317 print "getStepWithID:", id
319 for x in self.wizard.keys():
320 if self.wizard[x]["id"] == id:
321 print "result:", count
324 print "result: nothing"
327 def finished(self, gotoStep = None, *args, **kwargs):
329 currStep = self.currStep
331 if self.updateValues not in self.onShown:
332 self.onShown.append(self.updateValues)
335 if self.wizard[currStep]["config"]["type"] == "dynamic":
336 eval("self." + self.wizard[currStep]["config"]["evaluation"])()
339 if (len(self.wizard[currStep]["evaluatedlist"]) > 0):
340 print "current:", self["list"].current
341 nextStep = self["list"].current[1]
342 if (self.wizard[currStep].has_key("listevaluation")):
343 exec("self." + self.wizard[self.currStep]["listevaluation"] + "('" + nextStep + "')")
345 self.currStep = self.getStepWithID(nextStep)
348 if ((currStep == self.numSteps and self.wizard[currStep]["nextstep"] is None) or self.wizard[currStep]["id"] == "end"): # wizard finished
349 print "wizard finished"
353 self.codeafter = True
354 self.runCode(self.wizard[currStep]["codeafter"])
355 self.prevStep = currStep
356 self.gotoStep = gotoStep
357 if not self.runCode(self.wizard[currStep]["codeafter_async"]):
358 self.afterAsyncCode()
360 if self.updateValues in self.onShown:
361 self.onShown.remove(self.updateValues)
364 print "Now: " + str(self.currStep)
370 currStep = self.currStep
373 if (self.wizard[currStep]["config"]["screen"] != None):
374 # TODO: don't die, if no run() is available
375 # there was a try/except here, but i can't see a reason
376 # for this. If there is one, please do a more specific check
377 # and/or a comment in which situation there is no run()
378 if callable(getattr(self.configInstance, "runAsync", None)):
379 if self.updateValues in self.onShown:
380 self.onShown.remove(self.updateValues)
381 self.configInstance.runAsync(self.finished)
384 self.configInstance.run()
387 def keyNumberGlobal(self, number):
388 if (self.wizard[self.currStep]["config"]["screen"] != None):
389 self.configInstance.keyNumberGlobal(number)
391 def keyGotAscii(self):
392 if (self.wizard[self.currStep]["config"]["screen"] != None):
393 self["config"].handleKey(KEY_ASCII)
397 if (self.wizard[self.currStep]["config"]["screen"] != None):
398 self.configInstance.keyLeft()
399 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
400 self["config"].handleKey(KEY_LEFT)
405 if (self.wizard[self.currStep]["config"]["screen"] != None):
406 self.configInstance.keyRight()
407 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
408 self["config"].handleKey(KEY_RIGHT)
413 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
414 self["config"].instance.moveSelection(self["config"].instance.moveUp)
415 self.handleInputHelpers()
416 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
417 self["list"].selectPrevious()
418 if self.wizard[self.currStep].has_key("onselect"):
419 print "current:", self["list"].current
420 self.selection = self["list"].current[-1]
421 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
422 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
427 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
428 self["config"].instance.moveSelection(self["config"].instance.moveDown)
429 self.handleInputHelpers()
430 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
431 #self["list"].instance.moveSelection(self["list"].instance.moveDown)
432 self["list"].selectNext()
433 if self.wizard[self.currStep].has_key("onselect"):
434 print "current:", self["list"].current
435 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
436 #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
437 self.selection = self["list"].current[-1]
438 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
439 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
442 def selChanged(self):
445 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
446 self["config"].instance.moveSelection(self["config"].instance.moveUp)
447 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
448 if self.wizard[self.currStep].has_key("onselect"):
449 self.selection = self["list"].current[-1]
450 print "self.selection:", self.selection
451 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
453 def resetCounter(self):
454 self.timeoutCounter = self.wizard[self.currStep]["timeout"]
456 def runCode(self, code):
463 def getTranslation(self, text):
466 def updateText(self, firstset = False):
467 text = self.getTranslation(self.wizard[self.currStep]["text"])
468 if text.find("[timeout]") != -1:
469 text = text.replace("[timeout]", str(self.timeoutCounter))
470 self["text"].setText(text)
473 self["text"].setText(text)
475 def updateValues(self):
476 print "Updating values in step " + str(self.currStep)
477 # calling a step which doesn't exist can only happen if the condition in the last step is not fulfilled
478 # if a non-existing step is called, end the wizard
479 if self.currStep > len(self.wizard):
484 self.timeoutTimer.stop()
486 if self.configInstance is not None:
488 self.configInstance["config"].onSelectionChanged = []
489 del self.configInstance["config"]
490 self.configInstance.doClose()
491 self.configInstance = None
493 self.condition = True
494 exec (self.wizard[self.currStep]["condition"])
495 if not self.condition:
496 print "keys*******************:", self.wizard[self.currStep].keys()
497 if self.wizard[self.currStep].has_key("laststep"): # exit wizard, if condition of laststep doesn't hold
505 if self.wizard[self.currStep].has_key("displaytext"):
506 displaytext = self.wizard[self.currStep]["displaytext"]
508 for x in self.lcdCallbacks:
510 if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
511 self.stepHistory.append(self.currStep)
512 print "wizard step:", self.wizard[self.currStep]
515 self["step"].setText(self.getTranslation("Step ") + str(self.currStep) + "/" + str(self.numSteps))
516 if self.showStepSlider:
517 self["stepslider"].setValue(self.currStep)
519 if self.wizard[self.currStep]["timeout"] is not None:
521 self.timeoutTimer.start(1000)
523 print "wizard text", self.getTranslation(self.wizard[self.currStep]["text"])
524 self.updateText(firstset = True)
525 if self.wizard[self.currStep].has_key("displaytext"):
526 displaytext = self.wizard[self.currStep]["displaytext"]
528 for x in self.lcdCallbacks:
532 self.runCode(self.wizard[self.currStep]["code"])
533 if self.runCode(self.wizard[self.currStep]["code_async"]):
534 if self.updateValues in self.onShown:
535 self.onShown.remove(self.updateValues)
537 self.afterAsyncCode()
539 def afterAsyncCode(self):
540 if not self.updateValues in self.onShown:
541 self.onShown.append(self.updateValues)
544 if self.wizard[self.prevStep]["nextstep"] is not None:
545 self.currStep = self.getStepWithID(self.wizard[self.prevStep]["nextstep"])
546 if self.gotoStep is not None:
547 self.currStep = self.getStepWithID(self.gotoStep)
550 print "Now: " + str(self.currStep)
553 print "showing list,", self.currStep
554 for renderer in self.renderer:
555 rootrenderer = renderer
556 while renderer.source is not None:
557 print "self.list:", self["list"]
558 if renderer.source is self["list"]:
560 rootrenderer.instance.setZPosition(1)
561 renderer = renderer.source
563 #self["list"].instance.setZPosition(1)
565 if (self.wizard[self.currStep].has_key("dynamiclist")):
566 print "dynamic list, calling", self.wizard[self.currStep]["dynamiclist"]
567 newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
568 #self.wizard[self.currStep]["evaluatedlist"] = []
569 for entry in newlist:
570 #self.wizard[self.currStep]["evaluatedlist"].append(entry)
571 self.list.append(entry)
572 #del self.wizard[self.currStep]["dynamiclist"]
573 if (len(self.wizard[self.currStep]["list"]) > 0):
574 #self["list"].instance.setZPosition(2)
575 for x in self.wizard[self.currStep]["list"]:
576 self.list.append((self.getTranslation(x[0]), x[1]))
577 self.wizard[self.currStep]["evaluatedlist"] = self.list
578 self["list"].list = self.list
579 self["list"].index = 0
584 print "showing config"
585 self["config"].instance.setZPosition(1)
586 if self.wizard[self.currStep]["config"]["type"] == "dynamic":
587 print "config type is dynamic"
588 self["config"].instance.setZPosition(2)
589 self["config"].l.setList(eval("self." + self.wizard[self.currStep]["config"]["source"])())
590 elif (self.wizard[self.currStep]["config"]["screen"] != None):
591 if self.wizard[self.currStep]["config"]["type"] == "standalone":
592 print "Type is standalone"
593 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
595 self["config"].instance.setZPosition(2)
596 print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
597 if self.wizard[self.currStep]["config"]["args"] == None:
598 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
600 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
601 self["config"].l.setList(self.configInstance["config"].list)
602 callbacks = self.configInstance["config"].onSelectionChanged
603 self.configInstance["config"].destroy()
604 print "clearConfigList", self.configInstance["config"], self["config"]
605 self.configInstance["config"] = self["config"]
606 self.configInstance["config"].onSelectionChanged = callbacks
607 print "clearConfigList", self.configInstance["config"], self["config"]
609 self["config"].l.setList([])
610 self.handleInputHelpers()
614 if self.has_key("config"):
615 self["config"].hide()
617 def timeoutCounterFired(self):
618 self.timeoutCounter -= 1
619 print "timeoutCounter:", self.timeoutCounter
620 if self.timeoutCounter == 0:
621 if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
622 print "selection next item"
625 if self.wizard[self.currStep]["timeoutaction"] == "changestep":
626 self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
629 def handleInputHelpers(self):
630 if self["config"].getCurrent() is not None:
631 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
632 if self.has_key("VKeyIcon"):
633 self["VirtualKB"].setEnabled(True)
634 self["VKeyIcon"].boolean = True
635 if self.has_key("HelpWindow"):
636 if self["config"].getCurrent()[1].help_window.instance is not None:
637 helpwindowpos = self["HelpWindow"].getPosition()
638 from enigma import ePoint
639 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
641 if self.has_key("VKeyIcon"):
642 self["VirtualKB"].setEnabled(False)
643 self["VKeyIcon"].boolean = False
645 if self.has_key("VKeyIcon"):
646 self["VirtualKB"].setEnabled(False)
647 self["VKeyIcon"].boolean = False
650 from Screens.VirtualKeyBoard import VirtualKeyBoard
651 self.currentConfigIndex = self["config"].getCurrentIndex()
652 self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].getValue())
654 def VirtualKeyBoardCallback(self, callback = None):
655 if callback is not None and len(callback):
656 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
657 if self.has_key("HelpWindow"):
658 if self["config"].getCurrent()[1].help_window.instance is not None:
659 helpwindowpos = self["HelpWindow"].getPosition()
660 from enigma import ePoint
661 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
662 self["config"].instance.moveSelectionTo(self.currentConfigIndex)
663 self["config"].setCurrentIndex(self.currentConfigIndex)
664 self["config"].getCurrent()[1].setValue(callback)
665 self["config"].invalidate(self["config"].getCurrent())
672 def registerWizard(self, wizard, precondition, priority = 0):
673 self.wizards.append((wizard, precondition, priority))
675 def getWizards(self):
676 # x[1] is precondition
677 for wizard in self.wizards:
678 wizard[0].isLastWizard = False
679 if len(self.wizards) > 0:
680 self.wizards[-1][0].isLastWizard = True
681 return [(x[2], x[0]) for x in self.wizards if x[1] == 1]
683 wizardManager = WizardManager()