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):
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:
38 self.list = [ (_("yes"), 0), (_("no"), 1) ]
40 self["list"] = MenuList(self.list)
42 self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"],
44 "cancel": self.cancel,
46 "alwaysOK": self.alwaysOK,
51 "upRepeated": self.up,
52 "downRepeated": self.down,
53 "leftRepeated": self.left,
54 "rightRepeated": self.right
57 def initTimeout(self, timeout):
58 self.timeout = timeout
61 self.timer.timeout.get().append(self.timerTick)
62 self.onExecBegin.append(self.startTimer)
67 self.onShown.append(self.__onShown)
68 self.timerRunning = True
70 self.timerRunning = False
73 self.onShown.remove(self.__onShown)
77 self.timer.start(1000)
82 self.setTitle(self.origTitle)
83 self.timerRunning = False
88 if self.origTitle is None:
89 self.origTitle = self.instance.getTitle()
90 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
93 self.timerRunning = False
94 self.timeoutCallback()
96 def timeoutCallback(self):
104 if self.type == self.TYPE_YESNO:
105 self.close(self["list"].getCurrent()[1] == 0)
113 self.move(self["list"].instance.moveUp)
116 self.move(self["list"].instance.moveDown)
119 self.move(self["list"].instance.pageUp)
122 self.move(self["list"].instance.pageDown)
124 def move(self, direction):
125 if self.close_on_any_key:
127 self["list"].instance.moveSelection(direction)
131 return str(type(self)) + "(" + self.text + ")"