2 from Components.MenuList import MenuList
3 from Components.ActionMap import ActionMap
4 from Components.ActionMap import NumberActionMap
5 from Components.Header import Header
6 from Components.Button import Button
7 from Components.Label import Label
9 from Components.HTMLComponent import *
10 from Components.GUIComponent import *
11 from Components.config import config, ConfigSubsection, ConfigSelection, ConfigSubList, getConfigListEntry, KEY_LEFT, KEY_RIGHT, KEY_0, ConfigNothing, ConfigPIN
12 from Components.ConfigList import ConfigList
14 from enigma import eTimer, eDVBCI_UI, eListboxPythonStringContent, eListboxPythonConfigContent
19 config.ci = ConfigSubList()
20 for slot in range(MAX_NUM_CI):
21 config.ci.append(ConfigSubsection())
22 config.ci[slot].canDescrambleMultipleServices = ConfigSelection(choices = [("auto", _("Auto")), ("no", _("No")), ("yes", _("Yes"))], default = "auto")
25 def __init__(self, session, slotid, action):
26 Screen.__init__(self, session)
28 print "ciMMI with action" + str(action)
34 self.timer.timeout.get().append(self.keyCancel)
37 self["title"] = Label("")
38 self["subtitle"] = Label("")
39 self["bottom"] = Label("")
40 self["entries"] = ConfigList([ ])
42 self["actions"] = NumberActionMap(["SetupActions"],
44 "ok": self.okbuttonClick,
45 "cancel": self.keyCancel,
48 "right": self.keyRight,
49 "1": self.keyNumberGlobal,
50 "2": self.keyNumberGlobal,
51 "3": self.keyNumberGlobal,
52 "4": self.keyNumberGlobal,
53 "5": self.keyNumberGlobal,
54 "6": self.keyNumberGlobal,
55 "7": self.keyNumberGlobal,
56 "8": self.keyNumberGlobal,
57 "9": self.keyNumberGlobal,
58 "0": self.keyNumberGlobal
63 if action == 2: #start MMI
64 eDVBCI_UI.getInstance().startMMI(self.slotid)
66 elif action == 3: #mmi already there (called from infobar)
69 def addEntry(self, list, entry):
70 if entry[0] == "TEXT": #handle every item (text / pin only?)
71 list.append( (entry[1], ConfigNothing(), entry[2]) )
76 x = ConfigPIN(0, len = pinlength, censor = "*")
79 x = ConfigPIN(0, len = pinlength)
80 self["subtitle"].setText(entry[2])
81 list.append( getConfigListEntry("", x) )
82 self["bottom"].setText(_("please press OK when ready"))
84 def okbuttonClick(self):
88 if self.tag == "WAIT":
89 print "do nothing - wait"
90 elif self.tag == "MENU":
92 cur = self["entries"].getCurrent()
94 eDVBCI_UI.getInstance().answerMenu(self.slotid, cur[2])
96 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
98 elif self.tag == "LIST":
100 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
102 elif self.tag == "ENQ":
103 cur = self["entries"].getCurrent()
104 answer = str(cur[1].value)
106 while length < cur[1].getLength():
109 eDVBCI_UI.getInstance().answerEnq(self.slotid, answer)
114 self.close(self.slotid)
120 if self.tag == "WAIT":
121 eDVBCI_UI.getInstance().stopMMI(self.slotid)
123 elif self.tag in [ "MENU", "LIST" ]:
125 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
127 elif self.tag == "ENQ":
129 eDVBCI_UI.getInstance().cancelEnq(self.slotid)
132 print "give cancel action to ci"
134 def keyConfigEntry(self, key):
137 self["entries"].handleKey(key)
141 def keyNumberGlobal(self, number):
143 self.keyConfigEntry(KEY_0 + number)
147 self.keyConfigEntry(KEY_LEFT)
151 self.keyConfigEntry(KEY_RIGHT)
153 def updateList(self, list):
154 List = self["entries"]
156 List.instance.moveSelectionTo(0)
163 self["title"].setText("")
164 self["subtitle"].setText("")
165 self["bottom"].setText("")
167 list.append( (_("wait for ci..."), ConfigNothing()) )
168 self.updateList(list)
170 def showScreen(self):
171 screen = eDVBCI_UI.getInstance().getMMIScreen(self.slotid)
176 if len(screen) > 0 and screen[0][0] == "CLOSE":
177 timeout = screen[0][1]
179 self.timer.start(timeout*1000, True)
183 self.tag = screen[0][0]
185 if entry[0] == "PIN":
186 self.addEntry(list, entry)
188 if entry[0] == "TITLE":
189 self["title"].setText(entry[1])
190 elif entry[0] == "SUBTITLE":
191 self["subtitle"].setText(entry[1])
192 elif entry[0] == "BOTTOM":
193 self["bottom"].setText(entry[1])
194 elif entry[0] == "TEXT":
195 self.addEntry(list, entry)
196 self.updateList(list)
198 def ciStateChanged(self):
199 if self.action == 0: #reset
201 if self.action == 1: #init
204 #module still there ?
205 if eDVBCI_UI.getInstance().getState(self.slotid) != 2:
208 #mmi session still active ?
209 if eDVBCI_UI.getInstance().getMMIState(self.slotid) != 1:
212 if self.action > 1 and eDVBCI_UI.getInstance().availableMMI(self.slotid) == 1:
215 #FIXME: check for mmi-session closed
217 class CiMessageHandler:
222 eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged)
224 def setSession(self, session):
225 self.session = session
227 def ciStateChanged(self, slot):
231 if slot in self.dlgs:
232 self.dlgs[slot].ciStateChanged()
233 elif eDVBCI_UI.getInstance().availableMMI(slot) == 1:
235 self.dlgs[slot] = self.session.openWithCallback(self.dlgClosed, CiMmi, slot, 3)
239 def dlgClosed(self, slot):
242 def registerCIMessageHandler(self, slot, func):
243 self.unregisterCIMessageHandler(slot)
246 def unregisterCIMessageHandler(self, slot):
250 CiHandler = CiMessageHandler()
252 class CiSelection(Screen):
253 def __init__(self, session):
254 Screen.__init__(self, session)
256 self["actions"] = ActionMap(["OkCancelActions", "CiSelectionActions"],
258 "left": self.keyLeft,
259 "right": self.keyLeft,
260 "ok": self.okbuttonClick,
261 "cancel": self.cancel
268 for slot in range(MAX_NUM_CI):
269 state = eDVBCI_UI.getInstance().getState(slot)
271 self.appendEntries(slot, state)
272 CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
274 menuList = ConfigList(self.list)
275 menuList.list = self.list
276 menuList.l.setList(self.list)
277 self["entries"] = menuList
279 def keyConfigEntry(self, key):
281 self["entries"].handleKey(key)
282 self["entries"].getCurrent()[1].save()
287 self.keyConfigEntry(KEY_LEFT)
290 self.keyConfigEntry(KEY_RIGHT)
292 def appendEntries(self, slot, state):
293 self.state[slot] = state
294 self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
295 self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
297 if self.state[slot] == 0: #no module
298 self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
299 elif self.state[slot] == 1: #module in init
300 self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
301 elif self.state[slot] == 2: #module ready
303 appname = eDVBCI_UI.getInstance().getAppName(slot)
304 self.list.append( (appname, ConfigNothing(), 2, slot) )
306 self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
308 def updateState(self, slot):
309 state = eDVBCI_UI.getInstance().getState(slot)
310 self.state[slot] = state
313 while self.list[slotidx][2] != slot:
316 slotidx += 1 # do not change Reset
317 slotidx += 1 # do not change Init
319 if state == 0: #no module
320 self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
321 elif state == 1: #module in init
322 self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
323 elif state == 2: #module ready
325 appname = eDVBCI_UI.getInstance().getAppName(slot)
326 self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
328 lst = self["entries"]
330 lst.l.setList(self.list)
332 def ciStateChanged(self, slot):
334 self.dlg.ciStateChanged()
336 state = eDVBCI_UI.getInstance().getState(slot)
337 if self.state[slot] != state:
338 #print "something happens"
339 self.state[slot] = state
340 self.updateState(slot)
342 def dlgClosed(self, slot):
345 def okbuttonClick(self):
346 cur = self["entries"].getCurrent()
347 if cur and len(cur) > 2:
350 if action == 0: #reset
351 eDVBCI_UI.getInstance().setReset(slot)
352 elif action == 1: #init
353 eDVBCI_UI.getInstance().setInit(slot)
354 elif self.state[slot] == 2:
355 self.dlg = self.session.openWithCallback(self.dlgClosed, CiMmi, slot, action)
358 CiHandler.unregisterCIMessageHandler(0)