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