from Screens.Screen import Screen
from Components.ActionMap import ActionMap
from Components.Label import Label
from Components.NimManager import nimmanager
from Components.ServiceInfoList import ServiceInfoList, ServiceInfoListEntry, TYPE_TEXT, TYPE_VALUE_HEX, TYPE_VALUE_DEC, TYPE_VALUE_HEX_DEC, TYPE_SLIDER
from Components.Sources.StaticText import StaticText
from ServiceReference import ServiceReference
from Tools.Transponder import ConvertToHumanReadable
from enigma import iServiceInformation, eServiceCenter, iDVBFrontend

feSatellite = iDVBFrontend.feSatellite
feCable = iDVBFrontend.feCable
feTerrestrial = iDVBFrontend.feTerrestrial

try:
	from Screens.ServiceInfo import ServiceInfo, TYPE_SERVICE_INFO, TYPE_TRANSPONDER_INFO
	print "[PowerMetrixFHD] 015 -OK-- ServiceInfo"
except:
	print "[PowerMetrixFHD] 015 -NOK- ServiceInfo"

#######################################################################################################################################################

def ServiceInfo__init__(self, session, serviceref=None):
	Screen.__init__(self, session)

	self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
	{
		"ok": self.close,
		"cancel": self.close,
		"red": self.information,
		"green": self.pids,
		"yellow": self.transponder,
		"blue": self.tuner
	}, -1)

	if serviceref:
		self.type = TYPE_TRANSPONDER_INFO
		self["red"] = StaticText()
		self["green"] = StaticText()
		self["yellow"] = StaticText()
		self["blue"] = StaticText()
		info = eServiceCenter.getInstance().info(serviceref)
		self.transponder_info = info.getInfoObject(serviceref, iServiceInformation.sTransponderData)
		# info is a iStaticServiceInformation, not a iServiceInformation
		self.info = None
		self.feinfo = None
	else:
		self.type = TYPE_SERVICE_INFO
		self["red"] = StaticText(_("Service"))
		self["green"] = StaticText(_("PIDs"))
		self["yellow"] = StaticText(_("Multiplex"))
		self["blue"] = StaticText(_("Tuner status"))
		service = session.nav.getCurrentService()
		if service is not None:
			self.info = service.info()
			self.feinfo = service.frontendInfo()
			print self.info.getInfoObject(iServiceInformation.sCAIDs);
		else:
			self.info = None
			self.feinfo = None

	tlist = [ ]

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

#######################################################################################################################################################

def doServiceInfoChange():
	try:
		ServiceInfo.__init__ = ServiceInfo__init__
		print "[PowerMetrixFHD] 015 -OK-- ServiceInfo"
	except:
		print "[PowerMetrixFHD] 015 -NOK- ServiceInfo"
