1 from Components.Converter.StringList import StringList
3 class TemplatedMultiContent(StringList):
4 """Turns a python tuple list into a multi-content list which can be used in a listbox renderer."""
5 def __init__(self, args):
6 StringList.__init__(self, args)
7 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, RT_HALIGN_CENTER, RT_HALIGN_RIGHT, RT_VALIGN_TOP, RT_VALIGN_CENTER, RT_VALIGN_BOTTOM, RT_WRAP
8 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmap, MultiContentEntryPixmapAlphaTest, MultiContentTemplateColor, MultiContentEntryProgress
10 del l["self"] # cleanup locals a bit
13 self.template = eval(args, {}, l)
14 self.active_style = None
15 assert "fonts" in self.template
16 assert "itemHeight" in self.template
17 assert "template" in self.template or "templates" in self.template
18 assert "template" in self.template or "default" in self.template["templates"] # we need to have a default template
20 if not "template" in self.template: # default template can be ["template"] or ["templates"]["default"]
21 self.template["template"] = self.template["templates"]["default"][1]
22 self.template["itemHeight"] = self.template["template"][0]
24 def changed(self, what):
26 from enigma import eListboxPythonMultiContent
27 self.content = eListboxPythonMultiContent()
30 # also setup fonts (also given by source)
32 for f in self.template["fonts"]:
33 self.content.setFont(index, f)
36 # if only template changed, don't reload list
37 if what[0] == self.CHANGED_SPECIFIC and what[1] == "style":
42 self.content.setList(self.source.list)
45 self.downstream_elements.changed(what)
47 def setTemplate(self):
49 style = self.source.style
50 if style == self.active_style:
51 return # style did not change
53 # if skin defined "templates", that means that it defines multiple styles in a dict. template should still be a default
54 templates = self.template.get("templates")
55 template = self.template.get("template")
56 itemheight = self.template["itemHeight"]
58 if templates and style and style in templates: # if we have a custom style defined in the source, and different templates in the skin, look it up
59 template = templates[style][1]
60 itemheight = templates[style][0]
62 self.content.setTemplate(template)
64 self.content.setItemHeight(itemheight)