allow to skin custom lists
[enigma2-plugins.git] / simplerss / src / RSSList.py
1 from Components.MenuList import MenuList
2 from Components.MultiContent import MultiContentEntryText
3
4 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
5         RT_WRAP
6
7 from skin import parseFont
8
9 class RSSBaseList(MenuList):
10         """Base List Component for RSSFeeds."""
11
12         def __init__(self, entries, itemheight):
13                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
14
15                 l = self.l
16                 l.setFont(0, gFont("Regular", 22))
17                 self.descriptionFont = gFont("Regular", 18)
18                 l.setFont(1, self.descriptionFont)
19                 l.setItemHeight(itemheight)
20
21         def applySkin(self, desktop, parent):
22                 attribs = [ ] 
23                 if self.skinAttributes is not None:
24                         for (attrib, value) in self.skinAttributes:
25                                 if attrib == "font":
26                                         self.l.setFont(0, parseFont(value, ((1,1),(1,1))))
27                                 elif attrib == "descriptionFont":
28                                         self.descriptionFont = parseFont(value, ((1,1),(1,1)))
29                                         self.l.setFont(1, self.descriptionFont)
30                                 elif attrib == "itemHeight":
31                                         self.l.setItemHeight(int(value))
32                                 else:
33                                         attribs.append((attrib, value))
34                 self.skinAttributes = attribs
35                 return MenuList.applySkin(self, desktop, parent)
36
37         def connectSelChanged(self, fnc):
38                 if not fnc in self.onSelectionChanged:
39                         self.onSelectionChanged.append(fnc)
40
41         def disconnectSelChanged(self, fnc):
42                 if fnc in self.onSelectionChanged:
43                         self.onSelectionChanged.remove(fnc)
44
45         def moveToEntry(self, identifier):
46                 pass
47
48         def invalidate(self):
49                 self.l.invalidate()
50
51 class RSSFeedList(RSSBaseList):
52         def __init__(self, entries):
53                 RSSBaseList.__init__(self, entries, 100)
54                 self.l.setBuildFunc(self.buildListboxEntry)
55
56         def moveToEntry(self, feed):
57                 if feed is None:
58                         return
59
60                 idx = 0
61                 for x in self.list:
62                         if feed.uri == x[0].uri:
63                                 self.instance.moveSelectionTo(idx)
64                                 break
65                         idx += 1
66
67         def buildListboxEntry(self, feed):
68                 size = self.l.getItemSize()
69                 width = size.width()
70                 descriptionHeight = self.descriptionFont.pointSize + 2
71                 titleHeight = size.height() - descriptionHeight
72
73                 return [
74                         None,
75                         MultiContentEntryText(pos=(0, 0), size=(width, titleHeight), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = feed.title),
76                         MultiContentEntryText(pos=(0, titleHeight), size=(width, descriptionHeight), font=1, flags = RT_HALIGN_LEFT, text = feed.description)
77                 ]
78
79         def getCurrent(self):
80                 # We know that the list will never be empty...
81                 return self.l.getCurrentSelection()[0]
82
83 class RSSEntryList(RSSBaseList):
84         def __init__(self, entries):
85                 RSSBaseList.__init__(self, entries, 50)
86                 self.l.setBuildFunc(self.buildListboxEntry)
87
88         def moveToEntry(self, entry):
89                 if entry is None:
90                         return
91
92                 idx = 0
93                 for x in self.list:
94                         if entry[0] == x[0]:
95                                 self.instance.moveSelectionTo(idx)
96                                 break
97                         idx += 1
98
99         def buildListboxEntry(self, title, link, summary, enclosures):
100                 size = self.l.getItemSize()
101                 return [
102                         None,
103                         MultiContentEntryText(pos=(0, 3), size=(size.width(), size.height() - 3), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = title)
104                 ]
105