Merge commit 'dm/experimental' into test
[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                 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
416                         self["config"].handleKey(KEY_0 + number)
417
418         def keyGotAscii(self):
419                 if (self.wizard[self.currStep]["config"]["screen"] != None):
420                         self["config"].handleKey(KEY_ASCII)
421                 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
422                         self["config"].handleKey(KEY_ASCII)
423                 
424         def left(self):
425                 self.resetCounter()
426                 if (self.wizard[self.currStep]["config"]["screen"] != None):
427                         self.configInstance.keyLeft()
428                 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
429                         self["config"].handleKey(KEY_LEFT)
430                 print "left"
431         
432         def right(self):
433                 self.resetCounter()
434                 if (self.wizard[self.currStep]["config"]["screen"] != None):
435                         self.configInstance.keyRight()
436                 elif (self.wizard[self.currStep]["config"]["type"] == "dynamic"):
437                         self["config"].handleKey(KEY_RIGHT)     
438                 print "right"
439
440         def up(self):
441                 self.resetCounter()
442                 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None  or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
443                         self["config"].instance.moveSelection(self["config"].instance.moveUp)
444                         self.handleInputHelpers()
445                 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
446                         self["list"].selectPrevious()
447                         if self.wizard[self.currStep].has_key("onselect"):
448                                 print "current:", self["list"].current
449                                 self.selection = self["list"].current[-1]
450                                 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
451                                 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
452                 print "up"
453                 
454         def down(self):
455                 self.resetCounter()
456                 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None  or self.wizard[self.currStep]["config"]["type"] == "dynamic"):
457                         self["config"].instance.moveSelection(self["config"].instance.moveDown)
458                         self.handleInputHelpers()
459                 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
460                         #self["list"].instance.moveSelection(self["list"].instance.moveDown)
461                         self["list"].selectNext()
462                         if self.wizard[self.currStep].has_key("onselect"):
463                                 print "current:", self["list"].current
464                                 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
465                                 #exec("self." + self.wizard[self.currStep]["onselect"] + "()")
466                                 self.selection = self["list"].current[-1]
467                                 #self.selection = self.wizard[self.currStep]["evaluatedlist"][self["list"].l.getCurrentSelectionIndex()][1]
468                                 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
469                 print "down"
470                 
471         def selChanged(self):
472                 self.resetCounter()
473                 
474                 if (self.showConfig and self.wizard[self.currStep]["config"]["screen"] != None):
475                         self["config"].instance.moveSelection(self["config"].instance.moveUp)
476                 elif (self.showList and len(self.wizard[self.currStep]["evaluatedlist"]) > 0):
477                         if self.wizard[self.currStep].has_key("onselect"):
478                                 self.selection = self["list"].current[-1]
479                                 print "self.selection:", self.selection
480                                 exec("self." + self.wizard[self.currStep]["onselect"] + "()")
481                 
482         def resetCounter(self):
483                 self.timeoutCounter = self.wizard[self.currStep]["timeout"]
484                 
485         def runCode(self, code):
486                 if code != "":
487                         print "code", code
488                         exec(code)
489                         return True
490                 return False
491
492         def getTranslation(self, text):
493                 return _(text)
494                         
495         def updateText(self, firstset = False):
496                 text = self.getTranslation(self.wizard[self.currStep]["text"])
497                 if text.find("[timeout]") != -1:
498                         text = text.replace("[timeout]", str(self.timeoutCounter))
499                         self["text"].setText(text)
500                 else:
501                         if firstset:
502                                 self["text"].setText(text)
503                 
504         def updateValues(self):
505                 print "Updating values in step " + str(self.currStep)
506                 # calling a step which doesn't exist can only happen if the condition in the last step is not fulfilled
507                 # if a non-existing step is called, end the wizard 
508                 if self.currStep > len(self.wizard):
509                         self.markDone()
510                         self.close()
511                         return
512
513                 self.timeoutTimer.stop()
514                 
515                 if self.configInstance is not None:
516                         # remove callbacks
517                         self.configInstance["config"].onSelectionChanged = []
518                         del self.configInstance["config"]
519                         self.configInstance.doClose()
520                         self.configInstance = None
521
522                 self.condition = True
523                 exec (self.wizard[self.currStep]["condition"])
524                 if not self.condition:
525                         print "keys*******************:", self.wizard[self.currStep].keys()
526                         if self.wizard[self.currStep].has_key("laststep"): # exit wizard, if condition of laststep doesn't hold
527                                 self.markDone()
528                                 self.close()
529                                 return
530                         else:
531                                 self.currStep += 1
532                                 self.updateValues()
533                 else:
534                         if self.wizard[self.currStep].has_key("displaytext"):
535                                 displaytext = self.wizard[self.currStep]["displaytext"]
536                                 print "set LCD text"
537                                 for x in self.lcdCallbacks:
538                                         x(displaytext)
539                         if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
540                                 self.stepHistory.append(self.currStep)
541                         print "wizard step:", self.wizard[self.currStep]
542                         
543                         if self.showSteps:
544                                 self["step"].setText(self.getTranslation("Step ") + str(self.currStep) + "/" + str(self.numSteps))
545                         if self.showStepSlider:
546                                 self["stepslider"].setValue(self.currStep)
547                 
548                         if self.wizard[self.currStep]["timeout"] is not None:
549                                 self.resetCounter() 
550                                 self.timeoutTimer.start(1000)
551                         
552                         print "wizard text", self.getTranslation(self.wizard[self.currStep]["text"])
553                         self.updateText(firstset = True)
554                         if self.wizard[self.currStep].has_key("displaytext"):
555                                 displaytext = self.wizard[self.currStep]["displaytext"]
556                                 print "set LCD text"
557                                 for x in self.lcdCallbacks:
558                                         x(displaytext)
559                                 
560                         self.codeafter=False
561                         self.runCode(self.wizard[self.currStep]["code"])
562                         if self.runCode(self.wizard[self.currStep]["code_async"]):
563                                 if self.updateValues in self.onShown:
564                                         self.onShown.remove(self.updateValues)
565                         else:
566                                 self.afterAsyncCode()
567
568         def afterAsyncCode(self):
569                 if not self.updateValues in self.onShown:
570                         self.onShown.append(self.updateValues)
571
572                 if self.codeafter:
573                         if self.wizard[self.prevStep]["nextstep"] is not None:
574                                 self.currStep = self.getStepWithID(self.wizard[self.prevStep]["nextstep"])
575                         if self.gotoStep is not None:
576                                 self.currStep = self.getStepWithID(self.gotoStep)
577                         self.currStep += 1
578                         self.updateValues()
579                         print "Now: " + str(self.currStep)
580                 else:
581                         if self.showList:
582                                 print "showing list,", self.currStep
583                                 for renderer in self.renderer:
584                                         rootrenderer = renderer
585                                         while renderer.source is not None:
586                                                 print "self.list:", self["list"]
587                                                 if renderer.source is self["list"]:
588                                                         print "setZPosition"
589                                                         rootrenderer.instance.setZPosition(1)
590                                                 renderer = renderer.source
591
592                                 #self["list"].instance.setZPosition(1)
593                                 self.list = []
594                                 if (self.wizard[self.currStep].has_key("dynamiclist")):
595                                         print "dynamic list, calling",  self.wizard[self.currStep]["dynamiclist"]
596                                         newlist = eval("self." + self.wizard[self.currStep]["dynamiclist"] + "()")
597                                         #self.wizard[self.currStep]["evaluatedlist"] = []
598                                         for entry in newlist:
599                                                 #self.wizard[self.currStep]["evaluatedlist"].append(entry)
600                                                 self.list.append(entry)
601                                         #del self.wizard[self.currStep]["dynamiclist"]
602                                 if (len(self.wizard[self.currStep]["list"]) > 0):
603                                         #self["list"].instance.setZPosition(2)
604                                         for x in self.wizard[self.currStep]["list"]:
605                                                 self.list.append((self.getTranslation(x[0]), x[1]))
606                                 self.wizard[self.currStep]["evaluatedlist"] = self.list
607                                 self["list"].list = self.list
608                                 self["list"].index = 0
609                         else:
610                                 self["list"].hide()
611         
612                         if self.showConfig:
613                                 print "showing config"
614                                 self["config"].instance.setZPosition(1)
615                                 if self.wizard[self.currStep]["config"]["type"] == "dynamic":
616                                                 print "config type is dynamic"
617                                                 self["config"].instance.setZPosition(2)
618                                                 self["config"].l.setList(eval("self." + self.wizard[self.currStep]["config"]["source"])())
619                                 elif (self.wizard[self.currStep]["config"]["screen"] != None):
620                                         if self.wizard[self.currStep]["config"]["type"] == "standalone":
621                                                 print "Type is standalone"
622                                                 self.session.openWithCallback(self.ok, self.wizard[self.currStep]["config"]["screen"])
623                                         else:
624                                                 self["config"].instance.setZPosition(2)
625                                                 print "wizard screen", self.wizard[self.currStep]["config"]["screen"]
626                                                 if self.wizard[self.currStep]["config"]["args"] == None:
627                                                         self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"])
628                                                 else:
629                                                         self.configInstance = self.session.instantiateDialog(self.wizard[self.currStep]["config"]["screen"], eval(self.wizard[self.currStep]["config"]["args"]))
630                                                 self["config"].l.setList(self.configInstance["config"].list)
631                                                 callbacks = self.configInstance["config"].onSelectionChanged
632                                                 self.configInstance["config"].destroy()
633                                                 print "clearConfigList", self.configInstance["config"], self["config"]
634                                                 self.configInstance["config"] = self["config"]
635                                                 self.configInstance["config"].onSelectionChanged = callbacks
636                                                 print "clearConfigList", self.configInstance["config"], self["config"]
637                                 else:
638                                         self["config"].l.setList([])
639                                         self.handleInputHelpers()
640                                         
641                                         
642                         else:
643                                 if self.has_key("config"):
644                                         self["config"].hide()
645
646         def timeoutCounterFired(self):
647                 self.timeoutCounter -= 1
648                 print "timeoutCounter:", self.timeoutCounter
649                 if self.timeoutCounter == 0:
650                         if self.wizard[self.currStep]["timeoutaction"] == "selectnext":
651                                 print "selection next item"
652                                 self.down()
653                         else:
654                                 if self.wizard[self.currStep]["timeoutaction"] == "changestep":
655                                         self.finished(gotoStep = self.wizard[self.currStep]["timeoutstep"])
656                 self.updateText()
657
658         def handleInputHelpers(self):
659                 if self["config"].getCurrent() is not None:
660                         if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
661                                 if self.has_key("VKeyIcon"):
662                                         self["VirtualKB"].setEnabled(True)
663                                         self["VKeyIcon"].boolean = True
664                                 if self.has_key("HelpWindow"):
665                                         if self["config"].getCurrent()[1].help_window.instance is not None:
666                                                 helpwindowpos = self["HelpWindow"].getPosition()
667                                                 from enigma import ePoint
668                                                 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
669                         else:
670                                 if self.has_key("VKeyIcon"):
671                                         self["VirtualKB"].setEnabled(False)
672                                         self["VKeyIcon"].boolean = False
673                 else:
674                         if self.has_key("VKeyIcon"):
675                                 self["VirtualKB"].setEnabled(False)
676                                 self["VKeyIcon"].boolean = False
677
678         def KeyText(self):
679                 from Screens.VirtualKeyBoard import VirtualKeyBoard
680                 self.currentConfigIndex = self["config"].getCurrentIndex()
681                 self.session.openWithCallback(self.VirtualKeyBoardCallback, VirtualKeyBoard, title = self["config"].getCurrent()[0], text = self["config"].getCurrent()[1].getValue())
682
683         def VirtualKeyBoardCallback(self, callback = None):
684                 if callback is not None and len(callback):
685                         if isinstance(self["config"].getCurrent()[1], ConfigText) or isinstance(self["config"].getCurrent()[1], ConfigPassword):
686                                 if self.has_key("HelpWindow"):
687                                         if self["config"].getCurrent()[1].help_window.instance is not None:
688                                                 helpwindowpos = self["HelpWindow"].getPosition()
689                                                 from enigma import ePoint
690                                                 self["config"].getCurrent()[1].help_window.instance.move(ePoint(helpwindowpos[0],helpwindowpos[1]))
691                         self["config"].instance.moveSelectionTo(self.currentConfigIndex)
692                         self["config"].setCurrentIndex(self.currentConfigIndex)
693                         self["config"].getCurrent()[1].setValue(callback)
694                         self["config"].invalidate(self["config"].getCurrent())
695
696
697 class WizardManager:
698         def __init__(self):
699                 self.wizards = []
700         
701         def registerWizard(self, wizard, precondition, priority = 0):
702                 self.wizards.append((wizard, precondition, priority))
703         
704         def getWizards(self):
705                 # x[1] is precondition
706                 for wizard in self.wizards:
707                         wizard[0].isLastWizard = False
708                 if len(self.wizards) > 0:
709                         self.wizards[-1][0].isLastWizard = True
710                 return [(x[2], x[0]) for x in self.wizards if x[1] == 1]
711
712 wizardManager = WizardManager()