Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/python/Components/Addons/ScreenHeader.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ def applySkin(self, desktop, parent):
for (attrib, value) in self.skinAttributes[:]:
if attrib == "titleFont":
self.titleFont = parseFont(value, parent.scale)
if attrib == "titleSingleFont":
elif attrib == "titleSingleFont":
self.titleSingleFont = parseFont(value, parent.scale)
elif attrib == "pathFont":
self.pathFont = parseFont(value, parent.scale)
Expand Down
4 changes: 4 additions & 0 deletions lib/python/Components/ConfigList.py
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,10 @@ def applySkin(self, desktop, screen):
self.sepLineColor = parseColor(value).argb()
elif attrib == "sepLineThickness":
self.sepLineThickness = int(value)
elif attrib == "separatorLineColor":
self.sepLineColor = parseColor(value).argb()
elif attrib == "separatorLineSize":
self.sepLineThickness = int(value)
else:
attribs.append((attrib, value))
self.skinAttributes = attribs
Expand Down
178 changes: 177 additions & 1 deletion lib/python/Components/Converter/EventName.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,155 @@
from time import time, localtime


class ETSIClassifications(dict):
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
COLORS = (0x000000, 0x00A822, 0x00A822, 0x00A822, 0x007DCA, 0x007DCA, 0x007DCA, 0xFF7900, 0xFF7900, 0xFF7900, 0xFF5594, 0xFF5594, 0xFF5594, 0xD70723, 0xD70723, 0xD70723)

def shortRating(self, age):
if age == 0:
return _("All ages")
elif age <= 15:
age += 3
return " %d+" % age

def longRating(self, age):
if age == 0:
return _("Rating undefined")
elif age <= 15:
age += 3
return _("Minimum age %d years") % age

def imageRating(self, age):
if age == 0:
return "ratings/ETSI-ALL.png"
elif age <= 15:
age += 3
return "ratings/ETSI-%d.png" % age

def colorRating(self, age):
return self.COLORS[age]

def __init__(self):
self.update([(i, (self.shortRating(c), self.longRating(c), self.imageRating(c), self.colorRating(i))) for i, c in enumerate(range(0, 16))])


class AusClassifications(dict):
# In Australia "Not Classified" (NC) is to be displayed as an empty string.
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
SHORTTEXT = ("", "", "P", "P", "C", "C", "G", "G", "PG", "PG", "M", "M", "MA", "MA", "AV", "R")
LONGTEXT = {
"": _("Not Classified"),
"P": _("Preschool"),
"C": _("Children"),
"G": _("General"),
"PG": _("Parental Guidance Recommended"),
"M": _("Mature Audience 15+"),
"MA": _("Mature Adult Audience 15+"),
"AV": _("Adult Audience, Strong Violence 15+"),
"R": _("Restricted 18+")
}
IMAGES = {
"": "ratings/blank.png",
"P": "ratings/AUS-P.png",
"C": "ratings/AUS-C.png",
"G": "ratings/AUS-G.png",
"PG": "ratings/AUS-PG.png",
"M": "ratings/AUS-M.png",
"MA": "ratings/AUS-MA.png",
"AV": "ratings/AUS-AV.png",
"R": "ratings/AUS-R.png"
}

# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
COLORS = (0x000000, 0x00A822, 0x00A822, 0x00A822, 0x007DCA, 0x007DCA, 0x007DCA, 0xFF7900, 0xFF7900, 0xFF7900, 0xFF5594, 0xFF5594, 0xFF5594, 0xD70723, 0xD70723, 0xD70723)

def __init__(self):
self.update([(i, (c, self.LONGTEXT[c], self.IMAGES[c], self.COLORS[i])) for i, c in enumerate(self.SHORTTEXT)])


class GBrClassifications(dict):
# British Board of Film Classification
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
SHORTTEXT = ("", "", "", "U", "U", "U", "PG", "PG", "PG", "12", "12", "12", "15", "15", "15", "18")
LONGTEXT = {
"": _("Not Classified"),
"U": _("U - Suitable for all"),
"PG": _("PG - Parental Guidance"),
"12": _("Suitable for ages 12+"),
"15": _("Suitable for ages 15+"),
"18": _("Suitable only for Adults")
}
IMAGES = {
"": "ratings/blank.png",
"U": "ratings/GBR-U.png",
"PG": "ratings/GBR-PG.png",
"12": "ratings/GBR-12.png",
"15": "ratings/GBR-15.png",
"18": "ratings/GBR-18.png"
}

# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
COLORS = (0x000000, 0x000000, 0x000000, 0x00A822, 0x00A822, 0x00A822, 0xFAB800, 0xFAB800, 0xFAB800, 0xFF7900, 0xFF7900, 0xFF7900, 0xFF5594, 0xFF5594, 0xFF5594, 0xD70723)

def __init__(self):
self.update([(i, (c, self.LONGTEXT[c], self.IMAGES[c], self.COLORS[i])) for i, c in enumerate(self.SHORTTEXT)])


class ItaClassifications(dict):
# The classifications used by Sky Italia
# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
SHORTTEXT = ("", "", "", "T", "T", "T", "BA", "BA", "BA", "12", "12", "12", "14", "14", "14", "18")
LONGTEXT = {
"": _("Non Classificato"),
"T": _("Per Tutti"),
"BA": _("Bambini Accompagnati"),
"12": _("Dai 12 anni in su"),
"14": _("Dai 14 anni in su"),
"18": _("Dai 18 anni in su")
}
IMAGES = {
"": "ratings/blank.png",
"T": "ratings/ITA-T.png",
"BA": "ratings/ITA-BA.png",
"12": "ratings/ITA-12.png",
"14": "ratings/ITA-14.png",
"18": "ratings/ITA-18.png"
}

# 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
COLORS = (0x000000, 0x00A822, 0x00A822, 0x00A822, 0x007DCA, 0x007DCA, 0x007DCA, 0xFF7900, 0xFF7900, 0xFF7900, 0xFF5594, 0xFF5594, 0xFF5594, 0xD70723, 0xD70723, 0xD70723)

def __init__(self):
self.update([(i, (c, self.LONGTEXT[c], self.IMAGES[c], self.COLORS[i])) for i, c in enumerate(self.SHORTTEXT)])


# Each country classification object in the map tuple must be an object that
# supports obj.get(key[, default]). It need not actually be a dict object.
#
# The other element is how the rating number should be formatted if there
# is no match in the classification object.
#
# If there is no matching country then the default ETSI should be selected.

countries = {
"ETSI": (ETSIClassifications(), lambda age: (_("bc%d") % age, _("Rating defined by broadcaster - %d") % age, "ratings/ETSI-na.png")),
"AUS": (AusClassifications(), lambda age: (_("BC%d") % age, _("Rating defined by broadcaster - %d") % age, "ratings/AUS-na.png")),
"GBR": (GBrClassifications(), lambda age: (_("BC%d") % age, _("Rating defined by broadcaster - %d") % age, "ratings/GBR-na.png")),
"ITA": (ItaClassifications(), lambda age: (_("BC%d") % age, _("Rating defined by broadcaster - %d") % age, "ratings/ITA-na.png"))
}


# OpenTV country codes: epgchanneldata.cpp
# eEPGChannelData::getOpenTvParentalRating
opentv_countries = {
"OT1": "GBR",
"OT2": "ITA",
"OT3": "AUS",
"OT4": "NZL",
"OTV": "ETSI"
}


class EventName(Converter):
NAME = 0
SHORT_DESCRIPTION = 1
Expand All @@ -24,6 +173,16 @@ class EventName(Converter):
FORMAT_STRING = 14
RAWRATING = 15

RAWRATINGANDCOUNTRY = 30

RATSHORT = 0
RATLONG = 1
RATICON = 2
RATCOLOR = 3

RATNORMAL = 0
RATDEFAULT = 1

def __init__(self, type):
Converter.__init__(self, type)
self.parts = [(arg.strip() if i else arg) for i, arg in enumerate(type.split(","))]
Expand Down Expand Up @@ -59,6 +218,8 @@ def __init__(self, type):
self.type = self.ISRUNNINGSTATUS
elif type == "RawRating":
self.type = self.RAWRATING
elif type == "RawRatingAndCountry":
self.type = self.RAWRATINGANDCOUNTRY
else:
self.type = self.NAME

