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)
85 self["actions"] = NumberActionMap(["WizardActions", "NumberActions"],
93 "1": self.keyNumberGlobal,
94 "2": self.keyNumberGlobal,
95 "3": self.keyNumberGlobal,
96 "4": self.keyNumberGlobal,
97 "5": self.keyNumberGlobal,
98 "6": self.keyNumberGlobal,
99 "7": self.keyNumberGlobal,
100 "8": self.keyNumberGlobal,
101 "9": self.keyNumberGlobal,
102 "0": self.keyNumberGlobal
105 #self["actions"] = HelpableActionMap(self, "OkCancelActions",
107 #"ok": (self.ok, _("Close this Screen...")),
112 if self.currStep < 1:
118 if (self.wizard[self.currStep]["config"]["screen"] != None):
119 try: # don't die, if no run() is available
120 self.configInstance.run()
122 print "Failed to run configInstance"
124 if (len(self.wizard[self.currStep]["list"]) > 0):
125 nextStep = self.wizard[self.currStep]["list"][self["list"].l.getCurrentSelectionIndex()][1]
126 if nextStep == "end":
127 self.currStep = self.numSteps
128 elif nextStep == "next":
131 self.currStep = int(nextStep) - 1
133 if (self.currStep == self.numSteps): # wizard finished
134 config.misc.firstrun.value = 0;
135 config.misc.firstrun.save()
141 print "Now: " + str(self.currStep)
143 def keyNumberGlobal(self, number):
144 if (self.wizard[self.currStep]["config"]["screen"] != None):
145 self.configInstance.keyNumberGlobal(number)
148 if (self.wizard[self.currStep]["config"]["screen"] != None):
149 self.configInstance.keyLeft()
153 if (self.wizard[self.currStep]["config"]["screen"] != None):
154 self.configInstance.keyRight()
158 if (self.wizard[self.currStep]["config"]["screen"] != None):
159 self["config"].instance.moveSelection(self["config"].instance.moveUp)
160 elif (len(self.wizard[self.currStep]["list"]) > 0):
161 self["list"].instance.moveSelection(self["list"].instance.moveUp)
165 if (self.wizard[self.currStep]["config"]["screen"] != None):
166 self["config"].instance.moveSelection(self["config"].instance.moveDown)
167 elif (len(self.wizard[self.currStep]["list"]) > 0):
168 self["list"].instance.moveSelection(self["list"].instance.moveDown)
171 def updateValues(self):
172 print "Updating values in step " + str(self.currStep)
174 self.condition = True
175 exec (self.wizard[self.currStep]["condition"])
177 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
178 self["stepslider"].setValue(self.currStep)
180 print _(self.wizard[self.currStep]["text"])
181 self["text"].setText(_(self.wizard[self.currStep]["text"]))
183 if self.wizard[self.currStep]["code"] != "":
184 print self.wizard[self.currStep]["code"]
185 exec(self.wizard[self.currStep]["code"])
187 self["list"].instance.setZPosition(1)
189 if (len(self.wizard[self.currStep]["list"]) > 0):
190 self["list"].instance.setZPosition(2)
191 for x in self.wizard[self.currStep]["list"]:
192 self.list.append((_(x[0]), None))
193 self["list"].l.setList(self.list)
195 self["config"].instance.setZPosition(1)
196 if (self.wizard[self.currStep]["config"]["screen"] != None):
197 if self.wizard[self.currStep]["config"]["type"] == "standalone":
198 print "Type is standalone"
199 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
201 self["config"].instance.setZPosition(2)
202 print self.wizard[self.currStep]["config"]["screen"]
203 if self.wizard[self.currStep]["config"]["args"] == None:
204 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
206 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
207 self["config"].l.setList(self.configInstance["config"].list)
208 self.configInstance["config"] = self["config"]
210 self["config"].l.setList([])
211 else: # condition false
219 def registerWizard(self, wizard):
220 self.wizards.append(wizard)
222 def getWizards(self):
223 if config.misc.firstrun.value:
228 wizardManager = WizardManager()