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):
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)
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
65 def initTimeout(self, timeout):
66 self.timeout = timeout
69 self.timer.callback.append(self.timerTick)
70 self.onExecBegin.append(self.startTimer)
75 self.onShown.append(self.__onShown)
76 self.timerRunning = True
78 self.timerRunning = False
81 self.onShown.remove(self.__onShown)
85 self.timer.start(1000)
90 self.setTitle(self.origTitle)
91 self.timerRunning = False
96 if self.origTitle is None:
97 self.origTitle = self.instance.getTitle()
98 self.setTitle(self.origTitle + " (" + str(self.timeout) + ")")
101 self.timerRunning = False
102 self.timeoutCallback()
104 def timeoutCallback(self):
112 if self.type == self.TYPE_YESNO:
113 self.close(self["list"].getCurrent()[1] == 0)
121 self.move(self["list"].instance.moveUp)
124 self.move(self["list"].instance.moveDown)
127 self.move(self["list"].instance.pageUp)
130 self.move(self["list"].instance.pageDown)
132 def move(self, direction):
133 if self.close_on_any_key:
135 self["list"].instance.moveSelection(direction)
137 self["selectedChoice"].setText(self["list"].getCurrent()[0])
141 return str(type(self)) + "(" + self.text + ")"