start timer after message box is actually visible
[enigma2.git] / lib / python / Screens / MessageBox.py
index 8b599a37f481032fd89ee39fb4577d9f3247e9f4..33d51b24212731d8058ee422e08a7bf0092de512 100644 (file)
@@ -12,13 +12,14 @@ class MessageBox(Screen):
        TYPE_WARNING = 2
        TYPE_ERROR = 3
        
        TYPE_WARNING = 2
        TYPE_ERROR = 3
        
-       def __init__(self, session, text, type = TYPE_YESNO, timeout = -1):
+       def __init__(self, session, text, type = TYPE_YESNO, timeout = -1, close_on_any_key = False):
                self.type = type
                Screen.__init__(self, session)
                
                self["text"] = Label(text)
                
                self.text = text
                self.type = type
                Screen.__init__(self, session)
                
                self["text"] = Label(text)
                
                self.text = text
+               self.close_on_any_key = close_on_any_key
                
                self["ErrorPixmap"] = Pixmap()
                self["QuestionPixmap"] = Pixmap()
                
                self["ErrorPixmap"] = Pixmap()
                self["QuestionPixmap"] = Pixmap()
@@ -27,7 +28,7 @@ class MessageBox(Screen):
                if timeout > 0:
                        self.timer = eTimer()
                        self.timer.timeout.get().append(self.timerTick)
                if timeout > 0:
                        self.timer = eTimer()
                        self.timer.timeout.get().append(self.timerTick)
-                       self.timer.start(1000)
+                       self.onExecBegin.append(self.startTimer)
                        self.origTitle = None
                        self.onShown.append(self.timerTick)
                        self.timerRunning = True
                        self.origTitle = None
                        self.onShown.append(self.timerTick)
                        self.timerRunning = True
@@ -61,8 +62,10 @@ class MessageBox(Screen):
                                "leftRepeated": self.left,
                                "rightRepeated": self.right
                        }, -1)
                                "leftRepeated": self.left,
                                "rightRepeated": self.right
                        }, -1)
-                       
-       
+
+       def startTimer(self):
+               self.timer.start(1000)
+
        def timerTick(self):
                self.timeout -= 1
                if self.origTitle is None:
        def timerTick(self):
                self.timeout -= 1
                if self.origTitle is None:
@@ -98,12 +101,13 @@ class MessageBox(Screen):
        def left(self):
                self.move(self["list"].instance.pageUp)
                
        def left(self):
                self.move(self["list"].instance.pageUp)
                
-
-               
        def right(self):
                self.move(self["list"].instance.pageDown)
 
        def move(self, direction):
        def right(self):
                self.move(self["list"].instance.pageDown)
 
        def move(self, direction):
+               if self.close_on_any_key:
+                       self.close(True)
+
                self["list"].instance.moveSelection(direction)
                if self.timerRunning:
                        self.timer.stop()
                self["list"].instance.moveSelection(direction)
                if self.timerRunning:
                        self.timer.stop()