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
30 self.timer.timeout.get().append(self.timerTick)
31 self.onExecBegin.append(self.startTimer)
33 self.onShown.append(self.timerTick)
34 self.timerRunning = True
35 self.timeout = timeout
38 if type != self.TYPE_ERROR:
39 self["ErrorPixmap"].hide()
40 if type != self.TYPE_YESNO:
41 self["QuestionPixmap"].hide()
42 if type != self.TYPE_INFO:
43 self["InfoPixmap"].hide()
45 if type == self.TYPE_YESNO:
46 self.list = [ (_("yes"), 0), (_("no"), 1) ]
49 self["list"] = MenuList(self.list)
51 self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"],
53 "cancel": self.cancel,
55 "alwaysOK": self.alwaysOK,
60 "upRepeated": self.up,
61 "downRepeated": self.down,
62 "leftRepeated": self.left,
63 "rightRepeated": self.right
67 self.timer.start(1000)
72 if self.origTitle is None:
73 self.origTitle = self.instance.getTitle()
74 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
77 self.timerRunning = False
78 self.timeoutCallback()
80 def timeoutCallback(self):
88 if self.type == self.TYPE_YESNO:
89 self.close(self["list"].getCurrent()[1] == 0)
97 self.move(self["list"].instance.moveUp)
100 self.move(self["list"].instance.moveDown)
103 self.move(self["list"].instance.pageUp)
106 self.move(self["list"].instance.pageDown)
108 def move(self, direction):
109 if self.close_on_any_key:
112 self["list"].instance.moveSelection(direction)
113 if self.timerRunning:
115 self.setTitle(self.origTitle)
116 self.timerRunning = False
119 return str(type(self)) + "(" + self.text + ")"