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