#
# ChannelNumber
#
# Coded by dre (c) 2013
# Support: www.dreambox-tools.info
# E-Mail: dre@dreambox-tools.info
#
# This renderer is open source but it is NOT free software.
#
# This renderer may only be distributed to and executed on hardware which
# is licensed by Dream Multimedia GmbH.
# In other words:
# It's NOT allowed to distribute any parts of this renderer or its source code in ANY way
# to hardware which is NOT licensed by Dream Multimedia GmbH.
# It's NOT allowed to execute this renderer and its source code or even parts of it in ANY way
# on hardware which is NOT licensed by Dream Multimedia GmbH.
#
# If you want to use or modify the code or parts of it,
# you have to keep MY license and inform me about the modifications by mail.
#

from __future__ import absolute_import
from Components.VariableText import VariableText
from enigma import eLabel
from Components.Renderer.Renderer import Renderer
from Screens.InfoBar import InfoBar
from Components.config import config

ChannelSelectionServicelist = InfoBar.instance.servicelist

class ChannelNumber(Renderer, VariableText):
	def __init__(self):
		Renderer.__init__(self)
		VariableText.__init__(self)
		ChannelSelectionServicelist.servicelist.onSelectionChanged.append(self.channelSelectionServicelistServiceChanged)

	GUI_WIDGET = eLabel
	
	def disconnectAll(self):
		if InfoBar.instance is not None:
			ChannelSelectionServicelist.servicelist.onSelectionChanged.remove(self.channelSelectionServicelistServiceChanged)
		Renderer.disconnectAll(self)
	
	def channelSelectionServicelistServiceChanged(self):
		if config.merlin2.skin_showchannelnumber.value == False:
			self.text = " "
			return
		#check if channel is in bouquet as we only show a number for channels in bouquets
		if not ChannelSelectionServicelist.inBouquet():
			self.text = " "
		else:
			self.text = "%d" % (ChannelSelectionServicelist.servicelist.numberoffset + ChannelSelectionServicelist.servicelist.getCurrentIndex() + 1 - ChannelSelectionServicelist.servicelist.l.getNumMarkersBeforeCurrent())

