from Screens.Screen import Screen
from Components.ActionMap import NumberActionMap
from Components.config import config, getConfigListEntry
from Components.ConfigList import ConfigListScreen
from Components.Sources.StaticText import StaticText

try:
	from Plugins.Extensions.AudioSync.AC3utils import PLUGIN_BASE, PLUGIN_VERSION
	from Plugins.Extensions.AudioSync.AC3setup import AC3LipSyncSetup
	print "[PowerMetrixFHD] 006 -OK-- AudioSync"
except:
	print "[PowerMetrixFHD] 006 -NOK- AudioSync"

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

def AC3LipSyncSetup__init__(self, session, plugin_path):
	Screen.__init__(self, session)

	# Lets get a list of elements for the config list
	self.list = [
		getConfigListEntry(_("Outer Bound (+/-)"), config.plugins.AC3LipSync.outerBounds),
		getConfigListEntry(_("Step in ms for arrow keys"), config.plugins.AC3LipSync.arrowStepSize),
		getConfigListEntry(_("Wait time in ms before activation:"), config.plugins.AC3LipSync.activationDelay),
		getConfigListEntry(_("Step in ms for keys '%s'") %("1/3"), config.plugins.AC3LipSync.stepSize13),
		getConfigListEntry(_("Step in ms for keys '%s'") %("4/6"), config.plugins.AC3LipSync.stepSize46),
		getConfigListEntry(_("Step in ms for keys '%s'") %("7/9"), config.plugins.AC3LipSync.stepSize79),
		getConfigListEntry(_("Step in ms for key %i") %(2), config.plugins.AC3LipSync.absoluteStep2),
		getConfigListEntry(_("Step in ms for key %i") %(5), config.plugins.AC3LipSync.absoluteStep5),
		getConfigListEntry(_("Step in ms for key %i") %(8), config.plugins.AC3LipSync.absoluteStep8)
	]

	ConfigListScreen.__init__(self, self.list)

	self["config"].list = self.list

	self.skin_path = plugin_path

	# Plugin Information
	self["PluginInfo"] = StaticText(_("Plugin: %(plugin)s - Version: %(version)s") %dict(plugin=PLUGIN_BASE, version=PLUGIN_VERSION))

	# BUTTONS
	self["key_red"] = StaticText(_("Cancel"))
	self["key_green"] = StaticText(_("OK"))

	self["setupActions"] = NumberActionMap(["SetupActions", "ColorActions"],
	{
		"save": self.save,
		"cancel": self.cancel,
		"green": self.save,
		"red": self.cancel,
		"ok": self.save,
	}, -2)

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

def doAudioSyncChange():
	try:
		AC3LipSyncSetup.__init__ = AC3LipSyncSetup__init__
		print "[PowerMetrixFHD] 006 -OK-- AudioSync"
	except:
		print "[PowerMetrixFHD] 006 -NOK- AudioSync"
