allow exiting wizards with exit key if there is no step history (i.e. user is in...
[enigma2.git] / lib / python / Screens / Wizard.py
index feba8ac224672bad58893be5560c0d070671c8cc..6833c525c9bd6df8254432abc5fb0c05f799fcef 100755 (executable)
@@ -1,8 +1,7 @@
 from Screen import Screen
 
-import string
-
 from Screens.HelpMenu import HelpableScreen
+from Screens.MessageBox import MessageBox
 from Components.config import config, KEY_LEFT, KEY_RIGHT, KEY_HOME, KEY_END, KEY_0, KEY_DELETE, KEY_BACKSPACE, KEY_OK, KEY_TOGGLEOW, KEY_ASCII, KEY_TIMEOUT, KEY_NUMBERS
 
 from Components.Label import Label
@@ -87,9 +86,9 @@ class Wizard(Screen):
                                        timeoutstep = ''
                                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}
                        elif (name == "text"):
-                               self.wizard[self.lastStep]["text"] = string.replace(str(attrs.get('value')), "\\n", "\n")
+                               self.wizard[self.lastStep]["text"] = str(attrs.get('value')).replace("\\n", "\n")
                        elif (name == "displaytext"):
-                               self.wizard[self.lastStep]["displaytext"] = string.replace(str(attrs.get('value')), "\\n", "\n")
+                               self.wizard[self.lastStep]["displaytext"] = str(attrs.get('value')).replace("\\n", "\n")
                        elif (name == "list"):
                                if (attrs.has_key('type')):
                                        if attrs["type"] == "dynamic":
@@ -286,6 +285,8 @@ class Wizard(Screen):
                if len(self.stepHistory) > 1:
                        self.currStep = self.stepHistory[-2]
                        self.stepHistory = self.stepHistory[:-2]
+               else:
+                       self.session.openWithCallback(self.exitWizardQuestion, MessageBox, (_("Are you sure you want to exit this wizard?") ) )
                if self.currStep < 1:
                        self.currStep = 1
                print "currStep:", self.currStep
@@ -293,6 +294,11 @@ class Wizard(Screen):
                self.updateValues()
                print "after updateValues stepHistory:", self.stepHistory
                
+       def exitWizardQuestion(self, ret = False):
+               if (ret):
+                       self.markDone()
+                       self.close()
+               
        def markDone(self):
                pass
        
@@ -477,6 +483,11 @@ class Wizard(Screen):
                        self.currStep += 1
                        self.updateValues()
                else:
+                       if self.wizard[self.currStep].has_key("displaytext"):
+                               displaytext = self.wizard[self.currStep]["displaytext"]
+                               print "set LCD text"
+                               for x in self.lcdCallbacks:
+                                       x(displaytext)
                        if len(self.stepHistory) == 0 or self.stepHistory[-1] != self.currStep:
                                self.stepHistory.append(self.currStep)
                        print "wizard step:", self.wizard[self.currStep]
@@ -601,10 +612,7 @@ class WizardManager:
                self.wizards.append((wizard, precondition, priority))
        
        def getWizards(self):
-               list = []
-               for x in self.wizards:
-                       if x[1] == 1: # precondition
-                               list.append((x[2], x[0]))
-               return list
+               # x[1] is precondition
+               return [(x[2], x[0]) for x in self.wizards if x[1] == 1]
 
 wizardManager = WizardManager()