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 WelcomeWizard(Screen, HelpableScreen):
20 <screen position="0,0" size="720,560" title="Welcome..." flags="wfNoBorder" >
21 <widget name="text" position="50,100" size="440,200" font="Arial;23" />
22 <widget name="list" position="50,300" zPosition="1" size="440,200" />
23 <widget name="config" position="50,300" zPosition="1" size="440,200" transparent="1" />
24 <widget name="step" position="50,50" size="440,25" font="Arial;23" />
25 <widget name="stepslider" position="50,500" zPosition="1" size="440,20" backgroundColor="dark" />
26 <widget name="rc" pixmap="/usr/share/enigma2/rc.png" position="500,600" zPosition="10" size="154,475" transparent="1" alphatest="on"/>
27 <widget name="arrowdown" pixmap="/usr/share/enigma2/arrowdown.png" position="0,0" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
28 <widget name="arrowup" pixmap="/usr/share/enigma2/arrowup.png" position="-100,-100" zPosition="11" size="37,70" transparent="1" alphatest="on"/>
31 class parseWizard(ContentHandler):
32 def __init__(self, wizard):
33 self.isPointsElement, self.isReboundsElement = 0, 0
37 def startElement(self, name, attrs):
39 self.currContent = name
41 self.lastStep = int(attrs.get('number'))
42 self.wizard[self.lastStep] = {"text": "", "list": [], "config": {"screen": None, "args": None, "type": "" }, "code": ""}
43 elif (name == "text"):
44 self.wizard[self.lastStep]["text"] = str(attrs.get('value'))
45 elif (name == "listentry"):
46 self.wizard[self.lastStep]["list"].append((str(attrs.get('caption')), str(attrs.get('step'))))
47 elif (name == "config"):
48 exec "from Screens." + str(attrs.get('module')) + " import *"
49 self.wizard[self.lastStep]["config"]["screen"] = eval(str(attrs.get('screen')))
50 if (attrs.has_key('args')):
52 self.wizard[self.lastStep]["config"]["args"] = str(attrs.get('args'))
53 self.wizard[self.lastStep]["config"]["type"] = str(attrs.get('type'))
54 def endElement(self, name):
57 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
59 def characters(self, ch):
60 if self.currContent == "code":
61 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
63 def __init__(self, session):
64 self.skin = WelcomeWizard.skin
66 Screen.__init__(self, session)
67 HelpableScreen.__init__(self)
70 parser = make_parser()
71 print "Reading startwizard.xml"
72 wizardHandler = self.parseWizard(self.wizard)
73 parser.setContentHandler(wizardHandler)
74 parser.parse('/usr/share/enigma2/startwizard.xml')
76 self.numSteps = len(self.wizard)
79 self["text"] = Label()
80 self["rc"] = MovingPixmap()
81 self["arrowdown"] = MovingPixmap()
82 self["arrowup"] = MovingPixmap()
84 self["config"] = ConfigList([])
86 self["step"] = Label()
88 self["stepslider"] = Slider(1, self.numSteps)
91 self["list"] = MenuList(self.list)
93 self.onShown.append(self.updateValues)
95 self["actions"] = NumberActionMap(["WizardActions", "NumberActions"],
98 #"cancel": self.keyCancel,
103 "1": self.keyNumberGlobal,
104 "2": self.keyNumberGlobal,
105 "3": self.keyNumberGlobal,
106 "4": self.keyNumberGlobal,
107 "5": self.keyNumberGlobal,
108 "6": self.keyNumberGlobal,
109 "7": self.keyNumberGlobal,
110 "8": self.keyNumberGlobal,
111 "9": self.keyNumberGlobal,
112 "0": self.keyNumberGlobal
115 #self["actions"] = HelpableActionMap(self, "OkCancelActions",
117 #"ok": (self.ok, _("Close this Screen...")),
122 if (self.wizard[self.currStep]["config"]["screen"] != None):
123 try: # don't die, if no run() is available
124 self.configInstance.run()
126 print "Failed to run configInstance"
128 if (len(self.wizard[self.currStep]["list"]) > 0):
129 nextStep = self.wizard[self.currStep]["list"][self["list"].l.getCurrentSelectionIndex()][1]
130 if nextStep == "end":
131 self.currStep = self.numSteps
132 elif nextStep == "next":
135 self.currStep = int(nextStep) - 1
137 if (self.currStep == self.numSteps): # wizard finished
138 config.misc.firstrun.value = 0;
139 config.misc.firstrun.save()
145 print "Now: " + str(self.currStep)
147 def keyNumberGlobal(self, number):
148 if (self.wizard[self.currStep]["config"]["screen"] != None):
149 self.configInstance.keyNumberGlobal(number)
152 if (self.wizard[self.currStep]["config"]["screen"] != None):
153 self.configInstance.keyLeft()
157 if (self.wizard[self.currStep]["config"]["screen"] != None):
158 self.configInstance.keyRight()
162 if (self.wizard[self.currStep]["config"]["screen"] != None):
163 self["config"].instance.moveSelection(self["config"].instance.moveUp)
164 elif (len(self.wizard[self.currStep]["list"]) > 0):
165 self["list"].instance.moveSelection(self["config"].instance.moveUp)
169 if (self.wizard[self.currStep]["config"]["screen"] != None):
170 self["config"].instance.moveSelection(self["config"].instance.moveDown)
171 elif (len(self.wizard[self.currStep]["list"]) > 0):
172 self["list"].instance.moveSelection(self["config"].instance.moveDown)
175 def updateValues(self):
176 print "Updating values in step " + str(self.currStep)
177 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
178 self["stepslider"].setValue(self.currStep)
180 self["text"].setText(self.wizard[self.currStep]["text"])
182 if self.wizard[self.currStep]["code"] != "":
183 print self.wizard[self.currStep]["code"]
184 exec(self.wizard[self.currStep]["code"])
186 self["list"].instance.setZPosition(1)
188 if (len(self.wizard[self.currStep]["list"]) > 0):
189 self["list"].instance.setZPosition(2)
190 for x in self.wizard[self.currStep]["list"]:
191 self.list.append((x[0], None))
192 self["list"].l.setList(self.list)
194 self["config"].instance.setZPosition(1)
195 if (self.wizard[self.currStep]["config"]["screen"] != None):
196 if self.wizard[self.currStep]["config"]["type"] == "standalone":
197 print "Type is standalone"
198 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
200 self["config"].instance.setZPosition(2)
201 print self.wizard[self.currStep]["config"]["screen"]
202 if self.wizard[self.currStep]["config"]["args"] == None:
203 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
205 self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
206 self["config"].l.setList(self.configInstance["config"].list)
207 self.configInstance["config"] = self["config"]
209 self["config"].l.setList([])
213 def listActiveWizards():
216 if config.misc.firstrun.value:
217 wizards.append(WelcomeWizard)