Expand Down Expand Up @@ -168,6 +329,21 @@ def getText(self):
rating = event.getParentalData()
if rating:
return "%d" % rating.getRating()
elif self.type == self.RAWRATINGANDCOUNTRY:
rating = event.getParentalData()
if rating:
age = rating.getRating()
country = rating.getCountryCode().upper()
if country in opentv_countries:
country = opentv_countries[country]
if country in countries:
c = countries[country]
else:
c = countries["ETSI"]
rating = c[self.RATNORMAL].get(age, c[self.RATDEFAULT](age))
ageText = rating[self.RATSHORT].strip().replace("+", "")
color = rating[self.RATCOLOR]
return "%s;%s" % (ageText, hex(color))
elif self.type == self.FORMAT_STRING:
begin = event.getBeginTime()
end = begin + event.getDuration()
Expand All @@ -181,7 +357,7 @@ def getText(self):
duration = event.getDuration()
duration_str = "%d min" % (duration / 60)
start_time_str = "%2d:%02d" % (t_start.tm_hour, t_start.tm_min)
end_time_str = "%2d:%02d" % (t_end.tm_hour, t_end.tm_min)
end_time_str = "%2d:%02d" % (t_end.tm_hour, t_end.tm_min)
name = event.getEventName()
res_str = ""
for x in self.parts[1:]:
Expand Down
59 changes: 46 additions & 13 deletions lib/python/Components/Renderer/RatingIconLabel.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ class RatingIconLabel(Renderer):
def __init__(self):
Renderer.__init__(self)
self.colors = {}
self.extendDirection = "right"
self.sidesMargin = 20

GUI_WIDGET = eLabel

Expand All @@ -18,32 +20,63 @@ def applySkin(self, desktop, parent):
for (attrib, value) in self.skinAttributes:
if attrib == "colors":
self.colors = {int(k): parseColor(v) for k, v in (item.split(":") for item in value.split(","))}
elif attrib == "extendDirection":
self.extendDirection = value
elif attrib == "sidesMargin":
self.sidesMargin = int(value)
else:
attribs.append((attrib, value))
self.skinAttributes = attribs
rc = Renderer.applySkin(self, desktop, parent)
result = Renderer.applySkin(self, desktop, parent)
self.changed((self.CHANGED_DEFAULT,))
return rc
return result

def hideLabel(self):
self.instance.setText("")
self.instance.hide()
if self.instance:
self.instance.setText("")
self.instance.hide()

def changed(self, what):
self.hideLabel() # initially hide the label
if self.source and hasattr(self.source, "text") and self.instance:
if what[0] == self.CHANGED_CLEAR:
self.hideLabel()
else:
if self.source.text:
age = int(self.source.text.replace("+", ""))
if age == 0:
self.hideLabel()
return
if age <= 15:
age += 3

self.instance.setText(str(age))
self.instance.setBackgroundColor(gRGB(self.colors.get(age, 0x10000000)))
color = 0x00000000
ageText = ""
if ";" in self.source.text:
split_text = self.source.text.split(";")
if not split_text or len(split_text) == 1 or not split_text[0]:
self.hideLabel()
return
ageText = split_text[0]
color = int(split_text[1], 16)
else:
age = int(self.source.text.replace("+", ""))
if age <= 15:
age += 3
ageText = str(age)
color = self.colors.get(age, 0x10000000)

size = self.instance.size()
pos = self.instance.position()
self.instance.setNoWrap(1)
self.instance.setText(ageText)
textSize = self.instance.calculateSize()
self.instance.setNoWrap(0)
newWidth = textSize.width() + self.sidesMargin
if newWidth < size.width():
newWidth = size.width()

if self.extendDirection == "left":
rightEdgePos = pos.x() + size.width()
self.move(rightEdgePos - newWidth, pos.y())

if self.extendDirection != "none":
self.resize(newWidth, size.height())

self.instance.setBackgroundColor(gRGB(color))
self.instance.show()
else:
self.hideLabel()