1 from Screen import Screen
2 from Components.ActionMap import ActionMap
3 from Components.Label import Label
4 from Components.Button import Button
5 from Components.Pixmap import Pixmap
6 from Components.MenuList import MenuList
7 from enigma import eSize, ePoint, eTimer
9 class MessageBox(Screen):
15 def __init__(self, session, text, type = TYPE_YESNO, timeout = -1, close_on_any_key = False):
17 Screen.__init__(self, session)
19 self["text"] = Label(text)
22 self.close_on_any_key = close_on_any_key
24 self["ErrorPixmap"] = Pixmap()
25 self["QuestionPixmap"] = Pixmap()
26 self["InfoPixmap"] = Pixmap()
27 self.timerRunning = False
28 self.initTimeout(timeout)
31 if type != self.TYPE_ERROR:
32 self["ErrorPixmap"].hide()
33 if type != self.TYPE_YESNO:
34 self["QuestionPixmap"].hide()
35 if type != self.TYPE_INFO:
36 self["InfoPixmap"].hide()
38 if type == self.TYPE_YESNO:
39 self.list = [ (_("yes"), 0), (_("no"), 1) ]
41 self["list"] = MenuList(self.list)
43 self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"],
45 "cancel": self.cancel,
47 "alwaysOK": self.alwaysOK,
52 "upRepeated": self.up,
53 "downRepeated": self.down,
54 "leftRepeated": self.left,
55 "rightRepeated": self.right
58 def initTimeout(self, timeout):
59 self.timeout = timeout
62 self.timer.timeout.get().append(self.timerTick)
63 self.onExecBegin.append(self.startTimer)
68 self.onShown.append(self.__onShown)
69 self.timerRunning = True
71 self.timerRunning = False
74 self.onShown.remove(self.__onShown)
78 self.timer.start(1000)
83 self.setTitle(self.origTitle)
84 self.timerRunning = False
89 if self.origTitle is None:
90 self.origTitle = self.instance.getTitle()
91 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
94 self.timerRunning = False
95 self.timeoutCallback()
97 def timeoutCallback(self):
105 if self.type == self.TYPE_YESNO:
106 self.close(self["list"].getCurrent()[1] == 0)
114 self.move(self["list"].instance.moveUp)
117 self.move(self["list"].instance.moveDown)
120 self.move(self["list"].instance.pageUp)
123 self.move(self["list"].instance.pageDown)
125 def move(self, direction):
126 if self.close_on_any_key:
128 self["list"].instance.moveSelection(direction)
132 return str(type(self)) + "(" + self.text + ")"