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, MultiContentEntryPixmapAlphaBlend, MultiContentTemplateColor, MultiContentEntryProgress
10 del l["self"] # cleanup locals a bit
13 self.active_style = None
14 self.template = eval(args, {}, l)
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()
29 # also setup fonts (also given by source)
31 for f in self.template["fonts"]:
32 self.content.setFont(index, f)
35 # if only template changed, don't reload list
36 if what[0] == self.CHANGED_SPECIFIC and what[1] == "style":
39 self.content.setList(self.source.list)
42 self.downstream_elements.changed(what)
44 def setTemplate(self):
46 style = self.source.style
48 if style == self.active_style:
51 # if skin defined "templates", that means that it defines multiple styles in a dict. template should still be a default
52 templates = self.template.get("templates")
53 template = self.template.get("template")
54 itemheight = self.template["itemHeight"]
55 selectionEnabled = self.template.get("selectionEnabled", True)
56 scrollbarMode = self.template.get("scrollbarMode", "showOnDemand")
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]
61 if len(templates[style]) > 2:
62 selectionEnabled = templates[style][2]
63 if len(templates[style]) > 3:
64 scrollbarMode = templates[style][3]
66 self.content.setTemplate(template)
67 self.content.setItemHeight(itemheight)
68 self.selectionEnabled = selectionEnabled
69 self.scrollbarMode = scrollbarMode
70 self.active_style = style