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] = {"condition": "", "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 elif (name == "condition"):
46 def endElement(self, name):
49 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
50 elif name == 'condition':
51 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"].strip()
53 def characters(self, ch):
54 if self.currContent == "code":
55 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
56 elif self.currContent == "condition":
57 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"] + ch
58 def __init__(self, session):
59 Screen.__init__(self, session)
60 HelpableScreen.__init__(self)
63 parser = make_parser()
64 print "Reading " + self.xmlfile
65 wizardHandler = self.parseWizard(self.wizard)
66 parser.setContentHandler(wizardHandler)
67 parser.parse('/usr/share/enigma2/' + self.xmlfile)
69 self.numSteps = len(self.wizard)
72 self["text"] = Label()
74 self["config"] = ConfigList([])
76 self["step"] = Label()
78 self["stepslider"] = Slider(1, self.numSteps)
81 self["list"] = MenuList(self.list)
83 self.onShown.append(self.updateValues)
84 self.onClose.append(self.delReferences)
86 self["actions"] = NumberActionMap(["WizardActions", "NumberActions"],
94 "1": self.keyNumberGlobal,
95 "2": self.keyNumberGlobal,
96 "3": self.keyNumberGlobal,
97 "4": self.keyNumberGlobal,
98 "5": self.keyNumberGlobal,
99 "6": self.keyNumberGlobal,
100 "7": self.keyNumberGlobal,
101 "8": self.keyNumberGlobal,
102 "9": self.keyNumberGlobal,
103 "0": self.keyNumberGlobal
106 #self["actions"] = HelpableActionMap(self, "OkCancelActions",
108 #"ok": (self.ok, _("Close this Screen...")),
113 if self.currStep < 1:
119 if (self.wizard[self.currStep]["config"]["screen"] != None):
120 try: # don't die, if no run() is available
121 self.configInstance.run()
123 print "Failed to run configInstance"
125 if (len(self.wizard[self.currStep]["list"]) > 0):
126 nextStep = self.wizard[self.currStep]["list"][self["list"].l.getCurrentSelectionIndex()][1]
127 if nextStep == "end":
128 self.currStep = self.numSteps
129 elif nextStep == "next":
132 self.currStep = int(nextStep) - 1
134 if (self.currStep == self.numSteps): # wizard finished
135 config.misc.firstrun.value = 0;
136 config.misc.firstrun.save()
142 print "Now: " + str(self.currStep)
144 def keyNumberGlobal(self, number):
145 if (self.wizard[self.currStep]["config"]["screen"] != None):
146 self.configInstance.keyNumberGlobal(number)
149 if (self.wizard[self.currStep]["config"]["screen"] != None):
150 self.configInstance.keyLeft()
154 if (self.wizard[self.currStep]["config"]["screen"] != None):
155 self.configInstance.keyRight()
159 if (self.wizard[self.currStep]["config"]["screen"] != None):
160 self["config"].instance.moveSelection(self["config"].instance.moveUp)
161 elif (len(self.wizard[self.currStep]["list"]) > 0):
162 self["list"].instance.moveSelection(self["list"].instance.moveUp)
166 if (self.wizard[self.currStep]["config"]["screen"] != None):
167 self["config"].instance.moveSelection(self["config"].instance.moveDown)
168 elif (len(self.wizard[self.currStep]["list"]) > 0):
169 self["list"].instance.moveSelection(self["list"].instance.moveDown)
172 def updateValues(self):
173 print "Updating values in step " + str(self.currStep)
175 self.condition = True
176 exec (self.wizard[self.currStep]["condition"])
178 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
179 self["stepslider"].setValue(self.currStep)
181 print _(self.wizard[self.currStep]["text"])
182 self["text"].setText(_(self.wizard[self.currStep]["text"]))
184 if self.wizard[self.currStep]["code"] != "":
185 print self.wizard[self.currStep]["code"]
186 exec(self.wizard[self.currStep]["code"])
188 self["list"].instance.setZPosition(1)
190 if (len(self.wizard[self.currStep]["list"]) > 0):
191 self["list"].instance.setZPosition(2)
192 for x in self.wizard[self.currStep]["list"]:
193 self.list.append((_(x[0]), None))
194 self["list"].l.setList(self.list)
196 self["config"].instance.setZPosition(1)
197 if (self.wizard[self.currStep]["config"]["screen"] != None):
198 if self.wizard[self.currStep]["config"]["type"] == "standalone":
199 print "Type is standalone"
200 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
202 self["config"].instance.setZPosition(2)
203 print self.wizard[self.currStep]["config"]["screen"]
204 if self.wizard[self.currStep]["config"]["args"] == None:
205 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
207 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
208 self["config"].l.setList(self.configInstance["config"].list)
209 self.configInstance["config"] = self["config"]
211 self["config"].l.setList([])
212 else: # condition false
216 def delReferences(self):
217 del self.configInstance
223 def registerWizard(self, wizard):
224 self.wizards.append(wizard)
226 def getWizards(self):
227 if config.misc.firstrun.value:
232 wizardManager = WizardManager()