7bd8aa9821dbae3e1cfe1694c3011aee1ad2ee0a
[enigma2.git] / 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
9 RT_HALIGN_LEFT = 0
10
11 TYPE_TEXT = 0
12 TYPE_VALUE_HEX = 1
13 TYPE_VALUE_DEC = 2
14 TYPE_VALUE_HEX_DEC = 3
15 TYPE_SLIDER = 4
16
17 def ServiceInfoListEntry(a, b, valueType=TYPE_TEXT, param=4):
18         res = [ ]
19
20         #PyObject *type, *px, *py, *pwidth, *pheight, *pfnt, *pstring, *pflags;
21         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 200, 30, 0, RT_HALIGN_LEFT, ""))
22         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 200, 25, 0, RT_HALIGN_LEFT, a))
23         print "b:", b
24         if type(b) is not str:
25                 if valueType == TYPE_VALUE_HEX:
26                         b = ("0x%0" + str(param) + "x") % b
27                 elif valueType == TYPE_VALUE_DEC:
28                         b = str(b)
29                 elif valueType == TYPE_VALUE_HEX_DEC:
30                         b = ("0x%0" + str(param) + "x (%dd)") % (b, b)
31                 else:
32                         b = str(b)
33         
34         res.append((eListboxPythonMultiContent.TYPE_TEXT, 220, 0, 350, 25, 0, RT_HALIGN_LEFT, b))
35
36         return res
37
38 class ServiceInfoList(HTMLComponent, GUIComponent):
39         def __init__(self, source):
40                 GUIComponent.__init__(self)
41                 self.l = eListboxPythonMultiContent()
42                 self.list = source
43                 self.l.setList(self.list)
44                 self.l.setFont(0, gFont("Regular", 23))
45                 self.l.setItemHeight(25)
46
47         GUI_WIDGET = eListbox
48
49         def postWidgetCreate(self, instance):
50                 self.instance.setContent(self.l)
51
52 TYPE_SERVICE_INFO = 1
53 TYPE_TRANSPONDER_INFO = 2
54
55 class ServiceInfo(Screen):
56         def __init__(self, session, serviceref=None):
57                 Screen.__init__(self, session)
58                 
59                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
60                 {
61                         "ok": self.close,
62                         "cancel": self.close,
63                         "red": self.information,
64                         "green": self.pids,
65                         "yellow": self.transponder,
66                         "blue": self.tuner
67                 }, -1)
68
69                 if serviceref:
70                         self.type = TYPE_TRANSPONDER_INFO
71                         self["red"] = Label()
72                         self["green"] = Label()
73                         self["yellow"] = Label()
74                         self["blue"] = Label()
75                         info = eServiceCenter.getInstance().info(serviceref)
76                         self.transponder_info = info.getInfoObject(serviceref, iServiceInformation.sTransponderData)
77                         # info is a iStaticServiceInformation, not a iServiceInformation
78                         self.info = None
79                         self.feinfo = None
80                 else:
81                         self.type = TYPE_SERVICE_INFO
82                         self["red"] = Label(_("Serviceinfo"))
83                         self["green"] = Label(_("PIDs"))
84                         self["yellow"] = Label(_("Transponder"))
85                         self["blue"] = Label(_("Tuner status"))
86                         service = session.nav.getCurrentService()
87                         if service is not None:
88                                 self.info = service.info()
89                                 self.feinfo = service.frontendInfo()
90                                 print self.info.getInfoObject(iServiceInformation.sCAIDs);
91                         else:
92                                 self.info = None
93                                 self.feinfo = None
94
95                 tlist = [ ]
96
97                 self["infolist"] = ServiceInfoList(tlist)
98                 self.onShown.append(self.information)
99
100         def information(self):
101                 if self.type == TYPE_SERVICE_INFO:
102                         if self.session.nav.getCurrentlyPlayingServiceReference():
103                                 name = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()).getServiceName()
104                                 refstr = self.session.nav.getCurrentlyPlayingServiceReference().toString()
105                         else:
106                                 name = "N/A"
107                                 refstr = "N/A"
108                         aspect = self.getServiceInfoValue(iServiceInformation.sAspect)
109                         if aspect in ( 1, 2, 5, 6, 9, 0xA, 0xD, 0xE ):
110                                 aspect = "4:3"
111                         else:
112                                 aspect = "16:9"
113                         width = self.info and self.info.getInfo(iServiceInformation.sVideoWidth) or -1
114                         height = self.info and self.info.getInfo(iServiceInformation.sVideoHeight) or -1
115                         if width != -1 and height != -1:
116                                 Labels = ( ("Name", name, TYPE_TEXT),
117                                                    ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
118                                                    ("Videoformat", aspect, TYPE_TEXT),
119                                                    ("Videosize", "%dx%d" %(width, height), TYPE_TEXT),
120                                                    ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8),
121                                                    ("Service Reference", refstr, TYPE_TEXT))
122                         else:
123                                 Labels = ( ("Name", name, TYPE_TEXT),
124                                                    ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
125                                                    ("Videoformat", aspect, TYPE_TEXT),
126                                                    ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8),
127                                                    ("Service Reference", refstr, TYPE_TEXT))
128                         self.fillList(Labels)
129                 else:
130                         if self.transponder_info:
131                                 conv = { "type"                         : _("Transponder Type"),
132                                                  "frequency"            : _("Frequency"),
133                                                  "symbolrate"           : _("Symbolrate"),
134                                                  "orbital position" : _("Orbital Position"),
135                                                  "inversion"            : _("Inversion"),
136                                                  "fec inner"            : _("FEC"),
137                                                  "modulation"           : _("Modulation"),
138                                                  "polarization"         : _("Polarization"),
139                                                  "roll off"                     : _("Rolloff"),
140                                                  "system"                       : _("System"),
141                                                  "bandwidth"            : _("Bandwidth"),
142                                                  "code rate lp"         : _("Coderate LP"),
143                                                  "code rate hp"         : _("Coderate HP"),
144                                                  "constellation"        : _("Constellation"),
145                                                  "transmission mode": _("Transmission Mode"),
146                                                  "guard interval"       : _("Guard Interval"),
147                                                  "hierarchy"            : _("Hierarchy Information") }
148                                 Labels = [ ]
149                                 for i in self.transponder_info.keys():
150                                         Labels.append( (conv[i], self.transponder_info[i], TYPE_TEXT) )
151                                 self.fillList(Labels)
152
153         def pids(self):
154                 if self.type == TYPE_SERVICE_INFO:
155                         Labels = ( ("VideoPID", self.getServiceInfoValue(iServiceInformation.sVideoPID), TYPE_VALUE_HEX_DEC, 4),
156                                            ("AudioPID", self.getServiceInfoValue(iServiceInformation.sAudioPID), TYPE_VALUE_HEX_DEC, 4),
157                                            ("PCRPID", self.getServiceInfoValue(iServiceInformation.sPCRPID), TYPE_VALUE_HEX_DEC, 4),
158                                            ("PMTPID", self.getServiceInfoValue(iServiceInformation.sPMTPID), TYPE_VALUE_HEX_DEC, 4),
159                                            ("TXTPID", self.getServiceInfoValue(iServiceInformation.sTXTPID), TYPE_VALUE_HEX_DEC, 4),
160                                            ("TSID", self.getServiceInfoValue(iServiceInformation.sTSID), TYPE_VALUE_HEX_DEC, 4),
161                                            ("ONID", self.getServiceInfoValue(iServiceInformation.sONID), TYPE_VALUE_HEX_DEC, 4),
162                                            ("SID", self.getServiceInfoValue(iServiceInformation.sSID), TYPE_VALUE_HEX_DEC, 4))
163                         self.fillList(Labels)
164         
165         def showFrontendData(self, real):
166                 if self.type == TYPE_SERVICE_INFO:
167                         frontendData = self.feinfo and self.feinfo.getAll(real)
168                         Labels = self.getFEData(frontendData)
169                         self.fillList(Labels)
170         
171         def transponder(self):
172                 if self.type == TYPE_SERVICE_INFO:
173                         self.showFrontendData(True)
174                 
175         def tuner(self):
176                 if self.type == TYPE_SERVICE_INFO:
177                         self.showFrontendData(False)
178
179         def getFEData(self, frontendData):
180                 if frontendData and len(frontendData):
181                         if frontendData["tuner_type"] == "DVB-S":
182                                 return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
183                                                         ("Type", frontendData["system"], TYPE_TEXT),
184                                                         ("Modulation", frontendData["modulation"], TYPE_TEXT),
185                                                         ("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
186                                                         ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
187                                                         ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
188                                                         ("Polarization", frontendData["polarization"], TYPE_TEXT),
189                                                         ("Inversion", frontendData["inversion"], TYPE_TEXT),
190                                                         ("FEC inner", frontendData["fec_inner"], TYPE_TEXT))
191                         elif frontendData["tuner_type"] == "DVB-C":
192                                 return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
193                                                 ("Type", frontendData["tuner_type"], TYPE_TEXT),
194                                                 ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
195                                                 ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
196                                                 ("Modulation", frontendData["modulation"], TYPE_TEXT),
197                                                 ("Inversion", frontendData["inversion"], TYPE_TEXT),
198                                                 ("FEC inner", frontendData["fec_inner"], TYPE_TEXT))
199                         elif frontendData["tuner_type"] == "DVB-T":
200                                 return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
201                                                 ("Type", frontendData["tuner_type"], TYPE_TEXT),
202                                                 ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
203                                                 ("Inversion", frontendData["inversion"], TYPE_TEXT),
204                                                 ("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
205                                                 ("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
206                                                 ("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
207                                                 ("Constellation", frontendData["constellation"], TYPE_TEXT),
208                                                 ("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
209                                                 ("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
210                                                 ("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT))
211                 return [ ]
212
213         def fillList(self, Labels):
214                 tlist = [ ]
215
216                 for item in Labels:
217                         value = item[1]
218                         if len(item) < 4:
219                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2]))
220                         else:
221                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2], item[3]))
222
223                 self["infolist"].l.setList(tlist)
224
225         def getServiceInfoValue(self, what):
226                 if self.info is None:
227                         return ""
228                 
229                 v = self.info.getInfo(what)
230                 if v == -2:
231                         v = self.info.getInfoString(what)
232                 elif v == -1:
233                         v = "N/A"
234
235                 return v