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