aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Screens/ServiceInfo.py
blob: b063a8a78fe59207f88666264518babc89eed602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
from Components.HTMLComponent import *
from Components.GUIComponent import *
from Screen import Screen
from Components.ActionMap import ActionMap
from Components.Label import Label
from Components.MenuList import MenuList
from ServiceReference import ServiceReference
from enigma import eListboxPythonMultiContent, eListbox, gFont, iServiceInformation

RT_HALIGN_LEFT = 0

TYPE_TEXT = 0
TYPE_VALUE_HEX = 1
TYPE_VALUE_DEC = 2
TYPE_VALUE_HEX_DEC = 3
TYPE_SLIDER = 4

def ServiceInfoListEntry(a, b, valueType=TYPE_TEXT, param=4):
	res = [ ]

	#PyObject *type, *px, *py, *pwidth, *pheight, *pfnt, *pstring, *pflags;
	res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 200, 30, 0, RT_HALIGN_LEFT, ""))
	res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 150, 25, 0, RT_HALIGN_LEFT, a))
	print "b:", b
	if type(b) is not str:
		if valueType == TYPE_VALUE_HEX:
			b = ("0x%0" + str(param) + "x") % b
		elif valueType == TYPE_VALUE_DEC:
			b = str(b)
		elif valueType == TYPE_VALUE_HEX_DEC:
			b = ("0x%0" + str(param) + "x (%dd)") % (b, b)
		else:
			b = str(b)		
	
	
	res.append((eListboxPythonMultiContent.TYPE_TEXT, 170, 0, 350, 25, 0, RT_HALIGN_LEFT, b))

	return res

class ServiceInfoList(HTMLComponent, GUIComponent):
	def __init__(self, source):
		GUIComponent.__init__(self)
		self.l = eListboxPythonMultiContent()
		self.list = source
		self.l.setList(self.list)
		self.l.setFont(0, gFont("Regular", 23))

	def GUIcreate(self, parent):
		self.instance = eListbox(parent)
		self.instance.setContent(self.l)
		self.instance.setItemHeight(25)

	def GUIdelete(self):
		self.instance.setContent(None)
		self.instance = None

class ServiceInfo(Screen):
	def __init__(self, session):
		Screen.__init__(self, session)
		
		self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
		{
			"ok": self.close,
			"cancel": self.close,
			"red": self.information,
			"green": self.pids,
			"yellow": self.transponder
		}, -1)
		
		service = session.nav.getCurrentService()
		if service is not None:
			self.info = service.info()
			self.feinfo = service.frontendStatusInfo()
			if self.feinfo:
				print self.feinfo.getFrontendData(False)
		else:
			self.info = None

		self["red"] = Label("Serviceinfo")
		self["green"] = Label("PIDs")
		self["yellow"] = Label("Transponder")
		self["blue"] = Label("")
	
		tlist = [ ]

		self["infolist"] = ServiceInfoList(tlist)
		self.onShown.append(self.information)

	def information(self):
		if self.session.nav.getCurrentlyPlayingServiceReference() is not None:
			name = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()).getServiceName()
		else:
			name = "N/A"
		Labels = ( ("Name",  name, TYPE_TEXT),
				   ("Provider", self.getServiceInfoValue(iServiceInformation.sProvider), TYPE_TEXT),
				   ("Videoformat", self.getServiceInfoValue(iServiceInformation.sAspect), TYPE_TEXT),
				   ("Namespace", self.getServiceInfoValue(iServiceInformation.sNamespace), TYPE_VALUE_HEX, 8))
		self.fillList(Labels)
	
	def pids(self):
		Labels = ( ("VideoPID", self.getServiceInfoValue(iServiceInformation.sVideoPID), TYPE_VALUE_HEX_DEC, 4),
				   ("AudioPID", self.getServiceInfoValue(iServiceInformation.sAudioPID), TYPE_VALUE_HEX_DEC, 4),
				   ("PCRPID", self.getServiceInfoValue(iServiceInformation.sPCRPID), TYPE_VALUE_HEX_DEC, 4),
				   ("PMTPID", self.getServiceInfoValue(iServiceInformation.sPMTPID), TYPE_VALUE_HEX_DEC, 4),
				   ("TXTPID", self.getServiceInfoValue(iServiceInformation.sTXTPID), TYPE_VALUE_HEX_DEC, 4),
				   ("TSID", self.getServiceInfoValue(iServiceInformation.sTSID), TYPE_VALUE_HEX_DEC, 4),
				   ("ONID", self.getServiceInfoValue(iServiceInformation.sONID), TYPE_VALUE_HEX_DEC, 4),
				   ("SID", self.getServiceInfoValue(iServiceInformation.sSID), TYPE_VALUE_HEX_DEC, 4))
		self.fillList(Labels)
	
	def transponder(self):
		Labels = ( ("Frequency", "11823", TYPE_TEXT),
				   ("Polarity", "H", TYPE_TEXT))
		self.fillList(Labels)
	
	def fillList(self, Labels):
		tlist = [ ]

		for item in Labels:
			print item
			value = item[1]
			if len(item) < 4:
				tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2]))
			else:
				tlist.append(ServiceInfoListEntry(item[0]+":", value, item[2], item[3]))

		self["infolist"].l.setList(tlist)

	def getServiceInfoValue(self, what):
		if self.info is None:
			return ""
		
		v = self.info.getInfo(what)
		if v == -2:
			v = self.info.getInfoString(what)
		elif v == -1:
			v = "N/A"

		return v