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
8 from Components.MultiContent import MultiContentEntryText, MultiContentEntryPixmap, MultiContentEntryPixmapAlphaTest
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"]
23 def changed(self, what):
25 from enigma import eListboxPythonMultiContent
26 self.content = eListboxPythonMultiContent()
27 self.content.setItemHeight(self.template["itemHeight"])
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")
57 if templates and style: # if we have a custom style defined in the source, and different templates in the skin, look it up
58 template = templates.get(self.source.style, template) # default to default template
60 self.content.setTemplate(template)