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.Sources.StaticText import StaticText
6 from Components.MenuList import MenuList
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, enable_input = True):
17 Screen.__init__(self, session)
19 self["text"] = Label(text)
20 self["Text"] = StaticText(text)
21 self["selectedChoice"] = StaticText()
24 self.close_on_any_key = close_on_any_key
26 self["ErrorPixmap"] = Pixmap()
27 self["QuestionPixmap"] = Pixmap()
28 self["InfoPixmap"] = Pixmap()
29 self.timerRunning = False
30 self.initTimeout(timeout)
33 if type != self.TYPE_ERROR:
34 self["ErrorPixmap"].hide()
35 if type != self.TYPE_YESNO:
36 self["QuestionPixmap"].hide()
37 if type != self.TYPE_INFO:
38 self["InfoPixmap"].hide()
40 if type == self.TYPE_YESNO:
42 self.list = [ (_("yes"), 0), (_("no"), 1) ]
44 self.list = [ (_("no"), 1), (_("yes"), 0) ]
47 self["selectedChoice"].setText(self.list[0][0])
48 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
66 def initTimeout(self, timeout):
67 self.timeout = timeout
70 self.timer.callback.append(self.timerTick)
71 self.onExecBegin.append(self.startTimer)
76 self.onShown.append(self.__onShown)
77 self.timerRunning = True
79 self.timerRunning = False
82 self.onShown.remove(self.__onShown)
86 self.timer.start(1000)
91 self.onExecBegin.remove(self.startTimer)
92 self.setTitle(self.origTitle)
93 self.timerRunning = False
98 if self.origTitle is None:
99 self.origTitle = self.instance.getTitle()
100 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
101 if self.timeout == 0:
103 self.timerRunning = False
104 self.timeoutCallback()
106 def timeoutCallback(self):
114 if self.type == self.TYPE_YESNO:
115 self.close(self["list"].getCurrent()[1] == 0)
123 self.move(self["list"].instance.moveUp)
126 self.move(self["list"].instance.moveDown)
129 self.move(self["list"].instance.pageUp)
132 self.move(self["list"].instance.pageDown)
134 def move(self, direction):
135 if self.close_on_any_key:
137 self["list"].instance.moveSelection(direction)
139 self["selectedChoice"].setText(self["list"].getCurrent()[0])
143 return str(type(self)) + "(" + self.text + ")"