X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/db3210090df08c276af7ac14cdfe7b09214a3dbd..3d9be241bd3d4558ee28e57bbe405553b8626543:/lib/python/Screens/MessageBox.py diff --git a/lib/python/Screens/MessageBox.py b/lib/python/Screens/MessageBox.py index 8b599a37..deea54ba 100644 --- a/lib/python/Screens/MessageBox.py +++ b/lib/python/Screens/MessageBox.py @@ -12,27 +12,21 @@ class MessageBox(Screen): 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.close_on_any_key = close_on_any_key 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.initTimeout(timeout) + self.list = [] if type != self.TYPE_ERROR: self["ErrorPixmap"].hide() @@ -44,7 +38,6 @@ class MessageBox(Screen): if type == self.TYPE_YESNO: self.list = [ (_("yes"), 0), (_("no"), 1) ] - self["list"] = MenuList(self.list) self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"], @@ -61,18 +54,45 @@ class MessageBox(Screen): "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 + " (" + str(self.timeout) + ")") - if self.timeout == 0: - self.timer.stop() + + def initTimeout(self, timeout): + self.timeout = timeout + if timeout > 0: + self.timer = eTimer() + self.timer.timeout.get().append(self.timerTick) + self.onExecBegin.append(self.startTimer) + self.origTitle = None + if self.execing: + self.timerTick() + else: + self.onShown.append(self.__onShown) + self.timerRunning = True + else: self.timerRunning = False - self.timeoutCallback() - + + def __onShown(self): + self.onShown.remove(self.__onShown) + self.timerTick() + + def startTimer(self): + self.timer.start(1000) + + def stopTimer(self): + if self.timerRunning: + del self.timer + self.setTitle(self.origTitle) + + def timerTick(self): + if self.execing: + self.timeout -= 1 + if self.origTitle is None: + self.origTitle = self.instance.getTitle() + self.setTitle(self.origTitle + " (" + str(self.timeout) + ")") + if self.timeout == 0: + self.timer.stop() + self.timerRunning = False + self.timeoutCallback() + def timeoutCallback(self): print "Timeout!" self.ok() @@ -98,17 +118,14 @@ class MessageBox(Screen): def left(self): self.move(self["list"].instance.pageUp) - - 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.setTitle(self.origTitle) - self.timerRunning = False + self.stopTimer() def __repr__(self): return str(type(self)) + "(" + self.text + ")"