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.config import config, ConfigSubsection, ConfigSelection, ConfigSubList, getConfigListEntry, KEY_LEFT, KEY_RIGHT, KEY_0, ConfigNothing, ConfigPIN
10 from Components.ConfigList import ConfigList
12 from enigma import eTimer, eDVBCI_UI, eListboxPythonStringContent, eListboxPythonConfigContent
17 config.ci = ConfigSubList()
18 for slot in range(MAX_NUM_CI):
19 config.ci.append(ConfigSubsection())
20 config.ci[slot].canDescrambleMultipleServices = ConfigSelection(choices = [("auto", _("Auto")), ("no", _("No")), ("yes", _("Yes"))], default = "auto")
23 def __init__(self, session, slotid, action):
24 Screen.__init__(self, session)
26 print "ciMMI with action" + str(action)
32 self.timer.timeout.get().append(self.keyCancel)
35 self["title"] = Label("")
36 self["subtitle"] = Label("")
37 self["bottom"] = Label("")
38 self["entries"] = ConfigList([ ])
40 self["actions"] = NumberActionMap(["SetupActions"],
42 "ok": self.okbuttonClick,
43 "cancel": self.keyCancel,
46 "right": self.keyRight,
47 "1": self.keyNumberGlobal,
48 "2": self.keyNumberGlobal,
49 "3": self.keyNumberGlobal,
50 "4": self.keyNumberGlobal,
51 "5": self.keyNumberGlobal,
52 "6": self.keyNumberGlobal,
53 "7": self.keyNumberGlobal,
54 "8": self.keyNumberGlobal,
55 "9": self.keyNumberGlobal,
56 "0": self.keyNumberGlobal
61 if action == 2: #start MMI
62 eDVBCI_UI.getInstance().startMMI(self.slotid)
64 elif action == 3: #mmi already there (called from infobar)
67 def addEntry(self, list, entry):
68 if entry[0] == "TEXT": #handle every item (text / pin only?)
69 list.append( (entry[1], ConfigNothing(), entry[2]) )
74 x = ConfigPIN(0, len = pinlength, censor = "*")
77 x = ConfigPIN(0, len = pinlength)
78 self["subtitle"].setText(entry[2])
79 list.append( getConfigListEntry("", x) )
80 self["bottom"].setText(_("please press OK when ready"))
82 def okbuttonClick(self):
86 if self.tag == "WAIT":
87 print "do nothing - wait"
88 elif self.tag == "MENU":
90 cur = self["entries"].getCurrent()
92 eDVBCI_UI.getInstance().answerMenu(self.slotid, cur[2])
94 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
96 elif self.tag == "LIST":
98 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
100 elif self.tag == "ENQ":
101 cur = self["entries"].getCurrent()
102 answer = str(cur[1].value)
104 while length < cur[1].getLength():
107 eDVBCI_UI.getInstance().answerEnq(self.slotid, answer)
112 self.close(self.slotid)
118 if self.tag == "WAIT":
119 eDVBCI_UI.getInstance().stopMMI(self.slotid)
121 elif self.tag in [ "MENU", "LIST" ]:
123 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
125 elif self.tag == "ENQ":
127 eDVBCI_UI.getInstance().cancelEnq(self.slotid)
130 print "give cancel action to ci"
132 def keyConfigEntry(self, key):
135 self["entries"].handleKey(key)
139 def keyNumberGlobal(self, number):
141 self.keyConfigEntry(KEY_0 + number)
145 self.keyConfigEntry(KEY_LEFT)
149 self.keyConfigEntry(KEY_RIGHT)
151 def updateList(self, list):
152 List = self["entries"]
154 List.instance.moveSelectionTo(0)
161 self["title"].setText("")
162 self["subtitle"].setText("")
163 self["bottom"].setText("")
165 list.append( (_("wait for ci..."), ConfigNothing()) )
166 self.updateList(list)
168 def showScreen(self):
169 screen = eDVBCI_UI.getInstance().getMMIScreen(self.slotid)
174 if len(screen) > 0 and screen[0][0] == "CLOSE":
175 timeout = screen[0][1]
177 self.timer.start(timeout*1000, True)
181 self.tag = screen[0][0]
183 if entry[0] == "PIN":
184 self.addEntry(list, entry)
186 if entry[0] == "TITLE":
187 self["title"].setText(entry[1])
188 elif entry[0] == "SUBTITLE":
189 self["subtitle"].setText(entry[1])
190 elif entry[0] == "BOTTOM":
191 self["bottom"].setText(entry[1])
192 elif entry[0] == "TEXT":
193 self.addEntry(list, entry)
194 self.updateList(list)
196 def ciStateChanged(self):
197 if self.action == 0: #reset
199 if self.action == 1: #init
202 #module still there ?
203 if eDVBCI_UI.getInstance().getState(self.slotid) != 2:
206 #mmi session still active ?
207 if eDVBCI_UI.getInstance().getMMIState(self.slotid) != 1:
210 if self.action > 1 and eDVBCI_UI.getInstance().availableMMI(self.slotid) == 1:
213 #FIXME: check for mmi-session closed
215 class CiMessageHandler:
220 eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged)
222 def setSession(self, session):
223 self.session = session
225 def ciStateChanged(self, slot):
229 if slot in self.dlgs:
230 self.dlgs[slot].ciStateChanged()
231 elif eDVBCI_UI.getInstance().availableMMI(slot) == 1:
233 self.dlgs[slot] = self.session.openWithCallback(self.dlgClosed, CiMmi, slot, 3)
237 def dlgClosed(self, slot):
240 def registerCIMessageHandler(self, slot, func):
241 self.unregisterCIMessageHandler(slot)
244 def unregisterCIMessageHandler(self, slot):
248 CiHandler = CiMessageHandler()
250 class CiSelection(Screen):
251 def __init__(self, session):
252 Screen.__init__(self, session)
254 self["actions"] = ActionMap(["OkCancelActions", "CiSelectionActions"],
256 "left": self.keyLeft,
257 "right": self.keyLeft,
258 "ok": self.okbuttonClick,
259 "cancel": self.cancel
266 for slot in range(MAX_NUM_CI):
267 state = eDVBCI_UI.getInstance().getState(slot)
269 self.appendEntries(slot, state)
270 CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
272 menuList = ConfigList(self.list)
273 menuList.list = self.list
274 menuList.l.setList(self.list)
275 self["entries"] = menuList
276 self["entries"].onSelectionChanged.append(self.selectionChanged)
277 self["text"] = Label(_("Slot %d")%(1))
279 def selectionChanged(self):
280 cur_idx = self["entries"].getCurrentIndex()
281 self["text"].setText(_("Slot %d")%((cur_idx / 4)+1))
283 def keyConfigEntry(self, key):
285 self["entries"].handleKey(key)
286 self["entries"].getCurrent()[1].save()
291 self.keyConfigEntry(KEY_LEFT)
294 self.keyConfigEntry(KEY_RIGHT)
296 def appendEntries(self, slot, state):
297 self.state[slot] = state
298 self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
299 self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
301 if self.state[slot] == 0: #no module
302 self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
303 elif self.state[slot] == 1: #module in init
304 self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
305 elif self.state[slot] == 2: #module ready
307 appname = eDVBCI_UI.getInstance().getAppName(slot)
308 self.list.append( (appname, ConfigNothing(), 2, slot) )
310 self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
312 def updateState(self, slot):
313 state = eDVBCI_UI.getInstance().getState(slot)
314 self.state[slot] = state
317 while len(self.list[slotidx]) < 3 or self.list[slotidx][3] != slot:
320 slotidx += 1 # do not change Reset
321 slotidx += 1 # do not change Init
323 if state == 0: #no module
324 self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
325 elif state == 1: #module in init
326 self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
327 elif state == 2: #module ready
329 appname = eDVBCI_UI.getInstance().getAppName(slot)
330 self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
332 lst = self["entries"]
334 lst.l.setList(self.list)
336 def ciStateChanged(self, slot):
338 self.dlg.ciStateChanged()
340 state = eDVBCI_UI.getInstance().getState(slot)
341 if self.state[slot] != state:
342 #print "something happens"
343 self.state[slot] = state
344 self.updateState(slot)
346 def dlgClosed(self, slot):
349 def okbuttonClick(self):
350 cur = self["entries"].getCurrent()
351 if cur and len(cur) > 2:
354 if action == 0: #reset
355 eDVBCI_UI.getInstance().setReset(slot)
356 elif action == 1: #init
357 eDVBCI_UI.getInstance().setInit(slot)
358 elif self.state[slot] == 2:
359 self.dlg = self.session.openWithCallback(self.dlgClosed, CiMmi, slot, action)
362 CiHandler.unregisterCIMessageHandler(0)