[RecordTimer] fix repeat timer issue.
[vuplus_dvbapp] / lib / python / Screens / ServiceInfo.py
1 from Components.HTMLComponent import HTMLComponent
2 from Components.GUIComponent import GUIComponent
3 from Screen import Screen
4 from Components.ActionMap import ActionMap
5 from Components.Label import Label
6 from ServiceReference import ServiceReference
7 from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation, eServiceCenter
8 from Tools.Transponder import ConvertToHumanReadable
9 from Components.NimManager import nimmanager
10 import skin
11
12 RT_HALIGN_LEFT = 0
13
14 TYPE_TEXT = 0
15 TYPE_VALUE_HEX = 1
16 TYPE_VALUE_DEC = 2
17 TYPE_VALUE_HEX_DEC = 3
18 TYPE_SLIDER = 4
19
20 def to_unsigned(x):
21         return x & 0xFFFFFFFF
22
23 def ServiceInfoListEntry(a, b, valueType=TYPE_TEXT, param=4):
24         print "b:", b
25         if not isinstance(b, str):
26                 if valueType == TYPE_VALUE_HEX:
27                         b = ("0x%0" + str(param) + "x") % to_unsigned(b)
28                 elif valueType == TYPE_VALUE_DEC:
29                         b = str(b)
30                 elif valueType == TYPE_VALUE_HEX_DEC:
31                         b = ("0x%0" + str(param) + "x (%dd)") % (to_unsigned(b), b)
32                 else:
33                         b = str(b)
34
35         x, y, w, h = skin.parameters.get("ServiceInfo",(0, 0, 200, 30))
36         xa, ya, wa, ha = skin.parameters.get("ServiceInfoLeft",(0, 0, 200, 25))
37         xb, yb, wb, hb = skin.parameters.get("ServiceInfoRight",(220, 0, 350, 25))
38         return [
39                 #PyObject *type, *px, *py, *pwidth, *pheight, *pfnt, *pstring, *pflags;
40                 (eListboxPythonMultiContent.TYPE_TEXT, x, y, w, h, 0, RT_HALIGN_LEFT, ""),
41                 (eListboxPythonMultiContent.TYPE_TEXT, xa, ya, wa, ha, 0, RT_HALIGN_LEFT, a),
42                 (eListboxPythonMultiContent.TYPE_TEXT, xb, yb, wb, hb, 0, RT_HALIGN_LEFT, b)
43         ]
44
45 class ServiceInfoList(HTMLComponent, GUIComponent):
46         def __init__(self, source):
47                 GUIComponent.__init__(self)
48                 self.l = eListboxPythonMultiContent()
49                 self.list = source
50                 self.l.setList(self.list)
51                 font = skin.fonts.get("ServiceInfo", ("Regular", 23, 25))
52                 self.l.setFont(0, gFont(font[0], font[1]))
53                 self.l.setItemHeight(font[2])
54
55         GUI_WIDGET = eListbox
56
57         def postWidgetCreate(self, instance):
58                 self.instance.setContent(self.l)
59
60 TYPE_SERVICE_INFO = 1
61 TYPE_TRANSPONDER_INFO = 2
62
63 class ServiceInfo(Screen):
64         def __init__(self, session, serviceref=None):
65                 Screen.__init__(self, session)
66                 
67                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
68                 {
69                         "ok": self.close,
70                         "cancel": self.close,
71                         "red": self.information,
72                         "green": self.pids,
73                         "yellow": self.transponder,
74                         "blue": self.tuner
75                 }, -1)
76
77                 if serviceref:
78                         self.type = TYPE_TRANSPONDER_INFO
79                         self["red"] = Label()
80                         self["green"] = Label()
81                         self["yellow"] = Label()
82                         self["blue"] = Label()
83                         info = eServiceCenter.getInstance().info(serviceref)
84                         self.transponder_info = info.getInfoObject(serviceref, iServiceInformation.sTransponderData)
85                         # info is a iStaticServiceInformation, not a iServiceInformation
86                         self.info = None
87                         self.feinfo = None
88                 else:
89                         self.type = TYPE_SERVICE_INFO
90                         self["red"] = Label(_("Service"))
91                         self["green"] = Label(_("PIDs"))
92                         self["yellow"] = Label(_("Multiplex"))
93                         self["blue"] = Label(_("Tuner status"))
94                         service = session.nav.getCurrentService()
95                         if service is not None:
96                                 self.info = service.info()
97                                 self.feinfo = service.frontendInfo()
98                                 print self.info.getInfoObject(iServiceInformation.sCAIDs);
99                         else:
100                                 self.info = None
101                                 self.feinfo = None
102
103                 tlist = [ ]
104
105                 self["infolist"] = ServiceInfoList(tlist)
106                 self.onShown.append(self.information)
107
108         def information(self):
109                 if self.type == TYPE_SERVICE_INFO:
110                         if self.session.nav.getCurrentlyPlayingServiceReference():
111                                 name = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()).getServiceName()
112                                 refstr = self.session.nav.getCurrentlyPlayingServiceReference().toString()
113                         else:
114                                 name = _("N/A")
115                                 refstr = _("N/A")
116                         aspect = self.getServiceInfoValue(iServiceInformation.sAspect)
117                         if aspect in ( 1, 2, 5, 6, 9, 0xA, 0xD, 0xE ):
118                                 aspect = _("4:3")
119                         else:
120                                 aspect = _("16:9")
121                         width = self.info and self.info.getInfo(iServiceInformation.sVideoWidth) or -1
122                         height = self.info and self.info.getInfo(iServiceInformation.sVideoHeight) or -1
123                         if width != -1 and height != -1:
124                                 Labels = ( (_("Name"), name, TYPE_TEXT),
125                                                    (_("Provider"), self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
126                                                    (_("Aspect ratio"), aspect, TYPE_TEXT),
127                                                    (_("Resolution"), "%dx%d" %(width, height), TYPE_TEXT),
128                                                    (_("Namespace"), self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8),
129                                                    (_("Service reference"), refstr, TYPE_TEXT))
130                         else:
131                                 Labels = ( (_("Name"), name, TYPE_TEXT),
132                                                    (_("Provider"), self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
133                                                    (_("Aspect ratio"), aspect, TYPE_TEXT),
134                                                    (_("Namespace"), self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8),
135                                                    (_("Service reference"), refstr, TYPE_TEXT))
136                         self.fillList(Labels)
137                 else:
138                         if self.transponder_info:
139                                 tp_info = ConvertToHumanReadable(self.transponder_info)
140                                 conv = { "tuner_type"                   : _("Type"),
141                                          "system"                       : _("System"),
142                                          "modulation"                   : _("Modulation"),
143                                          "orbital_position"             : _("Orbital position"),
144                                          "frequency"                    : _("Frequency"),
145                                          "symbol_rate"                  : _("Symbol rate"),
146                                          "bandwidth"                    : _("Bandwidth"),
147                                          "polarization"                 : _("Polarization"),
148                                          "inversion"                    : _("Inversion"),
149                                          "pilot"                        : _("Pilot"),
150                                          "rolloff"                      : _("Roll-off"),
151                                          "fec_inner"                    : _("FEC"),
152                                          "code_rate_lp"                 : _("Code rate LP"),
153                                          "code_rate_hp"                 : _("Code rate HP"),
154                                          "constellation"                : _("Constellation"),
155                                          "transmission_mode"            : _("Transmission mode"),
156                                          "guard_interval"               : _("Guard interval"),
157                                          "hierarchy_information"        : _("Hierarchy info"),
158                                          "plp_id"                       : _("PLP ID"),
159                                          "is_id"                        : _("Input Stream ID"),
160                                          "pls_mode"                     : _("PLS Mode"),
161                                          "pls_code"                     : _("PLS Code")}
162                                 Labels = [(conv[i], tp_info[i], TYPE_VALUE_DEC) for i in tp_info.keys()]
163                                 self.fillList(Labels)
164
165         def pids(self):
166                 if self.type == TYPE_SERVICE_INFO:
167                         Labels = ( (_("Video PID"), self.getServiceInfoValue(iServiceInformation.sVideoPID), TYPE_VALUE_HEX_DEC, 4),
168                                            (_("Audio PID"), self.getServiceInfoValue(iServiceInformation.sAudioPID), TYPE_VALUE_HEX_DEC, 4),
169                                            (_("PCR PID"), self.getServiceInfoValue(iServiceInformation.sPCRPID), TYPE_VALUE_HEX_DEC, 4),
170                                            (_("PMT PID"), self.getServiceInfoValue(iServiceInformation.sPMTPID), TYPE_VALUE_HEX_DEC, 4),
171                                            (_("TXT PID"), self.getServiceInfoValue(iServiceInformation.sTXTPID), TYPE_VALUE_HEX_DEC, 4),
172                                            (_("TSID"), self.getServiceInfoValue(iServiceInformation.sTSID), TYPE_VALUE_HEX_DEC, 4),
173                                            (_("ONID"), self.getServiceInfoValue(iServiceInformation.sONID), TYPE_VALUE_HEX_DEC, 4),
174                                            (_("SID"), self.getServiceInfoValue(iServiceInformation.sSID), TYPE_VALUE_HEX_DEC, 4))
175                         self.fillList(Labels)
176         
177         def showFrontendData(self, real):
178                 if self.type == TYPE_SERVICE_INFO:
179                         frontendData = self.feinfo and self.feinfo.getAll(real)
180                         Labels = self.getFEData(frontendData)
181                         self.fillList(Labels)
182         
183         def transponder(self):
184                 if self.type == TYPE_SERVICE_INFO:
185                         self.showFrontendData(True)
186                 
187         def tuner(self):
188                 if self.type == TYPE_SERVICE_INFO:
189                         self.showFrontendData(False)
190
191         def getFEData(self, frontendDataOrg):
192                 if frontendDataOrg and len(frontendDataOrg):
193                         frontendData = ConvertToHumanReadable(frontendDataOrg)
194                         if frontendDataOrg["tuner_type"] == "DVB-S":
195                                 data = ((_("NIM"), chr(ord('A')+int(frontendData["tuner_number"])), TYPE_TEXT),
196                                                 (_("Type"), frontendData["tuner_type"], TYPE_TEXT),
197                                                 (_("System"), frontendData["system"], TYPE_TEXT),
198                                                 (_("Modulation"), frontendData["modulation"], TYPE_TEXT),
199                                                 (_("Orbital position"), frontendData["orbital_position"], TYPE_VALUE_DEC),
200                                                 (_("Frequency"), frontendData["frequency"], TYPE_VALUE_DEC),
201                                                 (_("Symbol rate"), frontendData["symbol_rate"], TYPE_VALUE_DEC),
202                                                 (_("Polarization"), frontendData["polarization"], TYPE_TEXT),
203                                                 (_("Inversion"), frontendData["inversion"], TYPE_TEXT),
204                                                 (_("FEC"), frontendData["fec_inner"], TYPE_TEXT),
205                                                 (_("Pilot"), frontendData.get("pilot", None), TYPE_TEXT),
206                                                 (_("Roll-off"), frontendData.get("rolloff", None), TYPE_TEXT))
207                                 if nimmanager.isSupportMultistream(int(frontendData["tuner_number"])):
208                                         data += ((_("Input Stream ID"), frontendData.get("is_id", 0), TYPE_VALUE_DEC),
209                                                 (_("PLS Mode"), frontendData.get("pls_mode", None), TYPE_TEXT),
210                                                 (_("PLS Code"), frontendData.get("pls_code", 0), TYPE_VALUE_DEC))
211                                 return data
212                         elif frontendDataOrg["tuner_type"] == "DVB-C":
213                                 return ((_("NIM"), chr(ord('A')+int(frontendData["tuner_number"])), TYPE_TEXT),
214                                                 (_("Type"), frontendData["tuner_type"], TYPE_TEXT),
215                                                 (_("Modulation"), frontendData["modulation"], TYPE_TEXT),
216                                                 (_("Frequency"), frontendData["frequency"], TYPE_VALUE_DEC),
217                                                 (_("Symbol rate"), frontendData["symbol_rate"], TYPE_VALUE_DEC),
218                                                 (_("Inversion"), frontendData["inversion"], TYPE_TEXT),
219                                                 (_("FEC"), frontendData["fec_inner"], TYPE_TEXT))
220                         elif frontendDataOrg["tuner_type"] == "DVB-T":
221                                 data = ((_("NIM"), chr(ord('A')+int(frontendData["tuner_number"])), TYPE_TEXT),
222                                                 (_("Type"), frontendData["tuner_type"], TYPE_TEXT),
223                                                 (_("System"), frontendData["system"], TYPE_TEXT),
224                                                 (_("Frequency"), frontendData["frequency"], TYPE_VALUE_DEC),
225                                                 (_("Inversion"), frontendData["inversion"], TYPE_TEXT),
226                                                 (_("Bandwidth"), frontendData["bandwidth"], TYPE_VALUE_DEC),
227                                                 (_("Code rate LP"), frontendData["code_rate_lp"], TYPE_TEXT),
228                                                 (_("Code rate HP"), frontendData["code_rate_hp"], TYPE_TEXT),
229                                                 (_("Constellation"), frontendData["constellation"], TYPE_TEXT),
230                                                 (_("Transmission mode"), frontendData["transmission_mode"], TYPE_TEXT),
231                                                 (_("Guard interval"), frontendData["guard_interval"], TYPE_TEXT),
232                                                 (_("Hierarchy info"), frontendData["hierarchy_information"], TYPE_TEXT))
233                                 if frontendData.has_key("plp_id"):
234                                         data += ((_("PLP ID"), frontendData["plp_id"], TYPE_VALUE_DEC), )
235                                 return data
236
237                 return [ ]
238
239         def fillList(self, Labels):
240                 tlist = [ ]
241
242                 for item in Labels:
243                         if item[1] is None:
244                                 continue;
245                         value = item[1]
246                         if len(item) < 4:
247                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2]))
248                         else:
249                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2], item[3]))
250
251                 self["infolist"].l.setList(tlist)
252
253         def getServiceInfoValue(self, what):
254                 if self.info is None:
255                         return ""
256                 
257                 v = self.info.getInfo(what)
258                 if v == -2:
259                         v = self.info.getInfoString(what)
260                 elif v == -1:
261                         v = _("N/A")
262
263                 return v