from Screens.Screen import Screen
from Screens.HelpMenu import HelpableScreen
from Components.ActionMap import HelpableActionMap, ActionMap
from Components.config import config
from Components.DiskInfo import DiskInfo
from Components.Label import Label
from Components.MovieList import MovieList
from Components.Pixmap import Pixmap
from Components.Sources.StaticText import StaticText
from Components.UsageConfig import defaultMoviePath
from Tools.Directories import fileExists, resolveFilename, SCOPE_HDD
from enigma import  eServiceReference, eTimer

try:
	from Screens.MovieSelection import MovieSelection, SelectionEventInfo
	print "[PowerMetrixFHD] 007 -OK-- MovieSelection"
except:
	print "[PowerMetrixFHD] 007 -NOK- MovieSelection"

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

def MovieSelection__init__(self, session, selectedmovie = None):
	Screen.__init__(self, session)
	HelpableScreen.__init__(self)

	self.tags = [ ]
	if selectedmovie:
		self.selected_tags = config.movielist.last_selected_tags.value
	else:
		self.selected_tags = None
	self.selected_tags_ele = None

	self.movemode = False
	self.bouquet_mark_edit = False

	self.delayTimer = eTimer()
	self.delayTimer_conn = self.delayTimer.timeout.connect(self.updateHDDData)

	self["waitingtext"] = Label(_("Please wait... Loading list..."))

	# create optional description border and hide immediately
	self["DescriptionBorder"] = Pixmap()
	self["DescriptionBorder"].hide()

	if not fileExists(config.movielist.last_videodir.value):
		config.movielist.last_videodir.value = defaultMoviePath()
		config.movielist.last_videodir.save()
	self.current_ref = eServiceReference("2:0:1:0:0:0:0:0:0:0:" + config.movielist.last_videodir.value)

	self["list"] = MovieList(None,
		config.movielist.listtype.value,
		config.movielist.moviesort.value,
		config.movielist.description.value)

	self.list = self["list"]
	self.selectedmovie = selectedmovie

	# Need list for init
	SelectionEventInfo.__init__(self)

	self["key_red"] = StaticText(_("All"))
	self["key_green"] = StaticText("")
	self["key_yellow"] = StaticText("")
	self["key_blue"] = StaticText("")

	self["freeDiskSpace"] = self.diskinfo = DiskInfo(config.movielist.last_videodir.value, DiskInfo.FREE, update=False)

	if config.usage.setup_level.index >= 2: # expert+
		self["InfobarActions"] = HelpableActionMap(self, "InfobarActions", 
			{
				"showMovies": (self.doPathSelect, _("select the movie path")),
			})

	self["MovieSelectionActions"] = HelpableActionMap(self, "MovieSelectionActions",
		{
			"contextMenu": (self.doContext, _("menu")),
			"showEventInfo": (self.showEventInformation, _("show event details")),
		})

	self["ColorActions"] = HelpableActionMap(self, "ColorActions",
		{
			"red": (self.showAll, _("show all")),
			"green": (self.showTagsFirst, _("show first selected tag")),
			"yellow": (self.showTagsSecond, _("show second selected tag")),
			"blue": (self.showTagsSelect, _("show tag menu")),
		})

	self["OkCancelActions"] = HelpableActionMap(self, "OkCancelActions",
		{
			"cancel": (self.abort, _("exit movielist")),
			"ok": (self.movieSelected, _("select movie")),
		})

	self.onShown.append(self.go)
	self.onLayoutFinish.append(self.saveListsize)
	self.inited = False

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

def doMovieSelectionChange():
	try:
		MovieSelection.__init__ = MovieSelection__init__
		print "[PowerMetrixFHD] 007 -OK-- MovieSelection"
	except:
		print "[PowerMetrixFHD] 007 -NOK- MovieSelection"
