1 from Screen import Screen
3 from Screens.HelpMenu import HelpableScreen
4 from Components.Label import Label
5 from Components.Slider import Slider
6 from Components.ActionMap import HelpableActionMap, NumberActionMap
7 from Components.config import config, configElementBoolean
8 from Components.Pixmap import *
9 from Components.MenuList import MenuList
10 from Components.ConfigList import ConfigList
12 from xml.sax import make_parser
13 from xml.sax.handler import ContentHandler
15 config.misc.firstrun = configElementBoolean("config.misc.firstrun", 1);
17 class Wizard(Screen, HelpableScreen):
19 class parseWizard(ContentHandler):
20 def __init__(self, wizard):
21 self.isPointsElement, self.isReboundsElement = 0, 0
25 def startElement(self, name, attrs):
27 self.currContent = name
29 self.lastStep = int(attrs.get('number'))
30 self.wizard[self.lastStep] = {"text": "", "list": [], "config": {"screen": None, "args": None, "type": "" }, "code": ""}
31 elif (name == "text"):
32 self.wizard[self.lastStep]["text"] = _(str(attrs.get('value')))
33 elif (name == "listentry"):
34 self.wizard[self.lastStep]["list"].append((str(attrs.get('caption')), str(attrs.get('step'))))
35 elif (name == "config"):
36 exec "from Screens." + str(attrs.get('module')) + " import *"
37 self.wizard[self.lastStep]["config"]["screen"] = eval(str(attrs.get('screen')))
38 if (attrs.has_key('args')):
40 self.wizard[self.lastStep]["config"]["args"] = str(attrs.get('args'))
41 self.wizard[self.lastStep]["config"]["type"] = str(attrs.get('type'))
42 def endElement(self, name):
45 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
47 def characters(self, ch):
48 if self.currContent == "code":
49 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
51 def __init__(self, session):
52 Screen.__init__(self, session)
53 HelpableScreen.__init__(self)
56 parser = make_parser()
57 print "Reading " + self.xmlfile
58 wizardHandler = self.parseWizard(self.wizard)
59 parser.setContentHandler(wizardHandler)
60 parser.parse('/usr/share/enigma2/' + self.xmlfile)
62 self.numSteps = len(self.wizard)
65 self["text"] = Label()
67 self["config"] = ConfigList([])
69 self["step"] = Label()
71 self["stepslider"] = Slider(1, self.numSteps)
74 self["list"] = MenuList(self.list)
76 self.onShown.append(self.updateValues)
78 self["actions"] = NumberActionMap(["WizardActions", "NumberActions"],
86 "1": self.keyNumberGlobal,
87 "2": self.keyNumberGlobal,
88 "3": self.keyNumberGlobal,
89 "4": self.keyNumberGlobal,
90 "5": self.keyNumberGlobal,
91 "6": self.keyNumberGlobal,
92 "7": self.keyNumberGlobal,
93 "8": self.keyNumberGlobal,
94 "9": self.keyNumberGlobal,
95 "0": self.keyNumberGlobal
98 #self["actions"] = HelpableActionMap(self, "OkCancelActions",
100 #"ok": (self.ok, _("Close this Screen...")),
105 if self.currStep < 1:
111 if (self.wizard[self.currStep]["config"]["screen"] != None):
112 try: # don't die, if no run() is available
113 self.configInstance.run()
115 print "Failed to run configInstance"
117 if (len(self.wizard[self.currStep]["list"]) > 0):
118 nextStep = self.wizard[self.currStep]["list"][self["list"].l.getCurrentSelectionIndex()][1]
119 if nextStep == "end":
120 self.currStep = self.numSteps
121 elif nextStep == "next":
124 self.currStep = int(nextStep) - 1
126 if (self.currStep == self.numSteps): # wizard finished
127 config.misc.firstrun.value = 0;
128 config.misc.firstrun.save()
134 print "Now: " + str(self.currStep)
136 def keyNumberGlobal(self, number):
137 if (self.wizard[self.currStep]["config"]["screen"] != None):
138 self.configInstance.keyNumberGlobal(number)
141 if (self.wizard[self.currStep]["config"]["screen"] != None):
142 self.configInstance.keyLeft()
146 if (self.wizard[self.currStep]["config"]["screen"] != None):
147 self.configInstance.keyRight()
151 if (self.wizard[self.currStep]["config"]["screen"] != None):
152 self["config"].instance.moveSelection(self["config"].instance.moveUp)
153 elif (len(self.wizard[self.currStep]["list"]) > 0):
154 self["list"].instance.moveSelection(self["config"].instance.moveUp)
158 if (self.wizard[self.currStep]["config"]["screen"] != None):
159 self["config"].instance.moveSelection(self["config"].instance.moveDown)
160 elif (len(self.wizard[self.currStep]["list"]) > 0):
161 self["list"].instance.moveSelection(self["config"].instance.moveDown)
164 def updateValues(self):
165 print "Updating values in step " + str(self.currStep)
166 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
167 self["stepslider"].setValue(self.currStep)
169 self["text"].setText(_(self.wizard[self.currStep]["text"]))
171 if self.wizard[self.currStep]["code"] != "":
172 print self.wizard[self.currStep]["code"]
173 exec(self.wizard[self.currStep]["code"])
175 self["list"].instance.setZPosition(1)
177 if (len(self.wizard[self.currStep]["list"]) > 0):
178 self["list"].instance.setZPosition(2)
179 for x in self.wizard[self.currStep]["list"]:
180 self.list.append((_(x[0]), None))
181 self["list"].l.setList(self.list)
183 self["config"].instance.setZPosition(1)
184 if (self.wizard[self.currStep]["config"]["screen"] != None):
185 if self.wizard[self.currStep]["config"]["type"] == "standalone":
186 print "Type is standalone"
187 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
189 self["config"].instance.setZPosition(2)
190 print self.wizard[self.currStep]["config"]["screen"]
191 if self.wizard[self.currStep]["config"]["args"] == None:
192 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
194 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
195 self["config"].l.setList(self.configInstance["config"].list)
196 self.configInstance["config"] = self["config"]
198 self["config"].l.setList([])
204 def registerWizard(self, wizard):
205 self.wizards.append(wizard)
207 def getWizards(self):
208 if config.misc.firstrun.value:
213 wizardManager = WizardManager()