use startwizard.xml for startwizard-generation
[enigma2.git] / lib / python / Screens / Wizard.py
1 from Screen import Screen
2
3 from Screens.HelpMenu import HelpableScreen
4 from Components.Label import Label
5 from Components.Slider import Slider
6 from Components.ActionMap import HelpableActionMap
7 from Components.config import config, configElementBoolean
8 from Components.Pixmap import *
9 from Components.MenuList import MenuList
10 from Components.ConfigList import ConfigList
11 from Screens.ScanSetup import ScanSimple
12
13 from xml.sax import make_parser
14 from xml.sax.handler import ContentHandler
15
16 config.misc.firstrun = configElementBoolean("config.misc.firstrun", 1);
17
18 class WelcomeWizard(Screen, HelpableScreen):
19
20         skin = """
21                 <screen position="0,0" size="720,560" title="Welcome..." flags="wfNoBorder" >
22                         <widget name="text" position="50,100" size="440,200" font="Arial;23" />
23                         <widget name="list" position="50,300" size="440,200" />
24                         <widget name="config" position="50,300" zPosition="100" size="440,200" />                       
25                         <widget name="step" position="50,50" size="440,25" font="Arial;23" />
26                         <widget name="stepslider" position="50,500" zPosition="1" size="440,20" backgroundColor="dark" />
27                         <widget name="rc" pixmap="/usr/share/enigma2/rc.png" position="500,600" size="154,475" transparent="1" alphatest="on"/>
28                         <widget name="arrowdown" pixmap="/usr/share/enigma2/arrowdown.png" position="0,0" zPosition="1" size="37,70" transparent="1" alphatest="on"/>
29                         <widget name="arrowup" pixmap="/usr/share/enigma2/arrowup.png" position="-100,-100" zPosition="1" size="37,70" transparent="1" alphatest="on"/>
30                 </screen>"""
31
32         class parseWizard(ContentHandler):
33                 def __init__(self, wizard):
34                         self.isPointsElement, self.isReboundsElement = 0, 0
35                         self.wizard = wizard
36                         self.currContent = ""
37                 
38                 def startElement(self, name, attrs):
39                         self.currContent = name
40                         if (name == "step"):
41                                 self.lastStep = int(attrs.get('number'))
42                                 self.wizard[self.lastStep] = {"text": "", "list": [], "config": None, "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')))
47                         elif (name == "config"):
48                                 exec "from Screens." + str(attrs.get('module')) + " import *"
49                                 self.wizard[self.lastStep]["config"] = eval(str(attrs.get('screen')))
50                                 
51                 def endElement(self, name):
52                         self.currContent = ""
53                         if name == 'code':
54                                 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
55                                 
56                 def characters(self, ch):
57                         if self.currContent == "code":
58                                  self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
59                                 
60         def __init__(self, session):
61                 self.skin = WelcomeWizard.skin
62
63                 Screen.__init__(self, session)
64                 HelpableScreen.__init__(self)
65
66                 self.wizard = {}
67                 print self.wizard
68                 parser = make_parser()
69                 print "Reading startwizard.xml"
70                 wizardHandler = self.parseWizard(self.wizard)
71                 parser.setContentHandler(wizardHandler)
72                 parser.parse('/usr/share/enigma2/startwizard.xml')
73                 
74                 print self.wizard
75                 
76                 self.numSteps = 4
77                 self.currStep = 1
78
79                 self["text"] = Label()
80                 self["rc"] = MovingPixmap()
81                 self["arrowdown"] = MovingPixmap()
82                 self["arrowdown"].moveTo(557, 232, 10)
83                 self["arrowup"] = MovingPixmap()
84                 self["rc"].moveTo(500, 50, 10)
85                 self["config"] = ConfigList([])
86                 
87                 self.onShown.append(self["arrowdown"].startMoving)
88                 self.onShown.append(self["rc"].startMoving)
89
90                 self["step"] = Label()
91                                 
92                 self["stepslider"] = Slider(1, self.numSteps)
93                 
94                 #self.scanSetupDialog = self.session.instantiateDialog(ScanSimple)
95                 
96                 self.list = []
97                 #list.append(("Use wizard to set up basic features", None))
98                 #list.append(("Exit wizard", None))
99                 self["list"] = MenuList(self.list)
100
101                 self.updateValues()
102                 
103                 self["actions"] = HelpableActionMap(self, "OkCancelActions",
104                         {
105                                 "ok": (self.ok, _("Close this Screen...")),
106                         })
107
108         def updateValues(self):
109                 self["step"].setText(_("Step ") + str(self.currStep) + "/" + str(self.numSteps))
110                 self["stepslider"].setValue(self.currStep)
111
112                 self["text"].setText(self.wizard[self.currStep]["text"])
113                 
114                 self.list = []
115                 if (len(self.wizard[self.currStep]["list"]) > 0):
116                         for x in self.wizard[self.currStep]["list"]:
117                                 self.list.append((x, None))
118                 self["list"].l.setList(self.list)
119                 
120                 if (self.wizard[self.currStep]["config"] != None):
121                         self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"])
122                         self["config"].l.setList(self.configInstance["config"].list)
123                 else:
124                         self["config"].l.setList([])
125
126                 if self.wizard[self.currStep]["code"] != "":
127                         print self.wizard[self.currStep]["code"]
128                         exec(self.wizard[self.currStep]["code"])
129                         
130         def ok(self):
131                 if (self.currStep == self.numSteps): # wizard finished
132                         config.misc.firstrun.value = 0;
133                         config.misc.firstrun.save()
134                         self.session.close()
135                 else:
136                         self.currStep += 1
137                         self.updateValues()
138
139 def listActiveWizards():
140         wizards = [ ]
141
142         if config.misc.firstrun.value:
143                 wizards.append(WelcomeWizard)
144         
145         return wizards