639b970a41fd32493b71110c90cfe5711369e1ae
[vuplus_dvbapp] / 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
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 class ServiceInfo(Screen):
55         def __init__(self, session):
56                 Screen.__init__(self, session)
57                 
58                 self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
59                 {
60                         "ok": self.close,
61                         "cancel": self.close,
62                         "red": self.information,
63                         "green": self.pids,
64                         "yellow": self.transponder,
65                         "blue": self.tuner
66                 }, -1)
67                 
68                 service = session.nav.getCurrentService()
69                 if service is not None:
70                         self.info = service.info()
71                         self.feinfo = service.frontendInfo()
72                         print self.info.getInfoObject(iServiceInformation.sCAIDs);
73                 else:
74                         self.info = None
75                         self.feinfo = None
76
77
78                 self["red"] = Label(_("Serviceinfo"))
79                 self["green"] = Label(_("PIDs"))
80                 self["yellow"] = Label(_("Transponder"))
81                 self["blue"] = Label(_("Tuner status"))
82         
83                 tlist = [ ]
84
85                 self["infolist"] = ServiceInfoList(tlist)
86                 self.onShown.append(self.information)
87
88         def information(self):
89                 if self.session.nav.getCurrentlyPlayingServiceReference() is not None:
90                         name = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()).getServiceName()
91                 else:
92                         name = "N/A"
93                 Labels = ( ("Name",  name, TYPE_TEXT),
94                                    ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
95                                    ("Videoformat", self.getServiceInfoValue(iServiceInformation.sAspect), TYPE_TEXT),
96                                    ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8))
97                 self.fillList(Labels)
98         
99         def pids(self):
100                 Labels = ( ("VideoPID", self.getServiceInfoValue(iServiceInformation.sVideoPID), TYPE_VALUE_HEX_DEC, 4),
101                                    ("AudioPID", self.getServiceInfoValue(iServiceInformation.sAudioPID), TYPE_VALUE_HEX_DEC, 4),
102                                    ("PCRPID", self.getServiceInfoValue(iServiceInformation.sPCRPID), TYPE_VALUE_HEX_DEC, 4),
103                                    ("PMTPID", self.getServiceInfoValue(iServiceInformation.sPMTPID), TYPE_VALUE_HEX_DEC, 4),
104                                    ("TXTPID", self.getServiceInfoValue(iServiceInformation.sTXTPID), TYPE_VALUE_HEX_DEC, 4),
105                                    ("TSID", self.getServiceInfoValue(iServiceInformation.sTSID), TYPE_VALUE_HEX_DEC, 4),
106                                    ("ONID", self.getServiceInfoValue(iServiceInformation.sONID), TYPE_VALUE_HEX_DEC, 4),
107                                    ("SID", self.getServiceInfoValue(iServiceInformation.sSID), TYPE_VALUE_HEX_DEC, 4))
108                 self.fillList(Labels)
109         
110         def showFrontendData(self, real):
111                 frontendData = self.feinfo and self.feinfo.getFrontendData(real)
112                 Labels = self.getFEData(frontendData)
113                 self.fillList(Labels)
114         
115         def transponder(self):
116                 self.showFrontendData(True)
117                 
118         def tuner(self):
119                 self.showFrontendData(False)
120                 
121         def getFEData(self, frontendData):
122                 if frontendData is None:
123                         return []
124                 if frontendData["tuner_type"] == "DVB-S":
125                         return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
126                                            ("Type", frontendData["system"], TYPE_TEXT),
127                                            ("Modulation", frontendData["modulation"], TYPE_TEXT),
128                                            ("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
129                                            ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
130                                            ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
131                                            ("Polarization", frontendData["polarization"], TYPE_TEXT),
132                                            ("Inversion", frontendData["inversion"], TYPE_TEXT),
133                                            ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
134                                                 )
135                 elif frontendData["tuner_type"] == "DVB-C":
136                         return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
137                                            ("Type", frontendData["tuner_type"], TYPE_TEXT),
138                                            ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
139                                            ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
140                                            ("Modulation", frontendData["modulation"], TYPE_TEXT),
141                                            ("Inversion", frontendData["inversion"], TYPE_TEXT),
142                                            ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
143                                                 )
144                 elif frontendData["tuner_type"] == "DVB-T":
145                         return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
146                                            ("Type", frontendData["tuner_type"], TYPE_TEXT),
147                                            ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
148                                            ("Inversion", frontendData["inversion"], TYPE_TEXT),
149                                            ("Bandwidth", frontendData["bandwidth"], TYPE_VALUE_DEC),
150                                            ("CodeRateLP", frontendData["code_rate_lp"], TYPE_TEXT),
151                                            ("CodeRateHP", frontendData["code_rate_hp"], TYPE_TEXT),
152                                            ("Constellation", frontendData["constellation"], TYPE_TEXT),
153                                            ("Transmission Mode", frontendData["transmission_mode"], TYPE_TEXT),
154                                            ("Guard Interval", frontendData["guard_interval"], TYPE_TEXT),
155                                            ("Hierarchy Inform.", frontendData["hierarchy_information"], TYPE_TEXT),
156                                                 )
157                 
158         def fillList(self, Labels):
159                 tlist = [ ]
160
161                 for item in Labels:
162                         value = item[1]
163                         if len(item) < 4:
164                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2]))
165                         else:
166                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2], item[3]))
167
168                 self["infolist"].l.setList(tlist)
169
170         def getServiceInfoValue(self, what):
171                 if self.info is None:
172                         return ""
173                 
174                 v = self.info.getInfo(what)
175                 if v == -2:
176                         v = self.info.getInfoString(what)
177                 elif v == -1:
178                         v = "N/A"
179
180                 return v