from Renderer import Renderer
from enigma import eServiceReference
from merlin.emerlinvideowidget import eMerlinVideoWidget

class VideoWidget(Renderer):
	def __init__(self):
		Renderer.__init__(self)
		self.ref = eServiceReference()

	GUI_WIDGET = eMerlinVideoWidget

	def applySkin(self, desktop, parent):
		attribs = [ ]
		for (attrib, value) in self.skinAttributes:
			if attrib == "scaleToWidget":
				self.instance.scaleToWidget(int(value))
			else:
				attribs.append((attrib,value))
		self.skinAttributes = attribs
		return Renderer.applySkin(self, desktop, parent)

	def doSuspend(self, suspended):
		if suspended:
			self.changed((self.CHANGED_CLEAR,))
		else:
			self.changed((self.CHANGED_DEFAULT,))

	def changed(self, what):
		if what[0] == self.CHANGED_CLEAR:
			self.instance.pauseVideo()
		else:
			ref = self.source.service
			if ref is not None:
				if self.ref != ref:
					if ref.flags & eServiceReference.mustDescent:
						self.ref = eServiceReference()
					else:
						self.ref = ref
					self.instance.playVideo(self.ref)
				else:
					self.instance.pauseVideo()

