commit missing code for pixmaps in mainmenu
[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                         else:
105                                 name = "N/A"
106                         aspect = self.getServiceInfoValue(iServiceInformation.sAspect)
107                         if aspect in ( 1, 2, 5, 6, 9, 0xA, 0xD, 0xE ):
108                                 aspect = "4:3"
109                         else:
110                                 aspect = "16:9"
111                         width = self.info and self.info.getInfo(iServiceInformation.sVideoWidth) or -1
112                         height = self.info and self.info.getInfo(iServiceInformation.sVideoHeight) or -1
113                         if width != -1 and height != -1:
114                                 Labels = ( ("Name", name, TYPE_TEXT),
115                                                    ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
116                                                    ("Videoformat", aspect, TYPE_TEXT),
117                                                    ("Videosize", "%dx%d" %(width, height), TYPE_TEXT),
118                                                    ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8))
119                         else:
120                                 Labels = ( ("Name", name, TYPE_TEXT),
121                                                    ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
122                                                    ("Videoformat", aspect, TYPE_TEXT),
123                                                    ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8))
124                         self.fillList(Labels)
125                 else:
126                         if self.transponder_info:
127                                 conv = { "type"                         : _("Transponder Type"),
128                                                  "frequency"            : _("Frequency"),
129                                                  "symbolrate"           : _("Symbolrate"),
130                                                  "orbital position" : _("Orbital Position"),
131                                                  "inversion"            : _("Inversion"),
132                                                  "fec inner"            : _("FEC"),
133                                                  "modulation"           : _("Modulation"),
134                                                  "polarization"         : _("Polarization"),
135                                                  "roll off"                     : _("Rolloff"),
136                                                  "system"                       : _("System"),
137                                                  "bandwidth"            : _("Bandwidth"),
138                                                  "code rate lp"         : _("Coderate LP"),
139                                                  "code rate hp"         : _("Coderate HP"),
140                                                  "constellation"        : _("Constellation"),
141                                                  "transmission mode": _("Transmission Mode"),
142                                                  "guard interval"       : _("Guard Interval"),
143                                                  "hierarchy"            : _("Hierarchy Information") }
144                                 Labels = [ ]
145                                 for i in self.transponder_info.keys():
146                                         Labels.append( (conv[i], self.transponder_info[i], TYPE_TEXT) )
147                                 self.fillList(Labels)
148
149         def pids(self):
150                 if self.type == TYPE_SERVICE_INFO:
151                         Labels = ( ("VideoPID", self.getServiceInfoValue(iServiceInformation.sVideoPID), TYPE_VALUE_HEX_DEC, 4),
152                                            ("AudioPID", self.getServiceInfoValue(iServiceInformation.sAudioPID), TYPE_VALUE_HEX_DEC, 4),
153                                            ("PCRPID", self.getServiceInfoValue(iServiceInformation.sPCRPID), TYPE_VALUE_HEX_DEC, 4),
154                                            ("PMTPID", self.getServiceInfoValue(iServiceInformation.sPMTPID), TYPE_VALUE_HEX_DEC, 4),
155                                            ("TXTPID", self.getServiceInfoValue(iServiceInformation.sTXTPID), TYPE_VALUE_HEX_DEC, 4),
156                                            ("TSID", self.getServiceInfoValue(iServiceInformation.sTSID), TYPE_VALUE_HEX_DEC, 4),
157                                            ("ONID", self.getServiceInfoValue(iServiceInformation.sONID), TYPE_VALUE_HEX_DEC, 4),
158                                            ("SID", self.getServiceInfoValue(iServiceInformation.sSID), TYPE_VALUE_HEX_DEC, 4))
159                         self.fillList(Labels)
160         
161         def showFrontendData(self, real):
162                 if self.type == TYPE_SERVICE_INFO:
163                         frontendData = self.feinfo and self.feinfo.getAll(real)
164                         Labels = self.getFEData(frontendData)
165                         self.fillList(Labels)
166         
167         def transponder(self):
168                 if self.type == TYPE_SERVICE_INFO:
169                         self.showFrontendData(True)
170                 
171         def tuner(self):
172                 if self.type == TYPE_SERVICE_INFO:
173                         self.showFrontendData(False)
174
175         def getFEData(self, frontendData):
176                 if frontendData and len(frontendData):
177                         if frontendData["tuner_type"] == "DVB-S":
178                                 return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
179                                                         ("Type", frontendData["system"], TYPE_TEXT),
180                                                         ("Modulation", frontendData["modulation"], TYPE_TEXT),
181                                                         ("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
182                                                         ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
183                                                         ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
184                                                         ("Polarization", frontendData["polarization"], TYPE_TEXT),
185                                                         ("Inversion", frontendData["inversion"], TYPE_TEXT),
186                                                         ("FEC inner", frontendData["fec_inner"], TYPE_TEXT))
187                         elif frontendData["tuner_type"] == "DVB-C":
188                                 return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
189                                                 ("Type", frontendData["tuner_type"], TYPE_TEXT),
190                                                 ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
191                                                 ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
192                                                 ("Modulation", frontendData["modulation"], TYPE_TEXT),
193                                                 ("Inversion", frontendData["inversion"], TYPE_TEXT),
194                                                 ("FEC inner", frontendData["fec_inner"], TYPE_TEXT))
195                         elif frontendData["tuner_type"] == "DVB-T":
196                                 return (("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
197                                                 ("Type", frontendData["tuner_type"], TYPE_TEXT),
198                                                 ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
199                                                 ("Inversion", frontendData["inversion"], TYPE_TEXT),
200                                                 ("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
201                                                 ("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
202                                                 ("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
203                                                 ("Constellation", frontendData["constellation"], TYPE_TEXT),
204                                                 ("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
205                                                 ("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
206                                                 ("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT))
207                 return [ ]
208
209         def fillList(self, Labels):
210                 tlist = [ ]
211
212                 for item in Labels:
213                         value = item[1]
214                         if len(item) < 4:
215                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2]))
216                         else:
217                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2], item[3]))
218
219                 self["infolist"].l.setList(tlist)
220
221         def getServiceInfoValue(self, what):
222                 if self.info is None:
223                         return ""
224                 
225                 v = self.info.getInfo(what)
226                 if v == -2:
227                         v = self.info.getInfoString(what)
228                 elif v == -1:
229                         v = "N/A"
230
231                 return v