Merge commit 'dm/experimental' into vuplus_experimental
[vuplus_dvbapp] / lib / python / Screens / Wizard.py
1 from Screen import Screen
2 from Screens.HelpMenu import HelpableScreen
3 from Screens.MessageBox import MessageBox
4 from Components.config import config, ConfigText, ConfigPassword, KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT, KEY_NUMBERS
5
6 from Components.Label import Label
7 from Components.Sources.StaticText import StaticText
8 from Components.Slider import Slider
9 from Components.ActionMap import NumberActionMap
10 from Components.MenuList import MenuList
11 from Components.ConfigList import ConfigList
12 from Components.Sources.List import List
13 from enigma import eTimer
14
15 from xml.sax import make_parser
16 from xml.sax.handler import ContentHandler
17
18 #       ikseong
19 from Plugins.SystemPlugins.FactoryTest.plugin import FactoryTest
20
21 class WizardSummary(Screen):
22         skin = """
23         <screen position="0,0" size="132,64">
24                 <widget source="text" render="Label" position="6,0" size="120,16" font="Regular;16" transparent="1" />
25                 <widget source="parent.list" render="Label" position="6,18" size="120,46" font="Regular;12">
26                         <convert type="StringListSelection" />
27                 </widget>
28         </screen>"""
29         
30         def __init__(self, session, parent):
31                 Screen.__init__(self, session, parent)
32                 
33                 #names = parent.skinName
34                 #if not isinstance(names, list):
35                         #names = [names]
36 #                       
37                 #self.skinName = [x + "_summary" for x in names ]
38                 #self.skinName.append("Wizard")
39                 #print "*************+++++++++++++++++****************++++++++++******************* WizardSummary", self.skinName
40                         #
41                 self["text"] = StaticText("")
42                 self.onShow.append(self.setCallback)
43                 
44         def setCallback(self):
45                 self.parent.setLCDTextCallback(self.setText)
46                 
47         def setText(self, text):
48                 self["text"].setText(text)
49
50 class Wizard(Screen):
51         def createSummary(self):
52                         print "WizardCreateSummary"
53                         return WizardSummary
54
55         class parseWizard(ContentHandler):
56                 def __init__(self, wizard):
57                         self.isPointsElement, self.isReboundsElement = 0, 0
58                         self.wizard = wizard
59                         self.currContent = ""
60                         self.lastStep = 0       
61
62                 def startElement(self, name, attrs):
63                         #print "startElement", name
64                         self.currContent = name
65                         if (name == "step"):
66                                 self.lastStep += 1
67                                 if attrs.has_key('id'):
68                                         id = str(attrs.get('id'))
69                                 else:
70                                         id = ""
71                                 #print "id:", id
72                                 if attrs.has_key('nextstep'):
73                                         nextstep = str(attrs.get('nextstep'))
74                                 else:
75                                         nextstep = None
76                                 if attrs.has_key('timeout'):
77                                         timeout = int(attrs.get('timeout'))
78                                 else:
79                                         timeout = None
80                                 if attrs.has_key('timeoutaction'):
81                                         timeoutaction = str(attrs.get('timeoutaction'))
82                                 else:
83                                         timeoutaction = 'nextpage'
84
85                                 if attrs.has_key('timeoutstep'):
86                                         timeoutstep = str(attrs.get('timeoutstep'))
87                                 else:
88                                         timeoutstep = ''
89                                 self.wizard[self.lastStep] = {"id": id, "condition": "", "text": "", "timeout": timeout, "timeoutaction": timeoutaction, "timeoutstep": timeoutstep, "list": [], "config": {"screen": None, "args": None, "type": "" }, "code": "", "codeafter": "", "code_async": "", "codeafter_async": "", "nextstep": nextstep}
90                                 if attrs.has_key('laststep'):
91                                         self.wizard[self.lastStep]["laststep"] = str(attrs.get('laststep'))
92                         elif (name == "text"):
93                                 self.wizard[self.lastStep]["text"] = str(attrs.get('value')).replace("\\n", "\n")
94                         elif (name == "displaytext"):
95                                 self.wizard[self.lastStep]["displaytext"] = str(attrs.get('value')).replace("\\n", "\n")
96                         elif (name == "list"):
97                                 if (attrs.has_key('type')):
98                                         if attrs["type"] == "dynamic":
99                                                 self.wizard[self.lastStep]["dynamiclist"] = attrs.get("source")
100                                         #self.wizard[self.lastStep]["list"].append(("Hallo", "test"))
101                                 if (attrs.has_key("evaluation")):
102                                         #print "evaluation"
103                                         self.wizard[self.lastStep]["listevaluation"] = attrs.get("evaluation")
104                                 if (attrs.has_key("onselect")):
105                                         self.wizard[self.lastStep]["onselect"] = attrs.get("onselect")                  
106                         elif (name == "listentry"):
107                                 self.wizard[self.lastStep]["list"].append((str(attrs.get('caption')), str(attrs.get('step'))))
108                         elif (name == "config"):
109                                 type = str(attrs.get('type'))
110                                 self.wizard[self.lastStep]["config"]["type"] = type
111                                 if type == "ConfigList" or type == "standalone":
112                                         try:
113                                                 exec "from Screens." + str(attrs.get('module')) + " import *"
114                                         except:
115                                                 exec "from " + str(attrs.get('module')) + " import *"
116                                 
117                                         self.wizard[self.lastStep]["config"]["screen"] = eval(str(attrs.get('screen')))
118                                         if (attrs.has_key('args')):
119                                                 #print "has args"
120                                                 self.wizard[self.lastStep]["config"]["args"] = str(attrs.get('args'))
121                                 elif type == "dynamic":
122                                         self.wizard[self.lastStep]["config"]["source"] = str(attrs.get('source'))
123                                         if (attrs.has_key('evaluation')):
124                                                 self.wizard[self.lastStep]["config"]["evaluation"] = str(attrs.get('evaluation'))
125                         elif (name == "code"):
126                                 self.async_code = attrs.has_key('async') and str(attrs.get('async')) == "yes"
127                                 if attrs.has_key('pos') and str(attrs.get('pos')) == "after":
128                                         self.codeafter = True
129                                 else:
130                                         self.codeafter = False
131                         elif (name == "condition"):
132                                 pass
133                         
134                 def endElement(self, name):
135                         self.currContent = ""
136                         if name == 'code':
137                                 if self.async_code:
138                                         if self.codeafter:
139                                                 self.wizard[self.lastStep]["codeafter_async"] = self.wizard[self.lastStep]["codeafter_async"].strip()
140                                         else:
141                                                 self.wizard[self.lastStep]["code_async"] = self.wizard[self.lastStep]["code_async"].strip()
142                                 else:
143                                         if self.codeafter:
144                                                 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"].strip()
145                                         else:
146                                                 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"].strip()
147                         elif name == 'condition':
148                                 self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"].strip()
149                         elif name == 'step':
150                                 #print "Step number", self.lastStep, ":", self.wizard[self.lastStep]
151                                 pass
152                                                                 
153                 def characters(self, ch):
154                         if self.currContent == "code":
155                                 if self.async_code:
156                                         if self.codeafter:
157                                                 self.wizard[self.lastStep]["codeafter_async"] = self.wizard[self.lastStep]["codeafter_async"] + ch
158                                         else:
159                                                 self.wizard[self.lastStep]["code_async"] = self.wizard[self.lastStep]["code_async"] + ch
160                                 else:
161                                         if self.codeafter:
162                                                 self.wizard[self.lastStep]["codeafter"] = self.wizard[self.lastStep]["codeafter"] + ch
163                                         else:
164                                                 self.wizard[self.lastStep]["code"] = self.wizard[self.lastStep]["code"] + ch
165                         elif self.currContent == "condition":
166                                  self.wizard[self.lastStep]["condition"] = self.wizard[self.lastStep]["condition"] + ch
167         
168         def __init__(self, session, showSteps = True, showStepSlider = True, showList = True, showConfig = True):
169                 Screen.__init__(self, session)
170                 
171                 self.isLastWizard = False # can be used to skip a "goodbye"-screen in a wizard
172
173                 self.stepHistory = []
174
175                 self.wizard = {}
176                 parser = make_parser()
177                 if not isinstance(self.xmlfile, list):
178                         self.xmlfile = [self.xmlfile]
179                 print "Reading ", self.xmlfile
180                 wizardHandler = self.parseWizard(self.wizard)
181                 parser.setContentHandler(wizardHandler)
182                 for xmlfile in self.xmlfile:
183                         if xmlfile[0] != '/':
184                                 parser.parse('/usr/share/enigma2/' + xmlfile)
185                         else:
186                                 parser.parse(xmlfile)
187
188                 self.showSteps = showSteps
189                 self.showStepSlider = showStepSlider
190                 self.showList = showList
191                 self.showConfig = showConfig
192
193                 self.numSteps = len(self.wizard)
194                 self.currStep = self.getStepWithID("start") + 1
195                 
196                 self.timeoutTimer = eTimer()
197                 self.timeoutTimer.callback.append(self.timeoutCounterFired)
198
199                 #       ikseong - for memory test
200                 self.memorytestmode = 0
201                 self.testkey = 0
202
203                 self["text"] = Label()
204
205                 if showConfig:
206                         self["config"] = ConfigList([], session = session)
207
208                 if self.showSteps:
209                         self["step"] = Label()
210                 
211                 if self.showStepSlider:
212                         self["stepslider"] = Slider(1, self.numSteps)
213                 
214                 if self.showList:
215                         self.list = []
216                         self["list"] = List(self.list, enableWrapAround = True)
217                         self["list"].onSelectionChanged.append(self.selChanged)
218                         #self["list"] = MenuList(self.list, enableWrapAround = True)
219
220                 self.onShown.append(self.updateValues)
221
222                 self.configInstance = None
223                 self.currentConfigIndex = None
224                 
225                 self.lcdCallbacks = []
226                 
227                 self.disableKeys = False
228                 
229                 self["actions"] = NumberActionMap(["WizardActions", "NumberActions", "ColorActions", "SetupActions", "InputAsciiActions", "KeyboardInputActions"],
230                 {
231                         "gotAsciiCode": self.keyGotAscii,
232                         "ok": self.ok,
233                         "back": self.back,
234                         "left": self.left,
235                         "right": self.right,
236                         "up": self.up,
237                         "down": self.down,
238                         "red": self.red,
239                         "green": self.green,
240                         "yellow": self.yellow,
241                         "blue":self.blue,
242                         "deleteBackward": self.deleteBackward,
243                         "deleteForward": self.deleteForward,
244                         "1": self.keyNumberGlobal,
245                         "2": self.keyNumberGlobal,
246                         "3": self.keyNumberGlobal,
247                         "4": self.keyNumberGlobal,
248                         "5": self.keyNumberGlobal,
249                         "6": self.keyNumberGlobal,
250                         "7": self.keyNumberGlobal,
251                         "8": self.keyNumberGlobal,
252                         "9": self.keyNumberGlobal,
253                         "0": self.keyNumberGlobal,
254 #       ikseong
255                         "test":self.testmode
256                 }, -1)
257
258                 self["VirtualKB"] = NumberActionMap(["VirtualKeyboardActions"],
259                 {
260                         "showVirtualKeyboard": self.KeyText,
261                 }, -2)
262                 
263                 self["VirtualKB"].setEnabled(False)
264                 
265         def red(self):
266                 print "red"
267                 pass
268
269         def green(self):
270                 print "green"
271                 pass
272         
273         def yellow(self):
274                 print "yellow"
275                 pass
276         
277         def blue(self):
278                 print "blue"
279                 pass
280         
281         def deleteForward(self):
282                 self.resetCounter()
283                 if (self.wizard[self.currStep]["config"]["screen"] != None):
284                         self.configInstance.keyDelete()
285                 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
286                         self["config"].handleKey(KEY_DELETE)
287                 print "deleteForward"
288
289         def deleteBackward(self):
290                 self.resetCounter()
291                 if (self.wizard[self.currStep]["config"]["screen"] != None):
292                         self.configInstance.keyBackspace()
293                 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
294                         self["config"].handleKey(KEY_BACKSPACE)
295                 print "deleteBackward"
296         
297         def setLCDTextCallback(self, callback):
298                 self.lcdCallbacks.append(callback)
299
300         def back(self):
301                 if self.disableKeys:
302                         return
303                 print "getting back..."
304                 print "stepHistory:", self.stepHistory
305                 if len(self.stepHistory) > 1:
306                         self.currStep = self.stepHistory[-2]
307                         self.stepHistory = self.stepHistory[:-2]
308                 else:
309                         self.session.openWithCallback(self.exitWizardQuestion, MessageBox, (_("Are you sure you want to exit this wizard?") ) )
310                 if self.currStep < 1:
311                         self.currStep = 1
312                 print "currStep:", self.currStep
313                 print "new stepHistory:", self.stepHistory
314                 self.updateValues()
315                 print "after updateValues stepHistory:", self.stepHistory
316                 
317         def exitWizardQuestion(self, ret = False):
318                 if (ret):
319                         self.markDone()
320                         self.close()
321                 
322         def markDone(self):
323                 pass
324         
325         def getStepWithID(self, id):
326                 print "getStepWithID:", id
327                 count = 0
328                 for x in self.wizard.keys():
329                         if self.wizard[x]["id"] == id:
330                                 print "result:", count
331                                 return count
332                         count += 1
333                 print "result: nothing"
334                 return 0
335
336         def finished(self, gotoStep = None, *args, **kwargs):
337                 print "finished"
338                 currStep = self.currStep
339
340                 if self.updateValues not in self.onShown:
341                         self.onShown.append(self.updateValues)
342                         
343                 if self.showConfig:
344                         if self.wizard[currStep]["config"]["type"] == "dynamic":
345                                 eval("self." + self.wizard[currStep]["config"]["evaluation"])()
346
347                 if self.showList:
348                         if (len(self.wizard[currStep]["evaluatedlist"]) > 0):
349                                 print "current:", self["list"].current
350                                 nextStep = self["list"].current[1]
351                                 if (self.wizard[currStep].has_key("listevaluation")):
352                                         exec("self." + self.wizard[self.currStep]["listevaluation"] + "('" + nextStep + "')")
353                                 else:
354                                         self.currStep = self.getStepWithID(nextStep)
355
356                 print_now = True
357                 if ((currStep == self.numSteps and self.wizard[currStep]["nextstep"] is None) or self.wizard[currStep]["id"] == "end"): # wizard finished
358                         print "wizard finished"
359                         self.markDone()
360                         self.close()
361                 else:
362                         self.codeafter = True
363                         self.runCode(self.wizard[currStep]["codeafter"])
364                         self.prevStep = currStep
365                         self.gotoStep = gotoStep
366                         if not self.runCode(self.wizard[currStep]["codeafter_async"]):
367                                 self.afterAsyncCode()
368                         else:
369                                 if self.updateValues in self.onShown:
370                                         self.onShown.remove(self.updateValues)
371
372                 if print_now:
373                         print "Now: " + str(self.currStep)
374
375         def ok(self):
376                 print "OK"
377                 if self.disableKeys:
378                         return
379                 currStep = self.currStep
380                 
381                 if self.showConfig:
382                         if (self.wizard[currStep]["config"]["screen"] != None):
383                                 # TODO: don't die, if no run() is available
384                                 # there was a try/except here, but i can't see a reason
385                                 # for this. If there is one, please do a more specific check
386                                 # and/or a comment in which situation there is no run()
387                                 if callable(getattr(self.configInstance, "runAsync", None)):
388                                         if self.updateValues in self.onShown:
389                                                 self.onShown.remove(self.updateValues)
390                                         self.configInstance.runAsync(self.finished)
391                                         return
392                                 else:
393                                         self.configInstance.run()
394                 self.finished()
395
396 #       ikseong
397         def testmode(self):
398                 print "testmode ",self.memorytestmode
399                 if self.memorytestmode == 0:
400                         self.memorytestmode = 1
401                 else:
402                         self.memorytestmode = 0
403
404         def keyNumberGlobal(self, number):
405                 if self.memorytestmode == 1:
406                         self.testkey = self.testkey * 10 + number
407                         if self.testkey > 10000:
408                                 self.testkey = self.testkey%10000
409                         if self.testkey == 4599:
410                                 self.session.open(FactoryTest)
411                         print "testkey", self.testkey
412                         return
413                 if (self.wizard[self.currStep]["config"]["screen"] != None):
414                         self.configInstance.keyNumberGlobal(number)
415
416         def keyGotAscii(self):
417                 if (self.wizard[self.currStep]["config"]["screen"] != None):
418                         self["config"].handleKey(KEY_ASCII)
419                 
420         def left(self):
421                 self.resetCounter()
422                 if (self.wizard[self.currStep]["config"]["screen"] != None):
423                         self.configInstance.keyLeft()
424                 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
425                         self["config"].handleKey(KEY_LEFT)
426                 print "left"
427         
428         def right(self):
429                 self.resetCounter()
430                 if (self.wizard[self.currStep]["config"]["screen"] != None):
431                         self.configInstance.keyRight()
432                 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
433                         self["config"].handleKey(KEY_RIGHT)     
434                 print "right"
435
436         def up(self):
437                 self.resetCounter()
438                 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None  or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
439                         self["config"].instance.moveSelection(self["config"].instance.moveUp)
440                         self.handleInputHelpers()
441                 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
442                         self["list"].selectPrevious()
443                         if self.wizard[self.currStep].has_key("onselect"):
444                                 print "current:", self["list"].current
445                                 self.selection = self["list"].current[-1]
446                                 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
447                                 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
448                 print "up"
449                 
450         def down(self):
451                 self.resetCounter()
452                 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None  or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
453                         self["config"].instance.moveSelection(self["config"].instance.moveDown)
454                         self.handleInputHelpers()
455                 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
456                         #self["list"].instance.moveSelection(self["list"].instance.moveDown)
457                         self["list"].selectNext()
458                         if self.wizard[self.currStep].has_key("onselect"):
459                                 print "current:", self["list"].current
460                                 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
461                                 #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
462                                 self.selection = self["list"].current[-1]
463                                 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
464                                 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
465                 print "down"
466                 
467         def selChanged(self):
468                 self.resetCounter()
469                 
470                 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
471                         self["config"].instance.moveSelection(self["config"].instance.moveUp)
472                 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
473                         if self.wizard[self.currStep].has_key("onselect"):
474                                 self.selection = self["list"].current[-1]
475                                 print "self.selection:", self.selection
476                                 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
477                 
478         def resetCounter(self):
479                 self.timeoutCounter = self.wizard[self.currStep]["timeout"]
480                 
481         def runCode(self, code):
482                 if code != "":
483                         print "code", code
484                         exec(code)
485                         return True
486                 return False
487
488         def getTranslation(self, text):
489                 return _(text)
490                         
491         def updateText(self, firstset = False):
492                 text = self.getTranslation(self.wizard[self.currStep]["text"])
493                 if text.find("[timeout]") != -1:
494                         text = text.replace("[timeout]", str(self.timeoutCounter))
495                         self["text"].setText(text)
496                 else:
497                         if firstset:
498                                 self["text"].setText(text)
499                 
500         def updateValues(self):
501                 print "Updating values in step " + str(self.currStep)
502                 # calling a step which doesn't exist can only happen if the condition in the last step is not fulfilled
503                 # if a non-existing step is called, end the wizard 
504                 if self.currStep > len(self.wizard):
505                         self.markDone()
506                         self.close()
507                         return
508
509                 self.timeoutTimer.stop()
510                 
511                 if self.configInstance is not None:
512                         # remove callbacks
513                         self.configInstance["config"].onSelectionChanged = []
514                         del self.configInstance["config"]
515                         self.configInstance.doClose()
516                         self.configInstance = None
517
518                 self.condition = True
519                 exec (self.wizard[self.currStep]["condition"])
520                 if not self.condition:
521                         print "keys*******************:", self.wizard[self.currStep].keys()
522                         if self.wizard[self.currStep].has_key("laststep"): # exit wizard, if condition of laststep doesn't hold
523                                 self.markDone()
524                                 self.close()
525                                 return
526                         else:
527                                 self.currStep += 1
528                                 self.updateValues()
529                 else:
530                         if self.wizard[self.currStep].has_key("displaytext"):
531                                 displaytext = self.wizard[self.currStep]["displaytext"]
532                                 print "set LCD text"
533                                 for x in self.lcdCallbacks:
534                                         x(displaytext)
535                         if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
536                                 self.stepHistory.append(self.currStep)
537                         print "wizard step:", self.wizard[self.currStep]
538                         
539                         if self.showSteps:
540                                 self["step"].setText(self.getTranslation("Step ") + str(self.currStep) + "/" + str(self.numSteps))
541                         if self.showStepSlider:
542                                 self["stepslider"].setValue(self.currStep)
543                 
544                         if self.wizard[self.currStep]["timeout"] is not None:
545                                 self.resetCounter() 
546                                 self.timeoutTimer.start(1000)
547                         
548                         print "wizard text", self.getTranslation(self.wizard[self.currStep]["text"])
549                         self.updateText(firstset = True)
550                         if self.wizard[self.currStep].has_key("displaytext"):
551                                 displaytext = self.wizard[self.currStep]["displaytext"]
552                                 print "set LCD text"
553                                 for x in self.lcdCallbacks:
554                                         x(displaytext)
555                                 
556                         self.codeafter=False
557                         self.runCode(self.wizard[self.currStep]["code"])
558                         if self.runCode(self.wizard[self.currStep]["code_async"]):
559                                 if self.updateValues in self.onShown:
560                                         self.onShown.remove(self.updateValues)
561                         else:
562                                 self.afterAsyncCode()
563
564         def afterAsyncCode(self):
565                 if not self.updateValues in self.onShown:
566                         self.onShown.append(self.updateValues)
567
568                 if self.codeafter:
569                         if self.wizard[self.prevStep]["nextstep"] is not None:
570                                 self.currStep = self.getStepWithID(self.wizard[self.prevStep]["nextstep"])
571                         if self.gotoStep is not None:
572                                 self.currStep = self.getStepWithID(self.gotoStep)
573                         self.currStep += 1
574                         self.updateValues()
575                         print "Now: " + str(self.currStep)
576                 else:
577                         if self.showList:
578                                 print "showing list,", self.currStep
579                                 for renderer in self.renderer:
580                                         rootrenderer = renderer
581                                         while renderer.source is not None:
582                                                 print "self.list:", self["list"]
583                                                 if renderer.source is self["list"]:
584                                                         print "setZPosition"
585                                                         rootrenderer.instance.setZPosition(1)
586                                                 renderer = renderer.source
587
588                                 #self["list"].instance.setZPosition(1)
589                                 self.list = []
590                                 if (self.wizard[self.currStep].has_key("dynamiclist")):
591                                         print "dynamic list, calling",  self.wizard[self.currStep]["dynamiclist"]
592                                         newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
593                                         #self.wizard[self.currStep]["evaluatedlist"] = []
594                                         for entry in newlist:
595                                                 #self.wizard[self.currStep]["evaluatedlist"].append(entry)
596                                                 self.list.append(entry)
597                                         #del self.wizard[self.currStep]["dynamiclist"]
598                                 if (len(self.wizard[self.currStep]["list"]) > 0):
599                                         #self["list"].instance.setZPosition(2)
600                                         for x in self.wizard[self.currStep]["list"]:
601                                                 self.list.append((self.getTranslation(x[0]), x[1]))
602                                 self.wizard[self.currStep]["evaluatedlist"] = self.list
603                                 self["list"].list = self.list
604                                 self["list"].index = 0
605                         else:
606                                 self["list"].hide()
607         
608                         if self.showConfig:
609                                 print "showing config"
610                                 self["config"].instance.setZPosition(1)
611                                 if self.wizard[self.currStep]["config"]["type"] == "dynamic":
612                                                 print "config type is dynamic"
613                                                 self["config"].instance.setZPosition(2)
614                                                 self["config"].l.setList(eval("self." + self.wizard[self.currStep]["config"]["source"])())
615                                 elif (self.wizard[self.currStep]["config"]["screen"] != None):
616                                         if self.wizard[self.currStep]["config"]["type"] == "standalone":
617                                                 print "Type is standalone"
618                                                 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
619                                         else:
620                                                 self["config"].instance.setZPosition(2)
621                                                 print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
622                                                 if self.wizard[self.currStep]["config"]["args"] == None:
623                                                         self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
624                                                 else:
625                                                         self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
626                                                 self["config"].l.setList(self.configInstance["config"].list)
627                                                 callbacks = self.configInstance["config"].onSelectionChanged
628                                                 self.configInstance["config"].destroy()
629                                                 print "clearConfigList", self.configInstance["config"], self["config"]
630                                                 self.configInstance["config"] = self["config"]
631                                                 self.configInstance["config"].onSelectionChanged = callbacks
632                                                 print "clearConfigList", self.configInstance["config"], self["config"]
633                                 else:
634                                         self["config"].l.setList([])
635                                         self.handleInputHelpers()
636                                         
637                                         
638                         else:
639                                 if self.has_key("config"):
640                                         self["config"].hide()
641
642         def timeoutCounterFired(self):
643                 self.timeoutCounter -= 1
644                 print "timeoutCounter:", self.timeoutCounter
645                 if self.timeoutCounter == 0:
646                         if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
647                                 print "selection next item"
648                                 self.down()
649                         else:
650                                 if self.wizard[self.currStep]["timeoutaction"] == "changestep":
651                                         self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
652                 self.updateText()
653
654         def handleInputHelpers(self):
655                 if self["config"].getCurrent() is not None:
656                         if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
657                                 if self.has_key("VKeyIcon"):
658                                         self["VirtualKB"].setEnabled(True)
659                                         self["VKeyIcon"].boolean = True
660                                 if self.has_key("HelpWindow"):
661                                         if self["config"].getCurrent()[1].help_window.instance is not None:
662                                                 helpwindowpos = self["HelpWindow"].getPosition()
663                                                 from enigma import ePoint
664                                                 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
665                         else:
666                                 if self.has_key("VKeyIcon"):
667                                         self["VirtualKB"].setEnabled(False)
668                                         self["VKeyIcon"].boolean = False
669                 else:
670                         if self.has_key("VKeyIcon"):
671                                 self["VirtualKB"].setEnabled(False)
672                                 self["VKeyIcon"].boolean = False
673
674         def KeyText(self):
675                 from Screens.VirtualKeyBoard import VirtualKeyBoard
676                 self.currentConfigIndex = self["config"].getCurrentIndex()
677                 self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].getValue())
678
679         def VirtualKeyBoardCallback(self, callback = None):
680                 if callback is not None and len(callback):
681                         if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
682                                 if self.has_key("HelpWindow"):
683                                         if self["config"].getCurrent()[1].help_window.instance is not None:
684                                                 helpwindowpos = self["HelpWindow"].getPosition()
685                                                 from enigma import ePoint
686                                                 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
687                         self["config"].instance.moveSelectionTo(self.currentConfigIndex)
688                         self["config"].setCurrentIndex(self.currentConfigIndex)
689                         self["config"].getCurrent()[1].setValue(callback)
690                         self["config"].invalidate(self["config"].getCurrent())
691
692
693 class WizardManager:
694         def __init__(self):
695                 self.wizards = []
696         
697         def registerWizard(self, wizard, precondition, priority = 0):
698                 self.wizards.append((wizard, precondition, priority))
699         
700         def getWizards(self):
701                 # x[1] is precondition
702                 for wizard in self.wizards:
703                         wizard[0].isLastWizard = False
704                 if len(self.wizards) > 0:
705                         self.wizards[-1][0].isLastWizard = True
706                 return [(x[2], x[0]) for x in self.wizards if x[1] == 1]
707
708 wizardManager = WizardManager()