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
12 from Components.ConfigList import ConfigList
14 from enigma import eTimer, eDVBCI_UI, eListboxPythonStringContent, eListboxPythonConfigContent
21 config.ci = ConfigSubList()
22 for slot in range(MAX_NUM_CI):
23 config.ci.append(ConfigSubsection())
24 config.ci[slot].canDescrambleMultipleServices = ConfigSelection(choices = [("auto", _("Auto")), ("no", _("No")), ("yes", _("Yes"))], default = "auto")
27 def __init__(self, session, slotid, action):
28 Screen.__init__(self, session)
30 print "ciMMI with action" + str(action)
36 self.timer.timeout.get().append(self.keyCancel)
39 self["title"] = Label("")
40 self["subtitle"] = Label("")
41 self["bottom"] = Label("")
42 self["entries"] = ConfigList([ ])
43 self.listtype = TYPE_CONFIG
45 self["actions"] = NumberActionMap(["SetupActions"],
47 "ok": self.okbuttonClick,
48 "cancel": self.keyCancel,
51 "right": self.keyRight,
52 "1": self.keyNumberGlobal,
53 "2": self.keyNumberGlobal,
54 "3": self.keyNumberGlobal,
55 "4": self.keyNumberGlobal,
56 "5": self.keyNumberGlobal,
57 "6": self.keyNumberGlobal,
58 "7": self.keyNumberGlobal,
59 "8": self.keyNumberGlobal,
60 "9": self.keyNumberGlobal,
61 "0": self.keyNumberGlobal
66 if action == 2: #start MMI
67 eDVBCI_UI.getInstance().startMMI(self.slotid)
69 elif action == 3: #mmi already there (called from infobar)
72 def addEntry(self, list, entry):
73 if entry[0] == "TEXT": #handle every item (text / pin only?)
74 list.append( (entry[1], entry[2]) )
76 self.pinlength = entry[1]
79 x = ConfigPIN(len = self.pinlength, censor = "*")
82 x = ConfigPIN(len = self.pinlength)
83 self["subtitle"].setText(entry[2])
84 self.pin = getConfigListEntry("", x)
85 list.append( self.pin )
86 self["bottom"].setText(_("please press OK when ready"))
88 def okbuttonClick(self):
92 if self.tag == "WAIT":
93 print "do nothing - wait"
94 elif self.tag == "MENU":
96 cur = self["entries"].getCurrent()
98 eDVBCI_UI.getInstance().answerMenu(self.slotid, cur[1])
100 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
102 elif self.tag == "LIST":
104 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
106 elif self.tag == "ENQ":
107 answer = str(self.pin[1].parent.value[0])
109 while length < self.pinlength:
112 eDVBCI_UI.getInstance().answerEnq(self.slotid, answer)
117 self.close(self.slotid)
123 if self.tag == "WAIT":
124 eDVBCI_UI.getInstance().stopMMI(self.slotid)
126 elif self.tag in [ "MENU", "LIST" ]:
128 eDVBCI_UI.getInstance().answerMenu(self.slotid, 0)
130 elif self.tag == "ENQ":
132 eDVBCI_UI.getInstance().cancelEnq(self.slotid)
135 print "give cancel action to ci"
137 def keyConfigEntry(self, key):
140 self["entries"].handleKey(key)
144 def keyNumberGlobal(self, number):
146 self.keyConfigEntry(KEY_0 + number)
150 self.keyConfigEntry(KEY_LEFT)
154 self.keyConfigEntry(KEY_RIGHT)
156 def updateList(self, list):
157 List = self["entries"]
159 List.instance.moveSelectionTo(0)
164 if self.tag and self.tag == "ENQ":
169 if type != self.listtype:
170 if type == TYPE_CONFIG:
171 List.l = eListboxPythonConfigContent()
173 List.l = eListboxPythonStringContent()
174 List.instance.setContent(List.l)
181 self["title"].setText("")
182 self["subtitle"].setText("")
183 self["bottom"].setText("")
185 list.append( ("wait for ci...", 0) )
186 self.updateList(list)
188 def showScreen(self):
189 screen = eDVBCI_UI.getInstance().getMMIScreen(self.slotid)
194 if len(screen) > 0 and screen[0][0] == "CLOSE":
195 timeout = screen[0][1]
197 self.timer.start(timeout*1000, True)
201 self.tag = screen[0][0]
203 if entry[0] == "PIN":
204 self.addEntry(list, entry)
206 if entry[0] == "TITLE":
207 self["title"].setText(entry[1])
208 elif entry[0] == "SUBTITLE":
209 self["subtitle"].setText(entry[1])
210 elif entry[0] == "BOTTOM":
211 self["bottom"].setText(entry[1])
212 elif entry[0] == "TEXT":
213 self.addEntry(list, entry)
214 self.updateList(list)
216 def ciStateChanged(self):
217 if self.action == 0: #reset
219 if self.action == 1: #init
222 #module still there ?
223 if eDVBCI_UI.getInstance().getState(self.slotid) != 2:
226 #mmi session still active ?
227 if eDVBCI_UI.getInstance().getMMIState(self.slotid) != 1:
230 if self.action > 1 and eDVBCI_UI.getInstance().availableMMI(self.slotid) == 1:
233 #FIXME: check for mmi-session closed
235 class CiMessageHandler:
240 eDVBCI_UI.getInstance().ciStateChanged.get().append(self.ciStateChanged)
242 def setSession(self, session):
243 self.session = session
245 def ciStateChanged(self, slot):
249 if slot in self.dlgs:
250 self.dlgs[slot].ciStateChanged()
251 elif eDVBCI_UI.getInstance().availableMMI(slot) == 1:
253 self.dlgs[slot] = self.session.openWithCallback(self.dlgClosed, CiMmi, slot, 3)
257 def dlgClosed(self, slot):
260 def registerCIMessageHandler(self, slot, func):
261 self.unregisterCIMessageHandler(slot)
264 def unregisterCIMessageHandler(self, slot):
268 CiHandler = CiMessageHandler()
270 class CiSelection(Screen):
271 def __init__(self, session):
272 Screen.__init__(self, session)
274 self["actions"] = ActionMap(["OkCancelActions", "CiSelectionActions"],
276 "left": self.keyLeft,
277 "right": self.keyLeft,
278 "ok": self.okbuttonClick,
279 "cancel": self.cancel
286 for slot in range(MAX_NUM_CI):
287 state = eDVBCI_UI.getInstance().getState(slot)
289 self.appendEntries(slot, state)
290 CiHandler.registerCIMessageHandler(slot, self.ciStateChanged)
292 menuList = ConfigList(self.list)
293 menuList.list = self.list
294 menuList.l.setList(self.list)
295 self["entries"] = menuList
297 def keyConfigEntry(self, key):
299 self["entries"].handleKey(key)
300 self["entries"].getCurrent()[1].save()
305 self.keyConfigEntry(KEY_LEFT)
308 self.keyConfigEntry(KEY_RIGHT)
310 def appendEntries(self, slot, state):
311 self.state[slot] = state
312 self.list.append( (_("Reset"), ConfigNothing(), 0, slot) )
313 self.list.append( (_("Init"), ConfigNothing(), 1, slot) )
315 if self.state[slot] == 0: #no module
316 self.list.append( (_("no module found"), ConfigNothing(), 2, slot) )
317 elif self.state[slot] == 1: #module in init
318 self.list.append( (_("init module"), ConfigNothing(), 2, slot) )
319 elif self.state[slot] == 2: #module ready
321 appname = eDVBCI_UI.getInstance().getAppName(slot)
322 self.list.append( (appname, ConfigNothing(), 2, slot) )
324 self.list.append(getConfigListEntry(_("Multiple service support"), config.ci[slot].canDescrambleMultipleServices))
326 def updateState(self, slot):
327 state = eDVBCI_UI.getInstance().getState(slot)
328 self.state[slot] = state
331 while self.list[slotidx][2] != slot:
334 slotidx += 1 # do not change Reset
335 slotidx += 1 # do not change Init
337 if state == 0: #no module
338 self.list[slotidx] = (_("no module found"), ConfigNothing(), 2, slot)
339 elif state == 1: #module in init
340 self.list[slotidx] = (_("init module"), ConfigNothing(), 2, slot)
341 elif state == 2: #module ready
343 appname = eDVBCI_UI.getInstance().getAppName(slot)
344 self.list[slotidx] = (appname, ConfigNothing(), 2, slot)
346 lst = self["entries"]
348 lst.l.setList(self.list)
350 def ciStateChanged(self, slot):
352 self.dlg.ciStateChanged()
354 state = eDVBCI_UI.getInstance().getState(slot)
355 if self.state[slot] != state:
356 #print "something happens"
357 self.state[slot] = state
358 self.updateState(slot)
360 def dlgClosed(self, slot):
363 def okbuttonClick(self):
364 cur = self["entries"].getCurrent()
365 if cur and len(cur) > 2:
368 if action == 0: #reset
369 eDVBCI_UI.getInstance().setReset(slot)
370 elif action == 1: #init
371 eDVBCI_UI.getInstance().setInit(slot)
372 elif self.state[slot] == 2:
373 self.dlg = self.session.openWithCallback(self.dlgClosed, CiMmi, slot, action)
376 CiHandler.unregisterCIMessageHandler(0)