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 Components.Sources.StaticText import StaticText
8 from enigma import eTimer
10 class MessageBox(Screen):
16 def __init__(self, session, text, type = TYPE_YESNO, timeout = -1, close_on_any_key = False, default = True):
18 Screen.__init__(self, session)
20 self["text"] = Label(text)
21 self["Text"] = StaticText(text)
22 self["selectedChoice"] = StaticText()
25 self.close_on_any_key = close_on_any_key
27 self["ErrorPixmap"] = Pixmap()
28 self["QuestionPixmap"] = Pixmap()
29 self["InfoPixmap"] = Pixmap()
30 self.timerRunning = False
31 self.initTimeout(timeout)
34 if type != self.TYPE_ERROR:
35 self["ErrorPixmap"].hide()
36 if type != self.TYPE_YESNO:
37 self["QuestionPixmap"].hide()
38 if type != self.TYPE_INFO:
39 self["InfoPixmap"].hide()
41 if type == self.TYPE_YESNO:
43 self.list = [ (_("yes"), 0), (_("no"), 1) ]
45 self.list = [ (_("no"), 1), (_("yes"), 0) ]
48 self["selectedChoice"].setText(self.list[0][0])
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
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.setTitle(self.origTitle)
92 self.timerRunning = False
97 if self.origTitle is None:
98 self.origTitle = self.instance.getTitle()
99 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
100 if self.timeout == 0:
102 self.timerRunning = False
103 self.timeoutCallback()
105 def timeoutCallback(self):
113 if self.type == self.TYPE_YESNO:
114 self.close(self["list"].getCurrent()[1] == 0)
122 self.move(self["list"].instance.moveUp)
125 self.move(self["list"].instance.moveDown)
128 self.move(self["list"].instance.pageUp)
131 self.move(self["list"].instance.pageDown)
133 def move(self, direction):
134 if self.close_on_any_key:
136 self["list"].instance.moveSelection(direction)
138 self["selectedChoice"].setText(self["list"].getCurrent()[0])
142 return str(type(self)) + "(" + self.text + ")"