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, msgBoxID = None):
17 Screen.__init__(self, session)
19 self.msgBoxID = msgBoxID
21 self["text"] = Label(text)
22 self["Text"] = StaticText(text)
23 self["selectedChoice"] = StaticText()
26 self.close_on_any_key = close_on_any_key
28 self["ErrorPixmap"] = Pixmap()
29 self["QuestionPixmap"] = Pixmap()
30 self["InfoPixmap"] = Pixmap()
31 self.timerRunning = False
32 self.initTimeout(timeout)
35 if type != self.TYPE_ERROR:
36 self["ErrorPixmap"].hide()
37 if type != self.TYPE_YESNO:
38 self["QuestionPixmap"].hide()
39 if type != self.TYPE_INFO:
40 self["InfoPixmap"].hide()
42 if type == self.TYPE_YESNO:
44 self.list = [ (_("yes"), 0), (_("no"), 1) ]
46 self.list = [ (_("no"), 1), (_("yes"), 0) ]
49 self["selectedChoice"].setText(self.list[0][0])
50 self["list"] = MenuList(self.list)
53 self["actions"] = ActionMap(["MsgBoxActions", "DirectionActions"],
55 "cancel": self.cancel,
57 "alwaysOK": self.alwaysOK,
62 "upRepeated": self.up,
63 "downRepeated": self.down,
64 "leftRepeated": self.left,
65 "rightRepeated": self.right
68 def initTimeout(self, timeout):
69 self.timeout = timeout
72 self.timer.callback.append(self.timerTick)
73 self.onExecBegin.append(self.startTimer)
78 self.onShown.append(self.__onShown)
79 self.timerRunning = True
81 self.timerRunning = False
84 self.onShown.remove(self.__onShown)
88 self.timer.start(1000)
93 self.onExecBegin.remove(self.startTimer)
94 self.setTitle(self.origTitle)
95 self.timerRunning = False
100 if self.origTitle is None:
101 self.origTitle = self.instance.getTitle()
102 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
103 if self.timeout == 0:
105 self.timerRunning = False
106 self.timeoutCallback()
108 def timeoutCallback(self):
116 if self.type == self.TYPE_YESNO:
117 self.close(self["list"].getCurrent()[1] == 0)
125 self.move(self["list"].instance.moveUp)
128 self.move(self["list"].instance.moveDown)
131 self.move(self["list"].instance.pageUp)
134 self.move(self["list"].instance.pageDown)
136 def move(self, direction):
137 if self.close_on_any_key:
139 self["list"].instance.moveSelection(direction)
141 self["selectedChoice"].setText(self["list"].getCurrent()[0])
145 return str(type(self)) + "(" + self.text + ")"