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):
17 Screen.__init__(self, session)
19 self["text"] = Label(text)
23 self["ErrorPixmap"] = Pixmap()
24 self["QuestionPixmap"] = Pixmap()
25 self["InfoPixmap"] = Pixmap()
26 self.timerRunning = False
29 self.timer.timeout.get().append(self.timerTick)
30 self.timer.start(1000)
32 self.onShown.append(self.timerTick)
33 self.timerRunning = True
34 self.timeout = timeout
37 if type != self.TYPE_ERROR:
38 self["ErrorPixmap"].hide()
39 if type != self.TYPE_YESNO:
40 self["QuestionPixmap"].hide()
41 if type != self.TYPE_INFO:
42 self["InfoPixmap"].hide()
44 if type == self.TYPE_YESNO:
45 self.list = [ (_("yes"), 0), (_("no"), 1) ]
48 self["list"] = MenuList(self.list)
50 self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"],
52 "cancel": self.cancel,
54 "alwaysOK": self.alwaysOK,
59 "upRepeated": self.up,
60 "downRepeated": self.down,
61 "leftRepeated": self.left,
62 "rightRepeated": self.right
68 if self.origTitle is None:
69 self.origTitle = self.instance.getTitle()
70 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
73 self.timerRunning = False
74 self.timeoutCallback()
76 def timeoutCallback(self):
84 if self.type == self.TYPE_YESNO:
85 self.close(self["list"].getCurrent()[1] == 0)
93 self.move(self["list"].instance.moveUp)
96 self.move(self["list"].instance.moveDown)
99 self.move(self["list"].instance.pageUp)
104 self.move(self["list"].instance.pageDown)
106 def move(self, direction):
107 self["list"].instance.moveSelection(direction)
108 if self.timerRunning:
110 self.setTitle(self.origTitle)
111 self.timerRunning = False
114 return str(type(self)) + "(" + self.text + ")"