+ print "Now: " + str(self.currStep)
+
+
+ def ok(self):
+ print "OK"
+ if self.disableKeys:
+ return
+ currStep = self.currStep
+
+ if self.showConfig:
+ if (self.wizard[currStep]["config"]["screen"] != None):
+ # TODO: don't die, if no run() is available
+ # there was a try/except here, but i can't see a reason
+ # for this. If there is one, please do a more specific check
+ # and/or a comment in which situation there is no run()
+ if callable(getattr(self.configInstance, "runAsync", None)):
+ self.onShown.remove(self.updateValues)
+ self.configInstance.runAsync(self.finished)
+ return
+ else:
+ self.configInstance.run()
+ self.finished()
+
+ def keyNumberGlobal(self, number):
+ if (self.wizard[self.currStep]["config"]["screen"] != None):
+ self.configInstance.keyNumberGlobal(number)
+
+ def left(self):
+ self.resetCounter()
+ if (self.wizard[self.currStep]["config"]["screen"] != None):
+ self.configInstance.keyLeft()
+ elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
+ self["config"].handleKey(KEY_LEFT)
+ print "left"
+
+ def right(self):
+ self.resetCounter()
+ if (self.wizard[self.currStep]["config"]["screen"] != None):
+ self.configInstance.keyRight()
+ elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
+ self["config"].handleKey(KEY_RIGHT)
+ print "right"
+
+ def up(self):
+ self.resetCounter()
+ if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
+ self["config"].instance.moveSelection(self["config"].instance.moveUp)
+ elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
+ self["list"].selectPrevious()
+ if self.wizard[self.currStep].has_key("onselect"):
+ print "current:", self["list"].current
+ self.selection = self["list"].current[-1]
+ #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
+ exec("self." + self.wizard[self.currStep]["onselect"] + "()")
+ print "up"
+
+ def down(self):
+ self.resetCounter()
+ if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
+ self["config"].instance.moveSelection(self["config"].instance.moveDown)
+ elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
+ #self["list"].instance.moveSelection(self["list"].instance.moveDown)
+ self["list"].selectNext()
+ if self.wizard[self.currStep].has_key("onselect"):
+ print "current:", self["list"].current
+ #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
+ #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
+ self.selection = self["list"].current[-1]
+ #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
+ exec("self." + self.wizard[self.currStep]["onselect"] + "()")
+ print "down"
+
+ def selChanged(self):
+ self.resetCounter()
+
+ if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
+ self["config"].instance.moveSelection(self["config"].instance.moveUp)
+ elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
+ if self.wizard[self.currStep].has_key("onselect"):
+ self.selection = self["list"].current[-1]
+ print "self.selection:", self.selection
+ exec("self." + self.wizard[self.currStep]["onselect"] + "()")
+
+ def resetCounter(self):
+ self.timeoutCounter = self.wizard[self.currStep]["timeout"]
+
+ def runCode(self, code):
+ if code != "":
+ print "code", code
+ exec(code)
+
+ def getTranslation(self, text):
+ return _(text)
+
+ def updateText(self, firstset = False):
+ text = self.getTranslation(self.wizard[self.currStep]["text"])
+ if text.find("[timeout]") != -1:
+ text = text.replace("[timeout]", str(self.timeoutCounter))
+ self["text"].setText(text)
+ else:
+ if firstset:
+ self["text"].setText(text)
+
+ def updateValues(self):
+ print "Updating values in step " + str(self.currStep)
+ # calling a step which doesn't exist can only happen if the condition in the last step is not fulfilled
+ # if a non-existing step is called, end the wizard
+ if self.currStep > len(self.wizard):
+ self.markDone()
+ self.close()
+ return
+
+ self.timeoutTimer.stop()
+
+ if self.configInstance is not None:
+ # remove callbacks
+ self.configInstance["config"].onSelectionChanged = []
+ del self.configInstance["config"]
+ self.configInstance.doClose()
+ self.configInstance = None
+
+ self.condition = True
+ exec (self.wizard[self.currStep]["condition"])
+ if self.condition:
+ if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
+ self.stepHistory.append(self.currStep)
+ print "wizard step:", self.wizard[self.currStep]
+
+ if self.showSteps:
+ self["step"].setText(self.getTranslation("Step ") + str(self.currStep) + "/" + str(self.numSteps))
+ if self.showStepSlider:
+ self["stepslider"].setValue(self.currStep)
+
+ if self.wizard[self.currStep]["timeout"] is not None:
+ self.resetCounter()
+ self.timeoutTimer.start(1000)
+
+ print "wizard text", self.getTranslation(self.wizard[self.currStep]["text"])
+ self.updateText(firstset = True)
+ if self.wizard[self.currStep].has_key("displaytext"):
+ displaytext = self.wizard[self.currStep]["displaytext"]
+ print "set LCD text"
+ for x in self.lcdCallbacks:
+ x(displaytext)
+
+ self.runCode(self.wizard[self.currStep]["code"])
+
+ if self.showList:
+ print "showing list,", self.currStep
+ for renderer in self.renderer:
+ rootrenderer = renderer
+ while renderer.source is not None:
+ print "self.list:", self["list"]
+ if renderer.source is self["list"]:
+ print "setZPosition"
+ rootrenderer.instance.setZPosition(1)
+ renderer = renderer.source
+
+ #self["list"].instance.setZPosition(1)
+ self.list = []
+ if (self.wizard[self.currStep].has_key("dynamiclist")):
+ print "dynamic list, calling", self.wizard[self.currStep]["dynamiclist"]
+ newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
+ #self.wizard[self.currStep]["evaluatedlist"] = []
+ for entry in newlist:
+ #self.wizard[self.currStep]["evaluatedlist"].append(entry)
+ self.list.append(entry)
+ #del self.wizard[self.currStep]["dynamiclist"]
+ if (len(self.wizard[self.currStep]["list"]) > 0):
+ #self["list"].instance.setZPosition(2)
+ for x in self.wizard[self.currStep]["list"]:
+ self.list.append((self.getTranslation(x[0]), x[1]))
+ self.wizard[self.currStep]["evaluatedlist"] = self.list
+ self["list"].list = self.list
+ self["list"].index = 0
+ else:
+ self["list"].hide()
+
+ if self.showConfig:
+ print "showing config"
+ self["config"].instance.setZPosition(1)
+ if self.wizard[self.currStep]["config"]["type"] == "dynamic":
+ print "config type is dynamic"
+ self["config"].instance.setZPosition(2)
+ self["config"].l.setList(eval("self." + self.wizard[self.currStep]["config"]["source"])())
+ elif (self.wizard[self.currStep]["config"]["screen"] != None):
+ if self.wizard[self.currStep]["config"]["type"] == "standalone":
+ print "Type is standalone"
+ self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
+ else:
+ self["config"].instance.setZPosition(2)
+ print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
+ if self.wizard[self.currStep]["config"]["args"] == None:
+ self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
+ else:
+ self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
+ self["config"].l.setList(self.configInstance["config"].list)
+ callbacks = self.configInstance["config"].onSelectionChanged
+ self.configInstance["config"].destroy()
+ print "clearConfigList", self.configInstance["config"], self["config"]
+ self.configInstance["config"] = self["config"]
+ self.configInstance["config"].onSelectionChanged = callbacks
+ print "clearConfigList", self.configInstance["config"], self["config"]
+ else:
+ self["config"].l.setList([])
+ else:
+ if self.has_key("config"):
+ self["config"].hide()
+ else: # condition false
+ self.currStep += 1
+ self.updateValues()
+
+ def timeoutCounterFired(self):
+ self.timeoutCounter -= 1
+ print "timeoutCounter:", self.timeoutCounter
+ if self.timeoutCounter == 0:
+ if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
+ print "selection next item"
+ self.down()
+ else:
+ if self.wizard[self.currStep]["timeoutaction"] == "changestep":
+ self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
+ self.updateText()