from Screens.Screen import Screen
from Components.ActionMap import ActionMap
from Components.config import config, ConfigClock, ConfigInteger, getConfigListEntry, configfile
from Components.ConfigList import ConfigListScreen
from Components.Label import Label
from enigma import getDesktop

try:
	from Plugins.Extensions.GraphMultiEPG.GraphMultiEpg import GraphMultiEPGMenu
	print "[PowerMetrixFHD] 020 -OK-- GraphMultiEPG"
except:
	print "[PowerMetrixFHD] 020 -NOK- GraphMultiEPG"

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

def GraphMultiEPGMenu__init__(self, session):
	width = 492
	height = 230
	dsk_size = getDesktop(0).size()
	left = (dsk_size.width() - width) >> 1
	top = (dsk_size.height() - height) >> 1
	GraphMultiEPGMenu.skin = """<screen position="%d,%d" size="%d,%d" title="%s">
			<widget name="config" position="0,0"   size="492,105" scrollbarMode="showOnDemand" zPosition="1"/>
			<ePixmap pixmap="skin_default/div-h.png" position="0,108" zPosition="1" size="492,2" />
			<widget name="label"  position="0,110" size="492,70" font="Regular;16" zPosition="1" halign="left" valign="top"/>
			<ePixmap pixmap="skin_default/div-h.png" position="0,185" zPosition="1" size="492,2" />
			<ePixmap pixmap="skin_default/buttons/red.png"    position="0,190"   zPosition="0" size="140,40" transparent="1" alphatest="on" />
			<ePixmap pixmap="skin_default/buttons/green.png"  position="176,190" zPosition="0" size="140,40" transparent="1" alphatest="on" />
			<ePixmap pixmap="skin_default/buttons/yellow.png" position="352,190" zPosition="0" size="140,40" transparent="1" alphatest="on" />
			<widget name="key_r" position="0,190"   size="140,40" zPosition="5" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
			<widget name="key_g" position="176,190" size="140,40" zPosition="5" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
			<widget name="key_y" position="352,190" size="140,40" zPosition="5" valign="center" halign="center" font="Regular;21" transparent="1" foregroundColor="white" shadowColor="black" shadowOffset="-1,-1" />
		</screen>""" % (left, top, width, height, _("GraphMultiEPG settings"))

	Screen.__init__(self, session)

	# create config list
	self.list = []
	ConfigListScreen.__init__(self, self.list)
	self.createConfigList()

	self["actions"] = ActionMap(["OkCancelActions", "ColorActions"],
	{
		"ok"     : self.okPressed,
		"cancel" : self.cancelPressed,
		"red"    : self.cancelPressed,
		"green"  : self.okPressed,
		"yellow" : self.resetPressed,
		#"menu"   : self.cancelPressed,
	}, -2)
	self["actions"].setEnabled(True)

	self["label"] = Label("Info")
	self["key_r"] = Label(_("Cancel"))
	self["key_y"] = Label(_("Default"))
	self["key_g"] = Label(_("OK"))
	self.onLayoutFinish.append(self.__layoutFinished)

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

def __GraphMultiEPGMenulayoutFinished(self):
	if not self.selectionChanged in self["config"].onSelectionChanged:
		self["config"].onSelectionChanged.append(self.selectionChanged)
	self.selectionChanged()

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

def GraphMultiEPGMenuresetPressed(self):
	config.misc.graph_mepg_prime_time.value = config.misc.graph_mepg_prime_time.default
	self.createConfigList()
	self["config"].selectionChanged()

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

def doGraphMultiEPGChange():
	try:
		GraphMultiEPGMenu.__init__ = GraphMultiEPGMenu__init__
		GraphMultiEPGMenu.__layoutFinished = __GraphMultiEPGMenulayoutFinished
		GraphMultiEPGMenu.resetPressed = GraphMultiEPGMenuresetPressed
		print "[PowerMetrixFHD] 020 -OK-- GraphMultiEPG"
	except:
		print "[PowerMetrixFHD] 020 -NOK- GraphMultiEPG"
