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
19 from Plugins.SystemPlugins.FactoryTest.plugin import FactoryTest
21 class WizardSummary(Screen):
23 <screen position="0,0" size="132,64">
24 <widget source="text" render="Label" position="6,0" size="120,16" font="Regular;16" transparent="1" />
25 <widget source="parent.list" render="Label" position="6,18" size="120,46" font="Regular;12">
26 <convert type="StringListSelection" />
30 def __init__(self, session, parent):
31 Screen.__init__(self, session, parent)
33 #names = parent.skinName
34 #if not isinstance(names, list):
37 #self.skinName = [x + "_summary" for x in names ]
38 #self.skinName.append("Wizard")
39 #print "*************+++++++++++++++++****************++++++++++******************* WizardSummary", self.skinName
41 self["text"] = StaticText("")
42 self.onShow.append(self.setCallback)
44 def setCallback(self):
45 self.parent.setLCDTextCallback(self.setText)
47 def setText(self, text):
48 self["text"].setText(text)
51 def createSummary(self):
52 print "WizardCreateSummary"
55 class parseWizard(ContentHandler):
56 def __init__(self, wizard):
57 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": "", "code_async": "", "codeafter_async": "", "nextstep": nextstep}
90 if attrs.has_key('laststep'):
91 self.wizard[self.lastStep]["laststep"] = str(attrs.get('laststep'))
92 elif (name == "text"):
93 self.wizard[self.lastStep]["text"] = str(attrs.get('value')).replace("\\n", "\n")
94 elif (name == "displaytext"):
95 self.wizard[self.lastStep]["displaytext"] = str(attrs.get('value')).replace("\\n", "\n")
96 elif (name == "list"):
97 if (attrs.has_key('type')):
98 if attrs["type"] == "dynamic":
99 self.wizard[self.lastStep]["dynamiclist"] = attrs.get("source")
100 #self.wizard[self.lastStep]["list"].append(("Hallo", "test"))
101 if (attrs.has_key("evaluation")):
103 self.wizard[self.lastStep]["listevaluation"] = attrs.get("evaluation")
104 if (attrs.has_key("onselect")):
105 self.wizard[self.lastStep]["onselect"] = attrs.get("onselect")
106 elif (name == "listentry"):
107 self.wizard[self.lastStep]["list"].append((str(attrs.get('caption')), str(attrs.get('step'))))
108 elif (name == "config"):
109 type = str(attrs.get('type'))
110 self.wizard[self.lastStep]["config"]["type"] = type
111 if type == "ConfigList" or type == "standalone":
113 exec "from Screens." + str(attrs.get('module')) + " import *"
115 exec "from " + str(attrs.get('module')) + " import *"
117 self.wizard[self.lastStep]["config"]["screen"] = eval(str(attrs.get('screen')))
118 if (attrs.has_key('args')):
120 self.wizard[self.lastStep]["config"]["args"] = str(attrs.get('args'))
121 elif type == "dynamic":
122 self.wizard[self.lastStep]["config"]["source"] = str(attrs.get('source'))
123 if (attrs.has_key('evaluation')):
124 self.wizard[self.lastStep]["config"]["evaluation"] = str(attrs.get('evaluation'))
125 elif (name == "code"):
126 self.async_code = attrs.has_key('async') and str(attrs.get('async')) == "yes"
127 if attrs.has_key('pos') and str(attrs.get('pos')) == "after":
128 self.codeafter = True
130 self.codeafter = False
131 elif (name == "condition"):
134 def endElement(self, name):
135 self.currContent = ""
139 self.wizard[self.lastStep]["codeafter_async"] = self.wizard[self.lastStep]["codeafter_async"].strip()
141 self.wizard[self.lastStep]["code_async"] = self.wizard[self.lastStep]["code_async"].strip()
144 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"].strip()
146 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
147 elif name == 'condition':
148 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"].strip()
150 #print "Step number", self.lastStep, ":", self.wizard[self.lastStep]
153 def characters(self, ch):
154 if self.currContent == "code":
157 self.wizard[self.lastStep]["codeafter_async"] = self.wizard[self.lastStep]["codeafter_async"] + ch
159 self.wizard[self.lastStep]["code_async"] = self.wizard[self.lastStep]["code_async"] + ch
162 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"] + ch
164 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
165 elif self.currContent == "condition":
166 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"] + ch
168 def __init__(self, session, showSteps = True, showStepSlider = True, showList = True, showConfig = True):
169 Screen.__init__(self, session)
171 self.isLastWizard = False # can be used to skip a "goodbye"-screen in a wizard
173 self.stepHistory = []
176 parser = make_parser()
177 if not isinstance(self.xmlfile, list):
178 self.xmlfile = [self.xmlfile]
179 print "Reading ", self.xmlfile
180 wizardHandler = self.parseWizard(self.wizard)
181 parser.setContentHandler(wizardHandler)
182 for xmlfile in self.xmlfile:
183 if xmlfile[0] != '/':
184 parser.parse('/usr/share/enigma2/' + xmlfile)
186 parser.parse(xmlfile)
188 self.showSteps = showSteps
189 self.showStepSlider = showStepSlider
190 self.showList = showList
191 self.showConfig = showConfig
193 self.numSteps = len(self.wizard)
194 self.currStep = self.getStepWithID("start") + 1
196 self.timeoutTimer = eTimer()
197 self.timeoutTimer.callback.append(self.timeoutCounterFired)
199 # ikseong - for memory test
200 self.memorytestmode = 0
203 self["text"] = Label()
206 self["config"] = ConfigList([], session = session)
209 self["step"] = Label()
211 if self.showStepSlider:
212 self["stepslider"] = Slider(1, self.numSteps)
216 self["list"] = List(self.list, enableWrapAround = True)
217 self["list"].onSelectionChanged.append(self.selChanged)
218 #self["list"] = MenuList(self.list, enableWrapAround = True)
220 self.onShown.append(self.updateValues)
222 self.configInstance = None
223 self.currentConfigIndex = None
225 self.lcdCallbacks = []
227 self.disableKeys = False
229 self["actions"] = NumberActionMap(["WizardActions", "NumberActions", "ColorActions", "SetupActions", "InputAsciiActions", "KeyboardInputActions"],
231 "gotAsciiCode": self.keyGotAscii,
240 "yellow": self.yellow,
242 "deleteBackward": self.deleteBackward,
243 "deleteForward": self.deleteForward,
244 "1": self.keyNumberGlobal,
245 "2": self.keyNumberGlobal,
246 "3": self.keyNumberGlobal,
247 "4": self.keyNumberGlobal,
248 "5": self.keyNumberGlobal,
249 "6": self.keyNumberGlobal,
250 "7": self.keyNumberGlobal,
251 "8": self.keyNumberGlobal,
252 "9": self.keyNumberGlobal,
253 "0": self.keyNumberGlobal,
258 self["VirtualKB"] = NumberActionMap(["VirtualKeyboardActions"],
260 "showVirtualKeyboard": self.KeyText,
263 self["VirtualKB"].setEnabled(False)
281 def deleteForward(self):
283 if (self.wizard[self.currStep]["config"]["screen"] != None):
284 self.configInstance.keyDelete()
285 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
286 self["config"].handleKey(KEY_DELETE)
287 print "deleteForward"
289 def deleteBackward(self):
291 if (self.wizard[self.currStep]["config"]["screen"] != None):
292 self.configInstance.keyBackspace()
293 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
294 self["config"].handleKey(KEY_BACKSPACE)
295 print "deleteBackward"
297 def setLCDTextCallback(self, callback):
298 self.lcdCallbacks.append(callback)
303 print "getting back..."
304 print "stepHistory:", self.stepHistory
305 if len(self.stepHistory) > 1:
306 self.currStep = self.stepHistory[-2]
307 self.stepHistory = self.stepHistory[:-2]
309 self.session.openWithCallback(self.exitWizardQuestion, MessageBox, (_("Are you sure you want to exit this wizard?") ) )
310 if self.currStep < 1:
312 print "currStep:", self.currStep
313 print "new stepHistory:", self.stepHistory
315 print "after updateValues stepHistory:", self.stepHistory
317 def exitWizardQuestion(self, ret = False):
325 def getStepWithID(self, id):
326 print "getStepWithID:", id
328 for x in self.wizard.keys():
329 if self.wizard[x]["id"] == id:
330 print "result:", count
333 print "result: nothing"
336 def finished(self, gotoStep = None, *args, **kwargs):
338 currStep = self.currStep
340 if self.updateValues not in self.onShown:
341 self.onShown.append(self.updateValues)
344 if self.wizard[currStep]["config"]["type"] == "dynamic":
345 eval("self." + self.wizard[currStep]["config"]["evaluation"])()
348 if (len(self.wizard[currStep]["evaluatedlist"]) > 0):
349 print "current:", self["list"].current
350 nextStep = self["list"].current[1]
351 if (self.wizard[currStep].has_key("listevaluation")):
352 exec("self." + self.wizard[self.currStep]["listevaluation"] + "('" + nextStep + "')")
354 self.currStep = self.getStepWithID(nextStep)
357 if ((currStep == self.numSteps and self.wizard[currStep]["nextstep"] is None) or self.wizard[currStep]["id"] == "end"): # wizard finished
358 print "wizard finished"
362 self.codeafter = True
363 self.runCode(self.wizard[currStep]["codeafter"])
364 self.prevStep = currStep
365 self.gotoStep = gotoStep
366 if not self.runCode(self.wizard[currStep]["codeafter_async"]):
367 self.afterAsyncCode()
369 if self.updateValues in self.onShown:
370 self.onShown.remove(self.updateValues)
373 print "Now: " + str(self.currStep)
379 currStep = self.currStep
382 if (self.wizard[currStep]["config"]["screen"] != None):
383 # TODO: don't die, if no run() is available
384 # there was a try/except here, but i can't see a reason
385 # for this. If there is one, please do a more specific check
386 # and/or a comment in which situation there is no run()
387 if callable(getattr(self.configInstance, "runAsync", None)):
388 if self.updateValues in self.onShown:
389 self.onShown.remove(self.updateValues)
390 self.configInstance.runAsync(self.finished)
393 self.configInstance.run()
398 print "testmode ",self.memorytestmode
399 if self.memorytestmode == 0:
400 self.memorytestmode = 1
402 self.memorytestmode = 0
404 def keyNumberGlobal(self, number):
405 if self.memorytestmode == 1:
406 self.testkey = self.testkey * 10 + number
407 if self.testkey > 10000:
408 self.testkey = self.testkey%10000
409 if self.testkey == 4599:
410 self.session.open(FactoryTest)
411 print "testkey", self.testkey
413 if (self.wizard[self.currStep]["config"]["screen"] != None):
414 self.configInstance.keyNumberGlobal(number)
416 def keyGotAscii(self):
417 if (self.wizard[self.currStep]["config"]["screen"] != None):
418 self["config"].handleKey(KEY_ASCII)
422 if (self.wizard[self.currStep]["config"]["screen"] != None):
423 self.configInstance.keyLeft()
424 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
425 self["config"].handleKey(KEY_LEFT)
430 if (self.wizard[self.currStep]["config"]["screen"] != None):
431 self.configInstance.keyRight()
432 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
433 self["config"].handleKey(KEY_RIGHT)
438 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
439 self["config"].instance.moveSelection(self["config"].instance.moveUp)
440 self.handleInputHelpers()
441 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
442 self["list"].selectPrevious()
443 if self.wizard[self.currStep].has_key("onselect"):
444 print "current:", self["list"].current
445 self.selection = self["list"].current[-1]
446 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
447 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
452 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
453 self["config"].instance.moveSelection(self["config"].instance.moveDown)
454 self.handleInputHelpers()
455 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
456 #self["list"].instance.moveSelection(self["list"].instance.moveDown)
457 self["list"].selectNext()
458 if self.wizard[self.currStep].has_key("onselect"):
459 print "current:", self["list"].current
460 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
461 #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
462 self.selection = self["list"].current[-1]
463 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
464 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
467 def selChanged(self):
470 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
471 self["config"].instance.moveSelection(self["config"].instance.moveUp)
472 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
473 if self.wizard[self.currStep].has_key("onselect"):
474 self.selection = self["list"].current[-1]
475 print "self.selection:", self.selection
476 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
478 def resetCounter(self):
479 self.timeoutCounter = self.wizard[self.currStep]["timeout"]
481 def runCode(self, code):
488 def getTranslation(self, text):
491 def updateText(self, firstset = False):
492 text = self.getTranslation(self.wizard[self.currStep]["text"])
493 if text.find("[timeout]") != -1:
494 text = text.replace("[timeout]", str(self.timeoutCounter))
495 self["text"].setText(text)
498 self["text"].setText(text)
500 def updateValues(self):
501 print "Updating values in step " + str(self.currStep)
502 # calling a step which doesn't exist can only happen if the condition in the last step is not fulfilled
503 # if a non-existing step is called, end the wizard
504 if self.currStep > len(self.wizard):
509 self.timeoutTimer.stop()
511 if self.configInstance is not None:
513 self.configInstance["config"].onSelectionChanged = []
514 del self.configInstance["config"]
515 self.configInstance.doClose()
516 self.configInstance = None
518 self.condition = True
519 exec (self.wizard[self.currStep]["condition"])
520 if not self.condition:
521 print "keys*******************:", self.wizard[self.currStep].keys()
522 if self.wizard[self.currStep].has_key("laststep"): # exit wizard, if condition of laststep doesn't hold
530 if self.wizard[self.currStep].has_key("displaytext"):
531 displaytext = self.wizard[self.currStep]["displaytext"]
533 for x in self.lcdCallbacks:
535 if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
536 self.stepHistory.append(self.currStep)
537 print "wizard step:", self.wizard[self.currStep]
540 self["step"].setText(self.getTranslation("Step ") + str(self.currStep) + "/" + str(self.numSteps))
541 if self.showStepSlider:
542 self["stepslider"].setValue(self.currStep)
544 if self.wizard[self.currStep]["timeout"] is not None:
546 self.timeoutTimer.start(1000)
548 print "wizard text", self.getTranslation(self.wizard[self.currStep]["text"])
549 self.updateText(firstset = True)
550 if self.wizard[self.currStep].has_key("displaytext"):
551 displaytext = self.wizard[self.currStep]["displaytext"]
553 for x in self.lcdCallbacks:
557 self.runCode(self.wizard[self.currStep]["code"])
558 if self.runCode(self.wizard[self.currStep]["code_async"]):
559 if self.updateValues in self.onShown:
560 self.onShown.remove(self.updateValues)
562 self.afterAsyncCode()
564 def afterAsyncCode(self):
565 if not self.updateValues in self.onShown:
566 self.onShown.append(self.updateValues)
569 if self.wizard[self.prevStep]["nextstep"] is not None:
570 self.currStep = self.getStepWithID(self.wizard[self.prevStep]["nextstep"])
571 if self.gotoStep is not None:
572 self.currStep = self.getStepWithID(self.gotoStep)
575 print "Now: " + str(self.currStep)
578 print "showing list,", self.currStep
579 for renderer in self.renderer:
580 rootrenderer = renderer
581 while renderer.source is not None:
582 print "self.list:", self["list"]
583 if renderer.source is self["list"]:
585 rootrenderer.instance.setZPosition(1)
586 renderer = renderer.source
588 #self["list"].instance.setZPosition(1)
590 if (self.wizard[self.currStep].has_key("dynamiclist")):
591 print "dynamic list, calling", self.wizard[self.currStep]["dynamiclist"]
592 newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
593 #self.wizard[self.currStep]["evaluatedlist"] = []
594 for entry in newlist:
595 #self.wizard[self.currStep]["evaluatedlist"].append(entry)
596 self.list.append(entry)
597 #del self.wizard[self.currStep]["dynamiclist"]
598 if (len(self.wizard[self.currStep]["list"]) > 0):
599 #self["list"].instance.setZPosition(2)
600 for x in self.wizard[self.currStep]["list"]:
601 self.list.append((self.getTranslation(x[0]), x[1]))
602 self.wizard[self.currStep]["evaluatedlist"] = self.list
603 self["list"].list = self.list
604 self["list"].index = 0
609 print "showing config"
610 self["config"].instance.setZPosition(1)
611 if self.wizard[self.currStep]["config"]["type"] == "dynamic":
612 print "config type is dynamic"
613 self["config"].instance.setZPosition(2)
614 self["config"].l.setList(eval("self." + self.wizard[self.currStep]["config"]["source"])())
615 elif (self.wizard[self.currStep]["config"]["screen"] != None):
616 if self.wizard[self.currStep]["config"]["type"] == "standalone":
617 print "Type is standalone"
618 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
620 self["config"].instance.setZPosition(2)
621 print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
622 if self.wizard[self.currStep]["config"]["args"] == None:
623 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
625 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
626 self["config"].l.setList(self.configInstance["config"].list)
627 callbacks = self.configInstance["config"].onSelectionChanged
628 self.configInstance["config"].destroy()
629 print "clearConfigList", self.configInstance["config"], self["config"]
630 self.configInstance["config"] = self["config"]
631 self.configInstance["config"].onSelectionChanged = callbacks
632 print "clearConfigList", self.configInstance["config"], self["config"]
634 self["config"].l.setList([])
635 self.handleInputHelpers()
639 if self.has_key("config"):
640 self["config"].hide()
642 def timeoutCounterFired(self):
643 self.timeoutCounter -= 1
644 print "timeoutCounter:", self.timeoutCounter
645 if self.timeoutCounter == 0:
646 if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
647 print "selection next item"
650 if self.wizard[self.currStep]["timeoutaction"] == "changestep":
651 self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
654 def handleInputHelpers(self):
655 if self["config"].getCurrent() is not None:
656 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
657 if self.has_key("VKeyIcon"):
658 self["VirtualKB"].setEnabled(True)
659 self["VKeyIcon"].boolean = True
660 if self.has_key("HelpWindow"):
661 if self["config"].getCurrent()[1].help_window.instance is not None:
662 helpwindowpos = self["HelpWindow"].getPosition()
663 from enigma import ePoint
664 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
666 if self.has_key("VKeyIcon"):
667 self["VirtualKB"].setEnabled(False)
668 self["VKeyIcon"].boolean = False
670 if self.has_key("VKeyIcon"):
671 self["VirtualKB"].setEnabled(False)
672 self["VKeyIcon"].boolean = False
675 from Screens.VirtualKeyBoard import VirtualKeyBoard
676 self.currentConfigIndex = self["config"].getCurrentIndex()
677 self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].getValue())
679 def VirtualKeyBoardCallback(self, callback = None):
680 if callback is not None and len(callback):
681 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
682 if self.has_key("HelpWindow"):
683 if self["config"].getCurrent()[1].help_window.instance is not None:
684 helpwindowpos = self["HelpWindow"].getPosition()
685 from enigma import ePoint
686 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
687 self["config"].instance.moveSelectionTo(self.currentConfigIndex)
688 self["config"].setCurrentIndex(self.currentConfigIndex)
689 self["config"].getCurrent()[1].setValue(callback)
690 self["config"].invalidate(self["config"].getCurrent())
697 def registerWizard(self, wizard, precondition, priority = 0):
698 self.wizards.append((wizard, precondition, priority))
700 def getWizards(self):
701 # x[1] is precondition
702 for wizard in self.wizards:
703 wizard[0].isLastWizard = False
704 if len(self.wizards) > 0:
705 self.wizards[-1][0].isLastWizard = True
706 return [(x[2], x[0]) for x in self.wizards if x[1] == 1]
708 wizardManager = WizardManager()