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"],
81 #"cancel": self.keyCancel,
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.wizard[self.currStep]["config"]["screen"] != None):
106 try: # don't die, if no run() is available
107 self.configInstance.run()
109 print "Failed to run configInstance"
111 if (len(self.wizard[self.currStep]["list"]) > 0):
112 nextStep = self.wizard[self.currStep]["list"][self["list"].l.getCurrentSelectionIndex()][1]
113 if nextStep == "end":
114 self.currStep = self.numSteps
115 elif nextStep == "next":
118 self.currStep = int(nextStep) - 1
120 if (self.currStep == self.numSteps): # wizard finished
121 config.misc.firstrun.value = 0;
122 config.misc.firstrun.save()
128 print "Now: " + str(self.currStep)
130 def keyNumberGlobal(self, number):
131 if (self.wizard[self.currStep]["config"]["screen"] != None):
132 self.configInstance.keyNumberGlobal(number)
135 if (self.wizard[self.currStep]["config"]["screen"] != None):
136 self.configInstance.keyLeft()
140 if (self.wizard[self.currStep]["config"]["screen"] != None):
141 self.configInstance.keyRight()
145 if (self.wizard[self.currStep]["config"]["screen"] != None):
146 self["config"].instance.moveSelection(self["config"].instance.moveUp)
147 elif (len(self.wizard[self.currStep]["list"]) > 0):
148 self["list"].instance.moveSelection(self["config"].instance.moveUp)
152 if (self.wizard[self.currStep]["config"]["screen"] != None):
153 self["config"].instance.moveSelection(self["config"].instance.moveDown)
154 elif (len(self.wizard[self.currStep]["list"]) > 0):
155 self["list"].instance.moveSelection(self["config"].instance.moveDown)
158 def updateValues(self):
159 print "Updating values in step " + str(self.currStep)
160 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
161 self["stepslider"].setValue(self.currStep)
163 self["text"].setText(_(self.wizard[self.currStep]["text"]))
165 if self.wizard[self.currStep]["code"] != "":
166 print self.wizard[self.currStep]["code"]
167 exec(self.wizard[self.currStep]["code"])
169 self["list"].instance.setZPosition(1)
171 if (len(self.wizard[self.currStep]["list"]) > 0):
172 self["list"].instance.setZPosition(2)
173 for x in self.wizard[self.currStep]["list"]:
174 self.list.append((x[0], None))
175 self["list"].l.setList(self.list)
177 self["config"].instance.setZPosition(1)
178 if (self.wizard[self.currStep]["config"]["screen"] != None):
179 if self.wizard[self.currStep]["config"]["type"] == "standalone":
180 print "Type is standalone"
181 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
183 self["config"].instance.setZPosition(2)
184 print self.wizard[self.currStep]["config"]["screen"]
185 if self.wizard[self.currStep]["config"]["args"] == None:
186 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
188 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
189 self["config"].l.setList(self.configInstance["config"].list)
190 self.configInstance["config"] = self["config"]
192 self["config"].l.setList([])
198 def registerWizard(self, wizard):
199 self.wizards.append(wizard)
201 def getWizards(self):
202 if config.misc.firstrun.value:
207 wizardManager = WizardManager()