1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Label import Label
4 from Components.Pixmap import Pixmap
5 from Components.MenuList import MenuList
6 from enigma import eTimer
8 class MessageBox(Screen):
14 def __init__(self, session, text, type = TYPE_YESNO, timeout = -1, close_on_any_key = False, default = True):
16 Screen.__init__(self, session)
18 self["text"] = Label(text)
21 self.close_on_any_key = close_on_any_key
23 self["ErrorPixmap"] = Pixmap()
24 self["QuestionPixmap"] = Pixmap()
25 self["InfoPixmap"] = Pixmap()
26 self.timerRunning = False
27 self.initTimeout(timeout)
30 if type != self.TYPE_ERROR:
31 self["ErrorPixmap"].hide()
32 if type != self.TYPE_YESNO:
33 self["QuestionPixmap"].hide()
34 if type != self.TYPE_INFO:
35 self["InfoPixmap"].hide()
37 if type == self.TYPE_YESNO:
39 self.list = [ (_("yes"), 0), (_("no"), 1) ]
41 self.list = [ (_("no"), 1), (_("yes"), 0) ]
43 self["list"] = MenuList(self.list)
45 self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"],
47 "cancel": self.cancel,
49 "alwaysOK": self.alwaysOK,
54 "upRepeated": self.up,
55 "downRepeated": self.down,
56 "leftRepeated": self.left,
57 "rightRepeated": self.right
60 def initTimeout(self, timeout):
61 self.timeout = timeout
64 self.timer.callback.append(self.timerTick)
65 self.onExecBegin.append(self.startTimer)
70 self.onShown.append(self.__onShown)
71 self.timerRunning = True
73 self.timerRunning = False
76 self.onShown.remove(self.__onShown)
80 self.timer.start(1000)
85 self.setTitle(self.origTitle)
86 self.timerRunning = False
91 if self.origTitle is None:
92 self.origTitle = self.instance.getTitle()
93 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
96 self.timerRunning = False
97 self.timeoutCallback()
99 def timeoutCallback(self):
107 if self.type == self.TYPE_YESNO:
108 self.close(self["list"].getCurrent()[1] == 0)
116 self.move(self["list"].instance.moveUp)
119 self.move(self["list"].instance.moveDown)
122 self.move(self["list"].instance.pageUp)
125 self.move(self["list"].instance.pageDown)
127 def move(self, direction):
128 if self.close_on_any_key:
130 self["list"].instance.moveSelection(direction)
134 return str(type(self)) + "(" + self.text + ")"