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)
390 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
391 self["config"].handleKey(KEY_0 + number)
393 def keyGotAscii(self):
394 if (self.wizard[self.currStep]["config"]["screen"] != None):
395 self["config"].handleKey(KEY_ASCII)
396 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
397 self["config"].handleKey(KEY_ASCII)
401 if (self.wizard[self.currStep]["config"]["screen"] != None):
402 self.configInstance.keyLeft()
403 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
404 self["config"].handleKey(KEY_LEFT)
409 if (self.wizard[self.currStep]["config"]["screen"] != None):
410 self.configInstance.keyRight()
411 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
412 self["config"].handleKey(KEY_RIGHT)
417 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
418 self["config"].instance.moveSelection(self["config"].instance.moveUp)
419 self.handleInputHelpers()
420 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
421 self["list"].selectPrevious()
422 if self.wizard[self.currStep].has_key("onselect"):
423 print "current:", self["list"].current
424 self.selection = self["list"].current[-1]
425 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
426 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
431 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
432 self["config"].instance.moveSelection(self["config"].instance.moveDown)
433 self.handleInputHelpers()
434 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
435 #self["list"].instance.moveSelection(self["list"].instance.moveDown)
436 self["list"].selectNext()
437 if self.wizard[self.currStep].has_key("onselect"):
438 print "current:", self["list"].current
439 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
440 #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
441 self.selection = self["list"].current[-1]
442 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
443 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
446 def selChanged(self):
449 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
450 self["config"].instance.moveSelection(self["config"].instance.moveUp)
451 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
452 if self.wizard[self.currStep].has_key("onselect"):
453 self.selection = self["list"].current[-1]
454 print "self.selection:", self.selection
455 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
457 def resetCounter(self):
458 self.timeoutCounter = self.wizard[self.currStep]["timeout"]
460 def runCode(self, code):
467 def getTranslation(self, text):
470 def updateText(self, firstset = False):
471 text = self.getTranslation(self.wizard[self.currStep]["text"])
472 if text.find("[timeout]") != -1:
473 text = text.replace("[timeout]", str(self.timeoutCounter))
474 self["text"].setText(text)
477 self["text"].setText(text)
479 def updateValues(self):
480 print "Updating values in step " + str(self.currStep)
481 # calling a step which doesn't exist can only happen if the condition in the last step is not fulfilled
482 # if a non-existing step is called, end the wizard
483 if self.currStep > len(self.wizard):
488 self.timeoutTimer.stop()
490 if self.configInstance is not None:
492 self.configInstance["config"].onSelectionChanged = []
493 del self.configInstance["config"]
494 self.configInstance.doClose()
495 self.configInstance = None
497 self.condition = True
498 exec (self.wizard[self.currStep]["condition"])
499 if not self.condition:
500 print "keys*******************:", self.wizard[self.currStep].keys()
501 if self.wizard[self.currStep].has_key("laststep"): # exit wizard, if condition of laststep doesn't hold
509 if self.wizard[self.currStep].has_key("displaytext"):
510 displaytext = self.wizard[self.currStep]["displaytext"]
512 for x in self.lcdCallbacks:
514 if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
515 self.stepHistory.append(self.currStep)
516 print "wizard step:", self.wizard[self.currStep]
519 self["step"].setText(self.getTranslation("Step ") + str(self.currStep) + "/" + str(self.numSteps))
520 if self.showStepSlider:
521 self["stepslider"].setValue(self.currStep)
523 if self.wizard[self.currStep]["timeout"] is not None:
525 self.timeoutTimer.start(1000)
527 print "wizard text", self.getTranslation(self.wizard[self.currStep]["text"])
528 self.updateText(firstset = True)
529 if self.wizard[self.currStep].has_key("displaytext"):
530 displaytext = self.wizard[self.currStep]["displaytext"]
532 for x in self.lcdCallbacks:
536 self.runCode(self.wizard[self.currStep]["code"])
537 if self.runCode(self.wizard[self.currStep]["code_async"]):
538 if self.updateValues in self.onShown:
539 self.onShown.remove(self.updateValues)
541 self.afterAsyncCode()
543 def afterAsyncCode(self):
544 if not self.updateValues in self.onShown:
545 self.onShown.append(self.updateValues)
548 if self.wizard[self.prevStep]["nextstep"] is not None:
549 self.currStep = self.getStepWithID(self.wizard[self.prevStep]["nextstep"])
550 if self.gotoStep is not None:
551 self.currStep = self.getStepWithID(self.gotoStep)
554 print "Now: " + str(self.currStep)
557 print "showing list,", self.currStep
558 for renderer in self.renderer:
559 rootrenderer = renderer
560 while renderer.source is not None:
561 print "self.list:", self["list"]
562 if renderer.source is self["list"]:
564 rootrenderer.instance.setZPosition(1)
565 renderer = renderer.source
567 #self["list"].instance.setZPosition(1)
569 if (self.wizard[self.currStep].has_key("dynamiclist")):
570 print "dynamic list, calling", self.wizard[self.currStep]["dynamiclist"]
571 newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
572 #self.wizard[self.currStep]["evaluatedlist"] = []
573 for entry in newlist:
574 #self.wizard[self.currStep]["evaluatedlist"].append(entry)
575 self.list.append(entry)
576 #del self.wizard[self.currStep]["dynamiclist"]
577 if (len(self.wizard[self.currStep]["list"]) > 0):
578 #self["list"].instance.setZPosition(2)
579 for x in self.wizard[self.currStep]["list"]:
580 self.list.append((self.getTranslation(x[0]), x[1]))
581 self.wizard[self.currStep]["evaluatedlist"] = self.list
582 self["list"].list = self.list
583 self["list"].index = 0
588 print "showing config"
589 self["config"].instance.setZPosition(1)
590 if self.wizard[self.currStep]["config"]["type"] == "dynamic":
591 print "config type is dynamic"
592 self["config"].instance.setZPosition(2)
593 self["config"].l.setList(eval("self." + self.wizard[self.currStep]["config"]["source"])())
594 elif (self.wizard[self.currStep]["config"]["screen"] != None):
595 if self.wizard[self.currStep]["config"]["type"] == "standalone":
596 print "Type is standalone"
597 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
599 self["config"].instance.setZPosition(2)
600 print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
601 if self.wizard[self.currStep]["config"]["args"] == None:
602 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
604 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
605 self["config"].l.setList(self.configInstance["config"].list)
606 callbacks = self.configInstance["config"].onSelectionChanged
607 self.configInstance["config"].destroy()
608 print "clearConfigList", self.configInstance["config"], self["config"]
609 self.configInstance["config"] = self["config"]
610 self.configInstance["config"].onSelectionChanged = callbacks
611 print "clearConfigList", self.configInstance["config"], self["config"]
613 self["config"].l.setList([])
614 self.handleInputHelpers()
618 if self.has_key("config"):
619 self["config"].hide()
621 def timeoutCounterFired(self):
622 self.timeoutCounter -= 1
623 print "timeoutCounter:", self.timeoutCounter
624 if self.timeoutCounter == 0:
625 if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
626 print "selection next item"
629 if self.wizard[self.currStep]["timeoutaction"] == "changestep":
630 self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
633 def handleInputHelpers(self):
634 if self["config"].getCurrent() is not None:
635 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
636 if self.has_key("VKeyIcon"):
637 self["VirtualKB"].setEnabled(True)
638 self["VKeyIcon"].boolean = True
639 if self.has_key("HelpWindow"):
640 if self["config"].getCurrent()[1].help_window.instance is not None:
641 helpwindowpos = self["HelpWindow"].getPosition()
642 from enigma import ePoint
643 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
645 if self.has_key("VKeyIcon"):
646 self["VirtualKB"].setEnabled(False)
647 self["VKeyIcon"].boolean = False
649 if self.has_key("VKeyIcon"):
650 self["VirtualKB"].setEnabled(False)
651 self["VKeyIcon"].boolean = False
654 from Screens.VirtualKeyBoard import VirtualKeyBoard
655 self.currentConfigIndex = self["config"].getCurrentIndex()
656 self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].getValue())
658 def VirtualKeyBoardCallback(self, callback = None):
659 if callback is not None and len(callback):
660 if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
661 if self.has_key("HelpWindow"):
662 if self["config"].getCurrent()[1].help_window.instance is not None:
663 helpwindowpos = self["HelpWindow"].getPosition()
664 from enigma import ePoint
665 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
666 self["config"].instance.moveSelectionTo(self.currentConfigIndex)
667 self["config"].setCurrentIndex(self.currentConfigIndex)
668 self["config"].getCurrent()[1].setValue(callback)
669 self["config"].invalidate(self["config"].getCurrent())
676 def registerWizard(self, wizard, precondition, priority = 0):
677 self.wizards.append((wizard, precondition, priority))
679 def getWizards(self):
680 # x[1] is precondition
681 for wizard in self.wizards:
682 wizard[0].isLastWizard = False
683 if len(self.wizards) > 0:
684 self.wizards[-1][0].isLastWizard = True
685 return [(x[2], x[0]) for x in self.wizards if x[1] == 1]
687 wizardManager = WizardManager()