from Screens.Screen import Screen
from Components.ActionMap import ActionMap
from Components.FIFOList import FIFOList
from Components.Label import Label
from Components.NimManager import nimmanager as nimmgr
from Components.ProgressBar import ProgressBar
from Components.Sources.FrontendInfo import FrontendInfo
from Tools.Directories import resolveFilename, SCOPE_CONFIG, fileExists
from enigma import eComponentScan, iDVBFrontend, eSlot3IIIRetI

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

try:
	from Screens.ServiceScan import ServiceScan
	from Components.ServiceScan import ServiceScan as CScan
	print "[PowerMetrixFHD] 019 -OK-- ServiceScan"
except:
	print "[PowerMetrixFHD] 019 -NOK- ServiceScan"

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

def ServiceScan__init__(self, session, scanList):
	Screen.__init__(self, session)

	self.scanList = scanList

	self.session.nav.stopService()

	self["scan_progress"] = ProgressBar()
	self["scan_state"] = Label(_("scan state"))
	self["network"] = Label()
	self["transponder"] = Label()

	self["pass"] = Label("")
	self["servicelist"] = FIFOList(len=12)
	self["FrontendInfo"] = FrontendInfo()

	self["actions"] = ActionMap(["OkCancelActions"], 
		{
			"ok": self.ok,
			"cancel": self.cancel
		})

	self.onFirstExecBegin.append(self.doServiceScan)

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

def ServiceScanupdatePass(self):
	size = len(self.scanList)
	if size > 0:
		self.passNumber.setText(_("pass") + " " + str(self.run + 1) + "/" + str(size) + " (" + _("Tuner") + " " + str(self.scanList[self.run]["feid"]) + ")")

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

def doServiceScanChange():
	try:
		ServiceScan.__init__ = ServiceScan__init__
		CScan.updatePass = ServiceScanupdatePass
		print "[PowerMetrixFHD] 019 -OK-- ServiceScan"
	except:
		print "[PowerMetrixFHD] 019 -NOK- ServiceScan"
