add timeout for MessageBox screens (just add timeout=<seconds> as argument when creat...
authorStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Thu, 25 May 2006 23:14:05 +0000 (23:14 +0000)
committerStefan Pluecken <stefan.pluecken@multimedia-labs.de>
Thu, 25 May 2006 23:14:05 +0000 (23:14 +0000)
RecordTimer.py
lib/python/Plugins/DemoPlugins/TestPlugin/plugin.py
lib/python/Screens/MessageBox.py

index 5c64f9b..10a6013 100644 (file)
@@ -160,10 +160,10 @@ class RecordTimerEntry(timer.TimerEntry):
                                self.first_try_prepare = False
                                if config.recording.asktozap.value == 0:
                                        self.log(8, "asking user to zap away")
-                                       Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n"))
+                                       Notifications.AddNotificationWithCallback(self.failureCB, MessageBox, _("A timer failed to record!\nDisable TV and try again?\n"), timeout=15)
                                else: # zap without asking
                                        self.log(9, "zap without asking")
-                                       Notifications.AddNotification(MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n"), type=MessageBox.TYPE_WARNING)
+                                       Notifications.AddNotification(MessageBox, _("In order to record a timer, the TV was switched to the recording service!\n"), type=MessageBox.TYPE_WARNING, timeout=15)
                                        self.failureCB(True)
 
                        self.do_backoff()
index e6d83bf..e074aee 100644 (file)
@@ -49,8 +49,14 @@ class Test(Screen):
                self.onShown.append(self.openTest)
 
        def openTest(self):
-               self.session.open(InputBox)
-               
+               self.session.openWithCallback(self.callback, MessageBox, _("Test-Messagebox?"))
+
+#              self.session.open(InputBox)
+       
+       def callback(self, answer):
+               print "answer:", answer
+               self.close()
+       
        def keyLeft(self):
                self["text"].left()
        
@@ -69,7 +75,8 @@ class Test(Screen):
                self["text"].number(number)
 
 def main(session, **kwargs):
-       session.openWithCallback(test, ChoiceBox, title="Delete everything on this Dreambox?", list=[(_("yes"), "yes"), (_("no"), "no"), (_("perhaps"), "perhaps"), (_("ask me tomorrow"), "ask me tomorrow"), (_("leave me alone with this!"), "yes")])
+       session.openWithCallback(test, MessageBox, _("Test-Messagebox?"), timeout = 10)
+       #session.openWithCallback(test, ChoiceBox, title="Delete everything on this Dreambox?", list=[(_("yes"), "yes"), (_("no"), "no"), (_("perhaps"), "perhaps"), (_("ask me tomorrow"), "ask me tomorrow"), (_("leave me alone with this!"), "yes")])
        
 def test(returnValue):
        print "You entered", returnValue
index 51dd2fb..ed3bb4f 100644 (file)
@@ -4,7 +4,7 @@ from Components.Label import Label
 from Components.Button import Button
 from Components.Pixmap import Pixmap
 from Components.MenuList import MenuList
-from enigma import eSize, ePoint
+from enigma import eSize, ePoint, eTimer
 
 class MessageBox(Screen):
        TYPE_YESNO = 0
@@ -12,7 +12,7 @@ class MessageBox(Screen):
        TYPE_WARNING = 2
        TYPE_ERROR = 3
        
-       def __init__(self, session, text, type = TYPE_YESNO):
+       def __init__(self, session, text, type = TYPE_YESNO, timeout = -1):
                self.type = type
                Screen.__init__(self, session)
                
@@ -21,6 +21,15 @@ class MessageBox(Screen):
                self["ErrorPixmap"] = Pixmap()
                self["QuestionPixmap"] = Pixmap()
                self["InfoPixmap"] = Pixmap()
+               self.timerRunning = False
+               if timeout > 0:
+                       self.timer = eTimer()
+                       self.timer.timeout.get().append(self.timerTick)
+                       self.timer.start(1000)
+                       self.origTitle = None
+                       self.onShown.append(self.timerTick)
+                       self.timerRunning = True
+               self.timeout = timeout
                
                self.list = []
                if type != self.TYPE_ERROR:
@@ -36,14 +45,36 @@ class MessageBox(Screen):
 
                self["list"] = MenuList(self.list)
                
-               self["actions"] = ActionMap(["MsgBoxActions"], 
+               self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"], 
                        {
                                "cancel": self.cancel,
                                "ok": self.ok,
-                               "alwaysOK": self.alwaysOK
-                       })
+                               "alwaysOK": self.alwaysOK,
+                               "up": self.up,
+                               "down": self.down,
+                               "left": self.left,
+                               "right": self.right,
+                               "upRepeated": self.up,
+                               "downRepeated": self.down,
+                               "leftRepeated": self.left,
+                               "rightRepeated": self.right
+                       }, -1)
                        
        
+       def timerTick(self):
+               self.timeout -= 1
+               if self.origTitle is None:
+                       self.origTitle = self.instance.getTitle()
+               self.setTitle(self.origTitle + " (" + _("Timeout: ") + str(self.timeout) + ")")
+               if self.timeout == 0:
+                       self.timer.stop()
+                       self.timerRunning = False
+                       self.timeoutCallback()
+                       
+       def timeoutCallback(self):
+               print "Timeout!"
+               self.ok()
+       
        def cancel(self):
                self.close(False)
        
@@ -55,3 +86,24 @@ class MessageBox(Screen):
 
        def alwaysOK(self):
                self.close(True)
+
+       def up(self):
+               self.move(self["list"].instance.moveUp)
+               
+       def down(self):
+               self.move(self["list"].instance.moveDown)
+
+       def left(self):
+               self.move(self["list"].instance.pageUp)
+               
+
+               
+       def right(self):
+               self.move(self["list"].instance.pageDown)
+
+       def move(self, direction):
+               self["list"].instance.moveSelection(direction)
+               if self.timerRunning:
+                       self.timer.stop()
+                       self.setTitle(self.origTitle)
+                       self.timerRunning = False
\ No newline at end of file