1 from Screen import Screen
5 from Screens.HelpMenu import HelpableScreen
6 from Components.Label import Label
7 from Components.Slider import Slider
8 from Components.ActionMap import HelpableActionMap, NumberActionMap
9 from Components.config import config, configElementBoolean
10 from Components.Pixmap import *
11 from Components.MenuList import MenuList
12 from Components.ConfigList import ConfigList
14 from xml.sax import make_parser
15 from xml.sax.handler import ContentHandler
17 config.misc.firstrun = configElementBoolean("config.misc.firstrun", 1);
19 class Wizard(Screen, HelpableScreen):
21 class parseWizard(ContentHandler):
22 def __init__(self, wizard):
23 self.isPointsElement, self.isReboundsElement = 0, 0
27 def startElement(self, name, attrs):
29 self.currContent = name
31 self.lastStep = int(attrs.get('number'))
32 self.wizard[self.lastStep] = {"text": "", "list": [], "config": {"screen": None, "args": None, "type": "" }, "code": ""}
33 elif (name == "text"):
34 self.wizard[self.lastStep]["text"] = string.replace(str(attrs.get('value')), "\\n", "\n")
35 elif (name == "listentry"):
36 self.wizard[self.lastStep]["list"].append((str(attrs.get('caption')), str(attrs.get('step'))))
37 elif (name == "config"):
38 exec "from Screens." + str(attrs.get('module')) + " import *"
39 self.wizard[self.lastStep]["config"]["screen"] = eval(str(attrs.get('screen')))
40 if (attrs.has_key('args')):
42 self.wizard[self.lastStep]["config"]["args"] = str(attrs.get('args'))
43 self.wizard[self.lastStep]["config"]["type"] = str(attrs.get('type'))
44 def endElement(self, name):
47 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
49 def characters(self, ch):
50 if self.currContent == "code":
51 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
53 def __init__(self, session):
54 Screen.__init__(self, session)
55 HelpableScreen.__init__(self)
58 parser = make_parser()
59 print "Reading " + self.xmlfile
60 wizardHandler = self.parseWizard(self.wizard)
61 parser.setContentHandler(wizardHandler)
62 parser.parse('/usr/share/enigma2/' + self.xmlfile)
64 self.numSteps = len(self.wizard)
67 self["text"] = Label()
69 self["config"] = ConfigList([])
71 self["step"] = Label()
73 self["stepslider"] = Slider(1, self.numSteps)
76 self["list"] = MenuList(self.list)
78 self.onShown.append(self.updateValues)
80 self["actions"] = NumberActionMap(["WizardActions", "NumberActions"],
88 "1": self.keyNumberGlobal,
89 "2": self.keyNumberGlobal,
90 "3": self.keyNumberGlobal,
91 "4": self.keyNumberGlobal,
92 "5": self.keyNumberGlobal,
93 "6": self.keyNumberGlobal,
94 "7": self.keyNumberGlobal,
95 "8": self.keyNumberGlobal,
96 "9": self.keyNumberGlobal,
97 "0": self.keyNumberGlobal
100 #self["actions"] = HelpableActionMap(self, "OkCancelActions",
102 #"ok": (self.ok, _("Close this Screen...")),
107 if self.currStep < 1:
113 if (self.wizard[self.currStep]["config"]["screen"] != None):
114 try: # don't die, if no run() is available
115 self.configInstance.run()
117 print "Failed to run configInstance"
119 if (len(self.wizard[self.currStep]["list"]) > 0):
120 nextStep = self.wizard[self.currStep]["list"][self["list"].l.getCurrentSelectionIndex()][1]
121 if nextStep == "end":
122 self.currStep = self.numSteps
123 elif nextStep == "next":
126 self.currStep = int(nextStep) - 1
128 if (self.currStep == self.numSteps): # wizard finished
129 config.misc.firstrun.value = 0;
130 config.misc.firstrun.save()
136 print "Now: " + str(self.currStep)
138 def keyNumberGlobal(self, number):
139 if (self.wizard[self.currStep]["config"]["screen"] != None):
140 self.configInstance.keyNumberGlobal(number)
143 if (self.wizard[self.currStep]["config"]["screen"] != None):
144 self.configInstance.keyLeft()
148 if (self.wizard[self.currStep]["config"]["screen"] != None):
149 self.configInstance.keyRight()
153 if (self.wizard[self.currStep]["config"]["screen"] != None):
154 self["config"].instance.moveSelection(self["config"].instance.moveUp)
155 elif (len(self.wizard[self.currStep]["list"]) > 0):
156 self["list"].instance.moveSelection(self["list"].instance.moveUp)
160 if (self.wizard[self.currStep]["config"]["screen"] != None):
161 self["config"].instance.moveSelection(self["config"].instance.moveDown)
162 elif (len(self.wizard[self.currStep]["list"]) > 0):
163 self["list"].instance.moveSelection(self["list"].instance.moveDown)
166 def updateValues(self):
167 print "Updating values in step " + str(self.currStep)
168 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
169 self["stepslider"].setValue(self.currStep)
171 print _(self.wizard[self.currStep]["text"])
172 self["text"].setText(_(self.wizard[self.currStep]["text"]))
174 if self.wizard[self.currStep]["code"] != "":
175 print self.wizard[self.currStep]["code"]
176 exec(self.wizard[self.currStep]["code"])
178 self["list"].instance.setZPosition(1)
180 if (len(self.wizard[self.currStep]["list"]) > 0):
181 self["list"].instance.setZPosition(2)
182 for x in self.wizard[self.currStep]["list"]:
183 self.list.append((_(x[0]), None))
184 self["list"].l.setList(self.list)
186 self["config"].instance.setZPosition(1)
187 if (self.wizard[self.currStep]["config"]["screen"] != None):
188 if self.wizard[self.currStep]["config"]["type"] == "standalone":
189 print "Type is standalone"
190 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
192 self["config"].instance.setZPosition(2)
193 print self.wizard[self.currStep]["config"]["screen"]
194 if self.wizard[self.currStep]["config"]["args"] == None:
195 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
197 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
198 self["config"].l.setList(self.configInstance["config"].list)
199 self.configInstance["config"] = self["config"]
201 self["config"].l.setList([])
207 def registerWizard(self, wizard):
208 self.wizards.append(wizard)
210 def getWizards(self):
211 if config.misc.firstrun.value:
216 wizardManager = WizardManager()