#!/usr/bin/python
# -*- coding: utf-8 -*-
from Screens.Screen import Screen
from Components.ActionMap import ActionMap, HelpableActionMap
from Components.ConfigList import ConfigListScreen
from Components.config import config, getConfigListEntry, ConfigSelection, ConfigYesNo, ConfigInteger
from Components.Sources.StaticText import StaticText
from enigma import eLabel, eSize, eServiceReference, RT_VALIGN_TOP, RT_VALIGN_CENTER, RT_HALIGN_CENTER, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, gFont, eListbox, eServiceCenter, eListboxPythonMultiContent, eListboxServiceContent, eEPGCache, getDesktop, eTimer
from skin import parseColor, parseFont, TemplatedColors, componentSizes, TemplatedListFonts
from Components.GUIComponent import GUIComponent
from Tools.LoadPixmap import LoadPixmap
from Tools.Directories import resolveFilename, SCOPE_CURRENT_SKIN, SCOPE_LANGUAGE, SCOPE_PLUGINS
from time import time, localtime
from Components.ServiceList import PiconLoader
from Components.ServiceList import ServiceList
from Components.Language import language
import sys, os, gettext
VERSION = "0.0.5 beta"
#language-support
lang = language.getLanguage()
os.environ["LANGUAGE"] = lang[:2]
gettext.bindtextdomain("enigma2", resolveFilename(SCOPE_LANGUAGE))
gettext.textdomain("enigma2")
gettext.bindtextdomain("ChannelSelectionPlus", "%s%s" % (resolveFilename(SCOPE_PLUGINS), "Extensions/ChannelSelectionPlus/locale"))
def _(txt):
t = gettext.dgettext("ChannelSelectionPlus", txt)
if t == txt:
t = gettext.gettext(txt)
return t
#new config for channelselection
config.usage.configselection_listnumbersposition = ConfigSelection(default = "0", choices = [("0",_("ahead")),("1",_("together with servicename"))])
config.usage.configselection_listnumberformat = ConfigSelection(default = "%d", choices = [("%d",_("only number")),("%d.",_("number with dot"))])
config.usage.configselection_showeventnameunderservicename = ConfigYesNo(default=False)
config.usage.configselection_servicenamecolwidth_percent = ConfigInteger(40, limits =(0,100))
#check for Merlin-Image
global isMerlin
isMerlin = False
try:
from Components.Merlin import MerlinImage
isMerlin = True
except: pass
if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/EPGSearch"):
from Plugins.Extensions.EPGSearch.EPGSearch import EPGSearch
# overwrite EPGSelection __init__ for audio-key
from Screens.EpgSelection import EPGSelection
baseEPGSelection__init__ = None
baseEPGSelection__init__ = EPGSelection.__init__
def EPGSelection__init__(self, session, service, zapFunc=None, eventid=None, bouquetChangeCB=None, serviceChangeCB=None):
baseEPGSelection__init__(self, session, service, zapFunc, eventid, bouquetChangeCB, serviceChangeCB)
def bluePressed():
cur = self["list"].getCurrent()
if cur[0] is not None:
name = cur[0].getEventName()
else:
name = ''
self.session.open(EPGSearch, name)
self["epgsearch_epgselection"] = ActionMap(["InfobarAudioSelectionActions"],
{
"audioSelection": bluePressed,
})
EPGSelection.__init__ = EPGSelection__init__
# Overwrite EventViewBase.__init__
from Screens.EventView import EventViewBase
baseEventViewBase__init__ = EventViewBase.__init__
def EventViewBase__init__(self, Event, Ref, callback=None, similarEPGCB=None):
baseEventViewBase__init__(self, Event, Ref, callback, similarEPGCB)
def searchEPG():
eventName = self.event.getEventName()
self.session.open(EPGSearch, eventName)
self["epgsearch_eventview"] = HelpableActionMap(self, "InfobarAudioSelectionActions",
{
"audioSelection": (searchEPG, _("Search EPG with Message")),
})
EventViewBase.__init__ = EventViewBase__init__
ChannelSelectionBase_ori = None
from Screens.ChannelSelection import ChannelSelectionBase
ChannelSelectionBase_ori = ChannelSelectionBase.__init__
#overwrite ChannelSelectionBase from ChannelSelection
def ChannelSelectionBase__init__(self, session):
print "=== ChannelSelectionPlus ChannelSelectionBase__init__"
ChannelSelectionBase_ori(self, session)
self["list"] = ServiceListOwn(session)
self.servicelist = self["list"]
#set Audio-Key to search with EPGSearch
if os.path.exists("/usr/lib/enigma2/python/Plugins/Extensions/EPGSearch"):
def searchEPG():
eventName = getEventName(cur = self.servicelist.getCurrent())
self.session.open(EPGSearch, eventName)
def getEventName(cur):
serviceref = cur
refstr = serviceref.toString()
event = None
try:
epg = eEPGCache.getInstance()
event = epg.lookupEventTime(serviceref, -1, 0)
if event is None:
info = eServiceCenter.getInstance().info(serviceref)
event = info.getEvent(0)
except:
pass
if event is not None:
return event.getEventName()
else:
return ""
self["epgsearch_channelbase"] = HelpableActionMap(self, "InfobarAudioSelectionActions",
{
"audioSelection": (searchEPG, _("Search EPG with Message")),
})
ChannelSelectionBase.__init__ = ChannelSelectionBase__init__
#overwrite open ChannelSelectionDisplaySettings from ChannelContextMenu
def displaySettingsOwn(self):
self.session.openWithCallback(self.close, ChannelSelectionDisplaySettings)
from Screens.ChannelSelection import ChannelContextMenu
ChannelContextMenu.displaySettings = displaySettingsOwn
class ChannelSelectionDisplaySettings(Screen, ConfigListScreen):
skin = """
"""
def __init__(self, session):
Screen.__init__(self, session)
self.setTitle(_("ChannelSelection Display Settings") + " (CSP " + VERSION + ")")
self.createConfig()
self["actions"] = ActionMap(["SetupActions", "ColorActions"],
{
"green": self.keySave,
"red": self.keyCancel,
"cancel": self.keyCancel,
"left": self.keyLeft,
"right": self.keyRight,
}, -2)
self["key_blue"] = StaticText("")
self["key_yellow"] = StaticText("")
self["key_red"] = StaticText(_("Cancel"))
self["key_green"] = StaticText(_("OK"))
self.list = []
ConfigListScreen.__init__(self, self.list, session = session)
self.createSetup("config")
def keyCancel(self):
config.usage.configselection_bigpicons.cancel()
config.usage.configselection_secondlineinfo.cancel()
ConfigListScreen.cancelConfirm(self, True)
def keySave(self):
for x in self["config"].list:
x[1].save()
config.usage.configselection_bigpicons.save()
config.usage.configselection_secondlineinfo.save()
self.showeventnameunderservicename.save()
self.close()
def newConfig(self):
cur = self["config"].getCurrent()
if cur and cur in (self.additionEventInfoEntry, self.columnStyleEntry, self.showEventProgressEntry, self.showServiceNameEntry, self.showlistnumbersEntry, self.showEventnameUnderServicenameEntry):
self.createSetup("config")
if cur and cur in (self.piconPathEntry, self.showPiconsEntry):
if self.showpicons.value:
if self.piconpath.value.endswith("/picon/"):
config.usage.configselection_bigpicons.value = True
else:
config.usage.configselection_bigpicons.value = False
self.createSetup("config")
# logical dependence between settings for showservicename and showeventnameunderservicename
if cur and cur == self.showServiceNameEntry and not self.showservicename.value:
self.showeventnameunderservicename.value = self.showservicename.value
if cur and cur == self.showEventnameUnderServicenameEntry and self.showeventnameunderservicename.value:
self.showservicename.value = self.showeventnameunderservicename.value
#for Merlin-Image
if isMerlin and cur and cur[1] == config.usage.configselection_listnumbersposition:
self.createSetup("config")
def keyLeft(self):
ConfigListScreen.keyLeft(self)
self.newConfig()
def keyRight(self):
ConfigListScreen.keyRight(self)
self.newConfig()
def createConfig(self):
#set new choices with "nothing" instead "off"
#config.usage.configselection_showadditionaltimedisplay = ConfigSelection(default = config.usage.configselection_showadditionaltimedisplay.value, choices = [("0", _("nothing")), ("1", _("Percent")), ("2", _("Remain")),("3", _("Remain / duration")), ("4", _("Elapsed")), ("5", _("Elapsed / duration")), ("6", _("Elapsed / remain / duration")),("7", _("Time"))])
config.usage.configselection_showadditionaltimedisplay.choices.choices = [("0", _("nothing")), ("1", _("Percent")), ("2", _("Remain")),("3", _("Remain / duration")), ("4", _("Elapsed")), ("5", _("Elapsed / duration")), ("6", _("Elapsed / remain / duration")),("7", _("Time"))]
self.additionEventInfo = config.usage.configselection_showadditionaltimedisplay
self.columnStyle = config.usage.configselection_columnstyle
self.showlistnumbers = config.usage.configselection_showlistnumbers
self.listnumberposition = config.usage.configselection_listnumbersposition
self.listnumerformat = config.usage.configselection_listnumberformat
self.progressbarposition = config.usage.configselection_progressbarposition
self.showeventprogress = config.usage.show_event_progress_in_servicelist
self.showpicons = config.usage.configselection_showpicons
self.showservicename = config.usage.configselection_showservicename
self.showbigpicons = config.usage.configselection_bigpicons
self.piconpath = config.usage.configselection_piconspath
self.showeventnameunderservicename = config.usage.configselection_showeventnameunderservicename
def createSetup(self, widget):
self.list = []
self.columnStyleEntry = getConfigListEntry(_("Column style"), self.columnStyle)
self.list.append(self.columnStyleEntry)
# self.list.append(getConfigListEntry(_("Show settings in channel context menu"), config.usage.configselection_showsettingsincontextmenu))
self.list.append(getConfigListEntry(_("Show recordings"), config.usage.configselection_showrecordings))
if self.columnStyle.value:
self.showServiceNameEntry = getConfigListEntry(_("Show service name"), self.showservicename)
self.list.append(self.showServiceNameEntry)
self.showEventnameUnderServicenameEntry = getConfigListEntry(_("Show eventname below servicename"), self.showeventnameunderservicename)
if self.showservicename.value:
self.list.append(self.showEventnameUnderServicenameEntry)
else:
self.showServiceNameEntry = None
self.showEventnameUnderServicenameEntry = getConfigListEntry(_("Show eventname below servicename"), self.showeventnameunderservicename)
self.list.append(self.showEventnameUnderServicenameEntry)
if isMerlin:
self.list.append(getConfigListEntry(_("Show DVB-icons"), config.usage.configselection_showdvbicons))
self.showlistnumbersEntry = getConfigListEntry(_("Show service numbers"), self.showlistnumbers)
self.list.append(self.showlistnumbersEntry)
if self.showlistnumbers.value:
self.list.append(getConfigListEntry(_("service number position"), config.usage.configselection_listnumbersposition))
self.list.append(getConfigListEntry(_("service number format"), config.usage.configselection_listnumberformat))
if isMerlin and config.usage.configselection_listnumbersposition.value == "0":
self.list.append(getConfigListEntry(_("Service number alignment"), config.usage.configselection_listnumbersalignment))
self.showPiconsEntry = getConfigListEntry(_("Show Picons"), self.showpicons)
self.list.append(self.showPiconsEntry)
if self.showpicons.value:
self.piconPathEntry = getConfigListEntry(_("Picons path"), self.piconpath)
self.list.append(self.piconPathEntry)
else:
config.usage.configselection_bigpicons.value = False
self.piconPathEntry = None
if self.columnStyle.value:
self.list.append(getConfigListEntry(_("2nd line info"), config.usage.configselection_secondlineinfo))
else:
config.usage.configselection_secondlineinfo.value = "0"
if self.columnStyle.value:
self.list.append(getConfigListEntry(_("Servicename column width in %"), config.usage.configselection_servicenamecolwidth_percent))
self.showEventProgressEntry = getConfigListEntry(_("Show event-progress"), self.showeventprogress)
self.list.append(self.showEventProgressEntry)
if self.columnStyle.value and self.showservicename.value:
self.progressbarposition.setChoices([("0",_("After service number")),("1",_("After service name")), ("2",_("After event description"))])
else:
self.progressbarposition.setChoices([("0",_("After service number")), ("2",_("After event description"))])
if self.showeventprogress.value:
self.list.append(getConfigListEntry(_("Event-progessbar position"), self.progressbarposition))
self.additionEventInfoEntry = getConfigListEntry(_("Additional event-time info"), self.additionEventInfo)
self.list.append(self.additionEventInfoEntry)
if self.additionEventInfo.value != "0":
self.list.append(getConfigListEntry(_("Additional event-time position"), config.usage.configselection_additionaltimedisplayposition))
if isMerlin:
self.list.append(getConfigListEntry(_("Tag bouquet services"), config.usage.configselection_tagBouquetServices))
self[widget].list = self.list
self[widget].l.setList(self.list)
class ServiceListOwn(ServiceList):
def __init__(self, session = None):
print "=== ServiceListOwn__init__"
ServiceList.__init__(self, session)
tlf = TemplatedListFonts()
self.serviceNumberFont = gFont(tlf.face(TemplatedListFonts.MEDIUM), tlf.size(TemplatedListFonts.MEDIUM))
config.usage.configselection_showeventnameunderservicename.addNotifier(self.setItemHeight, initial_call = False)
print "== isMerlin", isMerlin
def setItemHeight(self, configElement = None):
print "=== ServiceListOwn setItemHeight"
if (config.usage.configselection_bigpicons.value or config.usage.configselection_secondlineinfo.value != "0" or config.usage.configselection_showeventnameunderservicename.value) and self.mode == self.MODE_FAVOURITES:
self.l.setItemHeight(self.itemHeightHigh)
if self.instance is not None and self.selectionPixmapBig:
self.instance.setSelectionPicture(self.selectionPixmapBig)
else:
self.l.setItemHeight(self.itemHeight)
if self.instance is not None and self.selectionPixmapStandard:
self.instance.setSelectionPicture(self.selectionPixmapStandard)
def _buildOptionEntryProgressBar(self, event, xoffset, width, height):
print "=== ServiceListOwn buildOptionEntryProgressBar"
percent = 0
progressW = self._progressBarWidth()
progressH = self._componentSizes.get(self.KEY_PROGRESS_BAR_HEIGHT, 8)
if event and event.getDuration():
now = int(time())
percent = 100 * (now - event.getBeginTime()) / event.getDuration()
top = int((height - progressH) / 2)
showeventnameunderservicename = config.usage.configselection_showeventnameunderservicename.value
progressbarPosition = config.usage.configselection_progressbarposition.value
if showeventnameunderservicename and self.mode != self.MODE_NORMAL and progressbarPosition != "0":
top = int((height - self.serviceInfoHeight - progressH) / 2)
if self.picServiceEventProgressbar is None:
return(eListboxPythonMultiContent.TYPE_PROGRESS, xoffset, top, progressW, progressH, percent, 1, self.serviceEventProgressbarColor, self.serviceEventProgressbarColorSelected, self.serviceEventProgressbarBackColor, self.serviceEventProgressbarBackColorSelected)
else:
return(eListboxPythonMultiContent.TYPE_PROGRESS_PIXMAP, xoffset, top, progressW, progressH, percent, self.picServiceEventProgressbar, 1, self.serviceEventProgressbarBorderColor, self.serviceEventProgressbarBorderColorSelected, self.serviceEventProgressbarBackColor, self.serviceEventProgressbarBackColorSelected)
# def _buildOptionEntryAddTimeDisplay(self, event, isPlayable, columnStyle):
# print "=== ServiceListOwn buildOptionEntryAddTimeDisplay"
# addtimedisplay = ""
# addtimedisplayWidth = 0
# if not ( config.usage.configselection_showadditionaltimedisplay.value != "0" and event and isPlayable ):
# return addtimedisplay, addtimedisplayWidth
# textTpl = ""
# maxTimeValue = 9999
# if config.usage.configselection_showadditionaltimedisplay.value == "1": # percent
# now = int(time())
# percent = 100 * (now - event.getBeginTime()) / event.getDuration()
# addtimedisplay = "%d%%" % percent
# textTpl = "100%"
# elif config.usage.configselection_showadditionaltimedisplay.value == "2": # remain
# now = int(time())
# remain = int((event.getBeginTime() + event.getDuration() - now) / 60)
# addtimedisplay = "+%d min" %(remain,)
# textTpl = "+%d min" %(maxTimeValue,)
# elif config.usage.configselection_showadditionaltimedisplay.value == "3": # Remain / duration
# now = int(time())
# remain = int((event.getBeginTime() + event.getDuration() - now) / 60)
# duration = int(event.getDuration() / 60)
# addtimedisplay = "+%d/%d min" % (remain, duration)
# textTpl = "+%d/%d min" % (maxTimeValue, maxTimeValue)
# elif config.usage.configselection_showadditionaltimedisplay.value == "4": # elapsed
# now = int(time())
# elapsed = int((now - event.getBeginTime()) / 60)
# addtimedisplay = "%d min" % (elapsed,)
# textTpl = "%d min" % (maxTimeValue,)
# elif config.usage.configselection_showadditionaltimedisplay.value == "5": # elapsed / duration
# now = int(time())
# elapsed = int((now - event.getBeginTime()) / 60)
# duration = int(event.getDuration() / 60)
# addtimedisplay = "%d/%d min" % (elapsed, duration)
# textTpl = "%d/%d min" % (maxTimeValue, maxTimeValue)
# elif config.usage.configselection_showadditionaltimedisplay.value == "6": # elapsed / remain / duration
# now = int(time())
# elapsed = int((now - event.getBeginTime()) / 60)
# remain = int((event.getBeginTime() + event.getDuration() - now) / 60)
# duration = int(event.getDuration() / 60)
# addtimedisplay = "%d/+%d/%d min" % (elapsed, remain, duration)
# textTpl = "%d/+%d/%d min" % (maxTimeValue, maxTimeValue, maxTimeValue)
# elif config.usage.configselection_showadditionaltimedisplay.value == "7": # begin - end time
# beginTime = localtime(event.getBeginTime())
# endTime = localtime(event.getBeginTime()+event.getDuration())
# addtimedisplay = "%02d:%02d - %02d:%02d" % (beginTime[3],beginTime[4],endTime[3],endTime[4])
# textTpl = "00:00 - 00:000"
# if columnStyle:
# addtimedisplayWidth = self._calcTextWidth(textTpl, font=self.additionalInfoFont, size=eSize(self.getDesktopWith() / 3, 0))
# return addtimedisplay, addtimedisplayWidth
def buildOptionEntry(self, service, **args):
width = self.l.getItemSize().width()
width -= self._componentSizes.get(self.KEY_END_MARGIN, 5)
height = self.l.getItemSize().height()
selected = args["selected"]
res = [ None ]
showListNumbers = config.usage.configselection_showlistnumbers.value
if isMerlin:
listNumbersAlignment = config.usage.configselection_listnumbersalignment.value
listNumerPosition = config.usage.configselection_listnumbersposition.value
showPicons = self.mode == self.MODE_FAVOURITES and config.usage.configselection_showpicons.value
showServiceName = self.mode == self.MODE_NORMAL or (self.mode == self.MODE_FAVOURITES and config.usage.configselection_showservicename.value)
showEventNameUnderServiceName = config.usage.configselection_showeventnameunderservicename.value
showProgressbar = config.usage.show_event_progress_in_servicelist.value
progressbarPosition = config.usage.configselection_progressbarposition.value
columnStyle = config.usage.configselection_columnstyle.value
additionalposition = config.usage.configselection_additionaltimedisplayposition.value
bigPicons = self.mode == self.MODE_FAVOURITES and config.usage.configselection_bigpicons.value
secondlineinfo = config.usage.configselection_secondlineinfo.value
# get service information
service_info = self.service_center.info(service)
isMarker = service.flags & eServiceReference.isMarker
isPlayable = not(service.flags & eServiceReference.isDirectory or isMarker)
recording = self._checkHasRecording(service, isPlayable)
marked = 0
if self.l.isCurrentMarked() and selected:
marked = 2
elif self.l.isMarked(service):
if selected:
marked = 2
else:
marked = 1
if marked == 1: # marked
additionalInfoColor = serviceDescriptionColor = forgroundColor = self.markedForeground
backgroundColor = self.markedBackground
forgroundColorSel = backgroundColorSel = additionalInfoColorSelected = serviceDescriptionColorSelected = None
elif marked == 2: # marked and selected
additionalInfoColorSelected = serviceDescriptionColorSelected = forgroundColorSel = self.markedForegroundSelected
backgroundColorSel = self.markedBackgroundSelected
forgroundColor = additionalInfoColor = serviceDescriptionColor = backgroundColor = None
else:
if recording:
forgroundColor = additionalInfoColor = serviceDescriptionColor = self.recordingColor
forgroundColorSel = additionalInfoColorSelected = serviceDescriptionColorSelected = self.recordingColorSelected
backgroundColor = backgroundColorSel = None
else:
forgroundColor = forgroundColorSel = backgroundColor = backgroundColorSel = None
serviceDescriptionColor = self.serviceDescriptionColor
serviceDescriptionColorSelected = self.serviceDescriptionColorSelected
additionalInfoColor = self.additionalInfoColor
additionalInfoColorSelected = self.additionalInfoColorSelected
if (marked == 0 and isPlayable and service_info and not service_info.isPlayable(service, self.is_playable_ignore)):
forgroundColor = forgroundColorSel = additionalInfoColor = additionalInfoColorSelected = serviceDescriptionColor = serviceDescriptionColorSelected = self.serviceNotAvail
# set windowstyle
if marked > 0:
res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width , height, 1, RT_HALIGN_RIGHT, "", forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
info = self.service_center.info(service)
serviceName = info and info.getName(service) or ""
event = info and info.getEvent(service)
index = self.getCurrentIndex()
xoffset = self._componentSizes.get(self.KEY_BEGIN_MARGIN, 5)
pixmap = self._buildOptionEntryServicePixmap(service)
drawProgressbar = isPlayable and showProgressbar
progressBarWidth = self._progressBarWidth(withOffset=True)
textOffset = self._componentSizes.get(self.KEY_TEXT_OFFSET, 10)
# pic for marker, folder, servicegroup or dvb_pic
if pixmap is not None:
pixmap_size = self.picMarker.size()
pix_width = pixmap_size.width()
pix_height = pixmap_size.height()
ypos = (height - pix_height) / 2
res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHABLEND, xoffset, ypos, pix_width, pix_height, pixmap))
xoffset += pix_width + self._componentSizes.get(self.KEY_PICON_OFFSET, 8)
#for Merlin
elif isMerlin and config.usage.configselection_showdvbicons.value:
# this is a hack. We assume as in the above function that the marker pic is always available
pixmap_size = self.picMarker.size()
pix_width = pixmap_size.width()
xoffset += pix_width + self._componentSizes.get(self.KEY_PICON_OFFSET, 8)
# for Merlin Shaderman tag bouquet services
if isMerlin and self.showBouquetEntries and isPlayable:
pixmap = self.picInBouquet
if pixmap is not None:
pixmap_size = pixmap.size()
pix_width = pixmap_size.width()
pix_height = pixmap_size.height()
if service in self.bouquetServices and self.mode == self.MODE_NORMAL:
ypos = (height - pix_height) / 2
res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHABLEND, xoffset, ypos, pix_width, pix_height, pixmap))
else:
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, pix_width , pix_height, 1, RT_HALIGN_LEFT, "", forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
xoffset += pix_width + self._componentSizes.get(self.KEY_INBOUQUET_OFFSET, 8)
# servicenumber on first position
listnumberwidth = 0
if self.mode != self.MODE_NORMAL:
if not (service.flags & eServiceReference.isMarker) and ((showListNumbers and not showServiceName and columnStyle) or (listNumerPosition=="0" and showListNumbers)):
markers_before = self.l.getNumMarkersBeforeCurrent()
servicenumberformat = config.usage.configselection_listnumberformat.value
text = servicenumberformat % (self.numberoffset + index + 1 - markers_before)
nameWidthmax = self._componentSizes.get(self.KEY_SERVICE_NUMBER_WIDTH, 50)
dotWidth = 0
if servicenumberformat == "%d.": # add dot to field-width if show with dot
dotWidth = self._calcTextWidth(".", font=self.serviceNumberFont, size=eSize(nameWidthmax,0))
listnumberwidth = nameWidthmax + dotWidth
#for Merlin
if isMerlin and listNumbersAlignment == "0":
align = RT_HALIGN_LEFT
else:
align = RT_HALIGN_RIGHT
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, listnumberwidth , height, 1, align|RT_VALIGN_CENTER, text, forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
xoffset += listnumberwidth + textOffset
# picons
if isPlayable and showPicons:
picon = self._buildOptionEntryServicePicon(service)
if bigPicons:
pix_width = self._componentSizes.get(self.KEY_PICON_WIDTH_BIG, 108)
else:
pix_width = self._componentSizes.get(self.KEY_PICON_WIDTH, 58)
if picon:
res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHABLEND, xoffset, 0, pix_width, height, picon))
xoffset += pix_width
xoffset += self._componentSizes.get(self.KEY_PICON_OFFSET, 8)
# progressbar between servicenumber and servicename
if drawProgressbar and progressbarPosition == "0":
res.append(self._buildOptionEntryProgressBar(event, xoffset, width, height))
xoffset += progressBarWidth
addtimedisplay, addtimedisplayWidth = self._buildOptionEntryAddTimeDisplay(event, isPlayable, columnStyle)
if columnStyle:
rwidth = 0
addoffset = 0
servicenameWidth = 0
#servicenameWidth = width - xoffset
# servicename
if (isPlayable and showServiceName) or not isPlayable:
if isPlayable:
rwidth = servicenameWidth # space for servicename
else:
rwidth = width - xoffset # space for servicename
xoffset_ServiceName = xoffset
servicenameWidth = width - xoffset
nheight = height
if self.mode != self.MODE_NORMAL:
# servicenumber if together with servicename
if not (service.flags & eServiceReference.isMarker) and showListNumbers and listNumerPosition=="1":
if showEventNameUnderServiceName and showServiceName: # set height for show in second line
nheight = height - self.serviceInfoHeight
markers_before = self.l.getNumMarkersBeforeCurrent()
servicenumberformat = config.usage.configselection_listnumberformat.value
text = servicenumberformat % (self.numberoffset + index + 1 - markers_before)
nameWidthmax = self._componentSizes.get(self.KEY_SERVICE_NUMBER_WIDTH, 50)
listnumberwidth = self._calcTextWidth(text, font=self.serviceNumberFont, size=eSize(width,0)) + textOffset
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, listnumberwidth , nheight, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, text, forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
xoffset += listnumberwidth
servicenameWidth = rwidth - listnumberwidth
if showEventNameUnderServiceName and showServiceName and not isMarker:
nheight = height - self.serviceInfoHeight
# autocalculate the servicenameWidth to new max value from percent in the settings
if not ((service.flags & eServiceReference.isMarker) or (service.flags & eServiceReference.isDirectory) or (service.flags & eServiceReference.isGroup)):
restWidth = width
restWidth -= xoffset_ServiceName
progresswidth = self._progressBarWidth(withOffset=True, withProgressBarSize=False)
progresswidth += self._progressBarWidth(withOffset=True, withProgressBarSize=True)
if not drawProgressbar or (showEventNameUnderServiceName and secondlineinfo != "0" and self.mode == self.MODE_FAVOURITES):
progresswidth = 0
restWidth -= progresswidth
addInfoWidth = addtimedisplayWidth
if addtimedisplay == "" or (showEventNameUnderServiceName and secondlineinfo != "0" and self.mode == self.MODE_FAVOURITES):
addInfoWidth = 0
restWidth -= addInfoWidth
percent_val = int(config.usage.configselection_servicenamecolwidth_percent.value)
#calculate the eventnamewidth with percent from settings (of free restWidth)
eventnamewidth = restWidth * ((100-percent_val)/float(100))
if showEventNameUnderServiceName and self.mode == self.MODE_FAVOURITES and secondlineinfo == "0":
eventnamewidth = 0
servicenameWidth = restWidth - eventnamewidth
if showListNumbers and listNumerPosition=="1" and self.mode == self.MODE_FAVOURITES:
servicenameWidth -= listnumberwidth
# end autocalculate the servicenameWidth to new max value from percent in the settings
# servicename
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, servicenameWidth , nheight, 2, RT_HALIGN_LEFT|RT_VALIGN_CENTER, serviceName, forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
xoffset += servicenameWidth + textOffset
# progressbar between servicename and service description
if event and isPlayable and drawProgressbar and progressbarPosition == "1":
res.append(self._buildOptionEntryProgressBar(event, xoffset, width, height))
if not showEventNameUnderServiceName or self.mode != self.MODE_FAVOURITES:
xoffset += progressBarWidth # move xoffset only if not showEventNameUnderServiceName
if event and isPlayable:
rwidth = width - xoffset
if drawProgressbar and progressbarPosition == "2":
rwidth -= self._progressBarWidth(withOffset=True, withProgressBarSize=False)
rwidth -= self._progressBarWidth(withOffset=True, withProgressBarSize=True)
if addtimedisplay != "" :
if additionalposition == "0":
# add time text before service description
iheight = height
itop = 0
if showEventNameUnderServiceName and showServiceName and self.mode == self.MODE_FAVOURITES:
iheight = height - self.serviceInfoHeight
axoffset = xoffset
if showEventNameUnderServiceName and drawProgressbar and progressbarPosition != "2" and self.mode == self.MODE_FAVOURITES:
axoffset += progressBarWidth
#pass
axoffset -= textOffset*2
res.append((eListboxPythonMultiContent.TYPE_TEXT, axoffset, itop, addtimedisplayWidth, iheight, 0, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, addtimedisplay, additionalInfoColor, additionalInfoColorSelected, backgroundColor, backgroundColorSel))
addoffset = addtimedisplayWidth + textOffset
if not showEventNameUnderServiceName or self.mode != self.MODE_FAVOURITES:
xoffset += addoffset # move xoffset only if not showEventNameUnderServiceName
rwidth -= addoffset
elif additionalposition == "1":
rwidth -= addtimedisplayWidth + textOffset
# service description
if (secondlineinfo != "0" or showEventNameUnderServiceName) and self.mode == self.MODE_FAVOURITES:
top = 0
sheight = height
sxoffset = xoffset
if showEventNameUnderServiceName: # eventname in second line
eWidth = servicenameWidth
if showListNumbers and listNumerPosition=="1":
eWidth += listnumberwidth
if showServiceName:
top = self.serviceInfoHeight
sheight = height - self.serviceInfoHeight
sxoffset = xoffset_ServiceName
if secondlineinfo == "0":
eWidth = width - xoffset_ServiceName
res.append((eListboxPythonMultiContent.TYPE_TEXT, sxoffset, top, eWidth, sheight, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, event.getEventName(), serviceDescriptionColor, serviceDescriptionColorSelected, backgroundColor, backgroundColorSel))
else: # eventname in next column (don't use second line)
sheight = height - self.serviceInfoHeight
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, top, rwidth, sheight, 3, RT_HALIGN_LEFT|RT_VALIGN_CENTER, event.getEventName(), serviceDescriptionColor, serviceDescriptionColorSelected, backgroundColor, backgroundColorSel))
text = ""
if secondlineinfo == "1": # shortdescription
text = event.getShortDescription()
elif secondlineinfo == "2": # next event with time
event_next = eEPGCache.getInstance().lookupEventTime(service, -1, 1)
if event_next:
beginTime = localtime(event_next.getBeginTime())
endTime = localtime(event_next.getBeginTime()+event_next.getDuration())
text = "%02d:%02d - %02d:%02d %s" % (beginTime[3],beginTime[4],endTime[3],endTime[4], event_next.getEventName())
else:
text = "%s: n/a" % _("upcoming event")
awidth = rwidth
if showEventNameUnderServiceName:
awidth = width - xoffset - textOffset # use full width for addInfo if showEventNameUnderServiceName
# add text-value for addInfo in second line
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, self.serviceInfoHeight, awidth, height - self.serviceInfoHeight, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, text, additionalInfoColor, additionalInfoColorSelected, backgroundColor, backgroundColorSel))
else:
# add eventname in next column (if not use the second line)
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, rwidth, height, 3, RT_HALIGN_LEFT|RT_VALIGN_CENTER, event.getEventName(), serviceDescriptionColor, serviceDescriptionColorSelected, backgroundColor, backgroundColorSel))
# progressbar after service description
xoffset += rwidth
if drawProgressbar and progressbarPosition == "2":
if showEventNameUnderServiceName and addtimedisplay != "" and self.mode == self.MODE_FAVOURITES:
xoffset += addoffset # move xoffset if showEventNameUnderServiceName
xoffset += self._progressBarWidth(withOffset=True, withProgressBarSize=False)
res.append(self._buildOptionEntryProgressBar(event, xoffset, width, height))
xoffset += progressBarWidth
# add time text at last position
if addtimedisplay != "" and additionalposition == "1":
aheight = height
if showEventNameUnderServiceName and showServiceName and self.mode != self.MODE_NORMAL:
aheight = height - self.serviceInfoHeight
xoffset += textOffset
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, addtimedisplayWidth , aheight, 0, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, addtimedisplay, additionalInfoColor, additionalInfoColorSelected, backgroundColor, backgroundColorSel))
# normal style, no columnStyle
else:
if event and isPlayable:
maxLength = width - xoffset
if drawProgressbar and progressbarPosition == "2":
# progressbar after service description
maxLength -= progressBarWidth
sheight = height
firstxoffset = xoffset
# set new high if event under servicename
if showEventNameUnderServiceName and self.mode == self.MODE_FAVOURITES:
#sheight = self.serviceInfoHeight
sheight = height - self.serviceInfoHeight
# servicenumber
if self.mode != self.MODE_NORMAL:
if not (service.flags & eServiceReference.isMarker) and showListNumbers and listNumerPosition=="1":
markers_before = self.l.getNumMarkersBeforeCurrent()
servicenumberformat = config.usage.configselection_listnumberformat.value
text = servicenumberformat % (self.numberoffset + index + 1 - markers_before)
nameWidthmax = self._componentSizes.get(self.KEY_SERVICE_NUMBER_WIDTH, 50)
nameWidth = self._calcTextWidth(text, font=self.serviceNumberFont, size=eSize(width,0)) + textOffset
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, nameWidth , sheight, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, text, forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
xoffset += nameWidth
# servicename without tabstyle
length = self._calcTextWidth(serviceName, font=self.serviceNameFont, size=eSize(maxLength,0)) + textOffset
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, length , sheight, 2, RT_HALIGN_LEFT|RT_VALIGN_CENTER, serviceName, forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
xoffset += length
if addtimedisplay != "":
addtimedisplayFormat = "(%s %s)"
if showEventNameUnderServiceName and self.mode == self.MODE_FAVOURITES:
addtimedisplayFormat = "%s %s"
if additionalposition == "1":
# add time text after service description
text = addtimedisplayFormat % (event.getEventName(), addtimedisplay)
else:
# add time text before service description
text = addtimedisplayFormat % (addtimedisplay, event.getEventName())
else:
# add eventName
addtimedisplayFormat = "(%s)"
if showEventNameUnderServiceName and self.mode == self.MODE_FAVOURITES:
addtimedisplayFormat = "%s"
text = addtimedisplayFormat % (event.getEventName())
length = width - xoffset
if drawProgressbar and progressbarPosition == "2":
# progressbar after service description - calculate width of service description
length -= progressBarWidth
# size/pos-Values for add service description from variable text
dheight = height
dxoffset = xoffset
top = 0
dWidth = length
fontsize = 3
# set new size/pos-Values if event under servicename
if showEventNameUnderServiceName and self.mode == self.MODE_FAVOURITES:
top = self.serviceInfoHeight
dheight = height - self.serviceInfoHeight
dxoffset = firstxoffset
dWidth = width - firstxoffset
fontsize = 0
# add service description from variable text
res.append((eListboxPythonMultiContent.TYPE_TEXT, dxoffset, top, dWidth , dheight, fontsize, RT_HALIGN_LEFT|RT_VALIGN_CENTER, text, serviceDescriptionColor, serviceDescriptionColorSelected, backgroundColor, backgroundColorSel))
# add progressbar after service description
if drawProgressbar and progressbarPosition == "2":
xoffset += length + textOffset / 2
res.append(self._buildOptionEntryProgressBar(event, xoffset, width, height))
# only servicename if don't have an event
else:
sheight = height
# set new high of the content if show event under servicename
if showEventNameUnderServiceName and not isMarker and self.mode == self.MODE_FAVOURITES:
sheight = self.serviceInfoHeight
# servicenumber
if self.mode != self.MODE_NORMAL:
if not (service.flags & eServiceReference.isMarker) and showListNumbers and listNumerPosition=="1":
markers_before = self.l.getNumMarkersBeforeCurrent()
servicenumberformat = config.usage.configselection_listnumberformat.value
text = servicenumberformat % (self.numberoffset + index + 1 - markers_before)
nameWidthmax = self._componentSizes.get(self.KEY_SERVICE_NUMBER_WIDTH, 50)
nameWidth = self._calcTextWidth(text, font=self.serviceNumberFont, size=eSize(width,0)) + textOffset
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, nameWidth , sheight, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, text, forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
xoffset += nameWidth
# servicename
res.append((eListboxPythonMultiContent.TYPE_TEXT, xoffset, 0, width - xoffset , sheight, 2, RT_HALIGN_LEFT|RT_VALIGN_CENTER, serviceName, forgroundColor, forgroundColorSel, backgroundColor, backgroundColorSel))
return res
def applySkin(self, desktop, parent):
attribs = [ ]
for (attrib, value) in self.skinAttributes:
if attrib == "foregroundColorMarked":
self.markedForeground = parseColor(value)
elif attrib == "foregroundColorMarkedSelected":
self.markedForegroundSelected = parseColor(value)
elif attrib == "backgroundColorMarked":
self.markedBackground = parseColor(value)
elif attrib == "backgroundColorMarkedSelected":
self.markedBackgroundSelected = parseColor(value)
elif attrib == "foregroundColorServiceNotAvail":
self.serviceNotAvail = parseColor(value)
elif attrib == "colorEventProgressbar":
self.serviceEventProgressbarColor = parseColor(value)
elif attrib == "colorEventProgressbarSelected":
self.serviceEventProgressbarColorSelected = parseColor(value)
elif attrib == "forgroundColorEventProgressbarBorder":
self.serviceEventProgressbarBackColor = parseColor(value)
elif attrib == "backgroundColorEventProgressbarBorderSelected":
self.serviceEventProgressbarBackColorSelected = parseColor(value)
elif attrib == "colorEventProgressbarBorder":
self.serviceEventProgressbarBorderColor = parseColor(value)
elif attrib == "colorEventProgressbarBorderSelected":
self.serviceEventProgressbarBorderColorSelected = parseColor(value)
elif attrib == "colorServiceDescription":
self.serviceDescriptionColor = parseColor(value)
elif attrib == "colorServiceDescriptionSelected":
self.serviceDescriptionColorSelected = parseColor(value)
elif attrib == "colorRecording":
self.recordingColor = parseColor(value)
elif attrib == "colorRecordingSelected":
self.recordingColorSelected = parseColor(value)
elif attrib == "colorAdditionalInfo":
self.additionalInfoColor = parseColor(value)
elif attrib == "colorAdditionalInfoSelected":
self.additionalInfoColorSelected = parseColor(value)
elif attrib == "picServiceEventProgressbar":
pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, value))
if pic:
self.picServiceEventProgressbar = pic
elif attrib == "serviceItemHeight":
self.itemHeight = int(value)
elif attrib == "serviceItemHeightHigh":
self.itemHeightHigh = int(value)
elif attrib == "serviceNameFont":
self.l.setFont(2, parseFont(value, ((1,1),(1,1))))
self.serviceNameFont = parseFont(value, ((1,1),(1,1)))
elif attrib == "serviceInfoFont":
self.l.setFont(3, parseFont(value, ((1,1),(1,1))))
name, size = value.split(';')
self.serviceInfoFontHeight = int(size)
elif attrib == "serviceNumberFont":
self.l.setFont(1, parseFont(value, ((1,1),(1,1))))
self.serviceNumberFont = parseFont(value, ((1,1),(1,1)))
elif attrib == "additionalInfoFont":
self.l.setFont(0, parseFont(value, ((1,1),(1,1))))
self.additionalInfoFont = parseFont(value, ((1,1),(1,1)))
elif attrib == "selectionPixmap":
pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, value))
if pic:
self.selectionPixmapStandard = pic
if not config.usage.configselection_bigpicons.value:
self.instance.setSelectionPicture(self.selectionPixmapStandard)
elif attrib == "selectionPixmapHigh":
pic = LoadPixmap(resolveFilename(SCOPE_CURRENT_SKIN, value))
if pic:
self.selectionPixmapBig = pic
if config.usage.configselection_bigpicons.value:
self.instance.setSelectionPicture(self.selectionPixmapBig)
else:
attribs.append((attrib, value))
self.skinAttributes = attribs
return GUIComponent.applySkin(self, desktop, parent)
def preWidgetRemove(self, instance):
if self.session:
self.session.nav.RecordTimer.on_state_change.remove(self.onTimerEntryStateChange)
instance.setContent(None)
self.selectionChanged_conn = None
config.usage.configselection_showrecordings.removeNotifier(self.getRecordingList)
config.usage.configselection_bigpicons.removeNotifier(self.setItemHeight)
config.usage.configselection_secondlineinfo.removeNotifier(self.setItemHeight)
config.usage.configselection_showeventnameunderservicename.removeNotifier(self.setItemHeight)
self.piconLoader.finish()