remove unneeded (double) close
[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
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         def GUIcreate(self, parent):
49                 self.instance = eListbox(parent)
50                 self.instance.setContent(self.l)
51                 self.instance.setItemHeight(25)
52
53         def GUIdelete(self):
54                 self.instance.setContent(None)
55                 self.instance = None
56
57 class ServiceInfo(Screen):
58         def __init__(self, session):
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                 service = session.nav.getCurrentService()
72                 if service is not None:
73                         self.info = service.info()
74                         self.feinfo = service.frontendStatusInfo()
75                 else:
76                         self.info = None
77
78
79                 self["red"] = Label("Serviceinfo")
80                 self["green"] = Label("PIDs")
81                 self["yellow"] = Label("Transponder")
82                 self["blue"] = Label("Tuner status")
83         
84                 tlist = [ ]
85
86                 self["infolist"] = ServiceInfoList(tlist)
87                 self.onShown.append(self.information)
88
89         def information(self):
90                 if self.session.nav.getCurrentlyPlayingServiceReference() is not None:
91                         name = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()).getServiceName()
92                 else:
93                         name = "N/A"
94                 Labels = ( ("Name",  name, TYPE_TEXT),
95                                    ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
96                                    ("Videoformat", self.getServiceInfoValue(iServiceInformation.sAspect), TYPE_TEXT),
97                                    ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8))
98                 self.fillList(Labels)
99         
100         def pids(self):
101                 Labels = ( ("VideoPID", self.getServiceInfoValue(iServiceInformation.sVideoPID), TYPE_VALUE_HEX_DEC, 4),
102                                    ("AudioPID", self.getServiceInfoValue(iServiceInformation.sAudioPID), TYPE_VALUE_HEX_DEC, 4),
103                                    ("PCRPID", self.getServiceInfoValue(iServiceInformation.sPCRPID), TYPE_VALUE_HEX_DEC, 4),
104                                    ("PMTPID", self.getServiceInfoValue(iServiceInformation.sPMTPID), TYPE_VALUE_HEX_DEC, 4),
105                                    ("TXTPID", self.getServiceInfoValue(iServiceInformation.sTXTPID), TYPE_VALUE_HEX_DEC, 4),
106                                    ("TSID", self.getServiceInfoValue(iServiceInformation.sTSID), TYPE_VALUE_HEX_DEC, 4),
107                                    ("ONID", self.getServiceInfoValue(iServiceInformation.sONID), TYPE_VALUE_HEX_DEC, 4),
108                                    ("SID", self.getServiceInfoValue(iServiceInformation.sSID), TYPE_VALUE_HEX_DEC, 4))
109                 self.fillList(Labels)
110         
111         def transponder(self):
112                 frontendData = self.feinfo.getFrontendData(True)
113                 Labels = self.getFEData(frontendData)
114                 self.fillList(Labels)
115                 
116         def tuner(self):
117                 frontendData = self.feinfo.getFrontendData(False)
118                 Labels = self.getFEData(frontendData)
119                 self.fillList(Labels)
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["tuner_type"], TYPE_TEXT),
127                                            ("Orbital position", frontendData["orbital_position"], TYPE_VALUE_DEC),
128                                            ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
129                                            ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
130                                            ("Polarization", frontendData["polarization"], TYPE_TEXT),
131                                            ("Inversion", frontendData["inversion"], TYPE_TEXT),
132                                            ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
133                                                 )
134                 elif frontendData["tuner_type"] == "DVB-C":
135                         return ( ("NIM", ['A', 'B', 'C', 'D'][frontendData["tuner_number"]], TYPE_TEXT),
136                                            ("Type", frontendData["tuner_type"], TYPE_TEXT),
137                                            ("Frequency", frontendData["frequency"], TYPE_VALUE_DEC),
138                                            ("Symbolrate", frontendData["symbol_rate"], TYPE_VALUE_DEC),
139                                            ("Modulation", frontendData["modulation"], TYPE_TEXT),
140                                            ("Inversion", frontendData["inversion"], TYPE_TEXT),
141                                            ("FEC inner", frontendData["fec_inner"], TYPE_TEXT),
142                                                 )
143                 elif frontendData["tuner_type"] == "DVB-T":
144                         return []
145                 
146         def fillList(self, Labels):
147                 tlist = [ ]
148
149                 for item in Labels:
150                         print item
151                         value = item[1]
152                         if len(item) < 4:
153                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2]))
154                         else:
155                                 tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2], item[3]))
156
157                 self["infolist"].l.setList(tlist)
158
159         def getServiceInfoValue(self, what):
160                 if self.info is None:
161                         return ""
162                 
163                 v = self.info.getInfo(what)
164                 if v == -2:
165                         v = self.info.getInfoString(what)
166                 elif v == -1:
167                         v = "N/A"
168
169                 return v