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)
79 self.onClose.append(self.delReferences)
81 self["actions"] = NumberActionMap(["WizardActions", "NumberActions"],
89 "1": self.keyNumberGlobal,
90 "2": self.keyNumberGlobal,
91 "3": self.keyNumberGlobal,
92 "4": self.keyNumberGlobal,
93 "5": self.keyNumberGlobal,
94 "6": self.keyNumberGlobal,
95 "7": self.keyNumberGlobal,
96 "8": self.keyNumberGlobal,
97 "9": self.keyNumberGlobal,
98 "0": self.keyNumberGlobal
101 #self["actions"] = HelpableActionMap(self, "OkCancelActions",
103 #"ok": (self.ok, _("Close this Screen...")),
108 if self.currStep < 1:
114 if (self.wizard[self.currStep]["config"]["screen"] != None):
115 try: # don't die, if no run() is available
116 self.configInstance.run()
118 print "Failed to run configInstance"
120 if (len(self.wizard[self.currStep]["list"]) > 0):
121 nextStep = self.wizard[self.currStep]["list"][self["list"].l.getCurrentSelectionIndex()][1]
122 if nextStep == "end":
123 self.currStep = self.numSteps
124 elif nextStep == "next":
127 self.currStep = int(nextStep) - 1
129 if (self.currStep == self.numSteps): # wizard finished
130 config.misc.firstrun.value = 0;
131 config.misc.firstrun.save()
137 print "Now: " + str(self.currStep)
139 def keyNumberGlobal(self, number):
140 if (self.wizard[self.currStep]["config"]["screen"] != None):
141 self.configInstance.keyNumberGlobal(number)
144 if (self.wizard[self.currStep]["config"]["screen"] != None):
145 self.configInstance.keyLeft()
149 if (self.wizard[self.currStep]["config"]["screen"] != None):
150 self.configInstance.keyRight()
154 if (self.wizard[self.currStep]["config"]["screen"] != None):
155 self["config"].instance.moveSelection(self["config"].instance.moveUp)
156 elif (len(self.wizard[self.currStep]["list"]) > 0):
157 self["list"].instance.moveSelection(self["list"].instance.moveUp)
161 if (self.wizard[self.currStep]["config"]["screen"] != None):
162 self["config"].instance.moveSelection(self["config"].instance.moveDown)
163 elif (len(self.wizard[self.currStep]["list"]) > 0):
164 self["list"].instance.moveSelection(self["list"].instance.moveDown)
167 def updateValues(self):
168 print "Updating values in step " + str(self.currStep)
169 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
170 self["stepslider"].setValue(self.currStep)
172 print _(self.wizard[self.currStep]["text"])
173 self["text"].setText(_(self.wizard[self.currStep]["text"]))
175 if self.wizard[self.currStep]["code"] != "":
176 print self.wizard[self.currStep]["code"]
177 exec(self.wizard[self.currStep]["code"])
179 self["list"].instance.setZPosition(1)
181 if (len(self.wizard[self.currStep]["list"]) > 0):
182 self["list"].instance.setZPosition(2)
183 for x in self.wizard[self.currStep]["list"]:
184 self.list.append((_(x[0]), None))
185 self["list"].l.setList(self.list)
187 self["config"].instance.setZPosition(1)
188 if (self.wizard[self.currStep]["config"]["screen"] != None):
189 if self.wizard[self.currStep]["config"]["type"] == "standalone":
190 print "Type is standalone"
191 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
193 self["config"].instance.setZPosition(2)
194 print self.wizard[self.currStep]["config"]["screen"]
195 if self.wizard[self.currStep]["config"]["args"] == None:
196 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
198 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
199 self["config"].l.setList(self.configInstance["config"].list)
200 self.configInstance["config"] = self["config"]
202 self["config"].l.setList([])
204 def delReferences(self):
205 del self.configInstance
211 def registerWizard(self, wizard):
212 self.wizards.append(wizard)
214 def getWizards(self):
215 if config.misc.firstrun.value:
220 wizardManager = WizardManager()