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 Components.Sources.StaticText import StaticText
7 from enigma import eTimer
9 class MessageBox(Screen):
15 def __init__(self, session, text, type = TYPE_YESNO, timeout = -1, close_on_any_key = False, default = True):
17 Screen.__init__(self, session)
19 self["text"] = Label(text)
20 self["Text"] = StaticText(text)
23 self.close_on_any_key = close_on_any_key
25 self["ErrorPixmap"] = Pixmap()
26 self["QuestionPixmap"] = Pixmap()
27 self["InfoPixmap"] = Pixmap()
28 self.timerRunning = False
29 self.initTimeout(timeout)
32 if type != self.TYPE_ERROR:
33 self["ErrorPixmap"].hide()
34 if type != self.TYPE_YESNO:
35 self["QuestionPixmap"].hide()
36 if type != self.TYPE_INFO:
37 self["InfoPixmap"].hide()
39 if type == self.TYPE_YESNO:
41 self.list = [ (_("yes"), 0), (_("no"), 1) ]
43 self.list = [ (_("no"), 1), (_("yes"), 0) ]
45 self["list"] = MenuList(self.list)
47 self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"],
49 "cancel": self.cancel,
51 "alwaysOK": self.alwaysOK,
56 "upRepeated": self.up,
57 "downRepeated": self.down,
58 "leftRepeated": self.left,
59 "rightRepeated": self.right
62 def initTimeout(self, timeout):
63 self.timeout = timeout
66 self.timer.callback.append(self.timerTick)
67 self.onExecBegin.append(self.startTimer)
72 self.onShown.append(self.__onShown)
73 self.timerRunning = True
75 self.timerRunning = False
78 self.onShown.remove(self.__onShown)
82 self.timer.start(1000)
87 self.setTitle(self.origTitle)
88 self.timerRunning = False
93 if self.origTitle is None:
94 self.origTitle = self.instance.getTitle()
95 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
98 self.timerRunning = False
99 self.timeoutCallback()
101 def timeoutCallback(self):
109 if self.type == self.TYPE_YESNO:
110 self.close(self["list"].getCurrent()[1] == 0)
118 self.move(self["list"].instance.moveUp)
121 self.move(self["list"].instance.moveDown)
124 self.move(self["list"].instance.pageUp)
127 self.move(self["list"].instance.pageDown)
129 def move(self, direction):
130 if self.close_on_any_key:
132 self["list"].instance.moveSelection(direction)
136 return str(type(self)) + "(" + self.text + ")"