drop rssentrylist in favour of a list->templatedmulticontent->listbox chain
[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 RSSFeedList(MenuList):
10         def __init__(self, entries):
11                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
12
13                 l = self.l
14                 l.setFont(0, gFont("Regular", 22))
15                 self.descriptionFont = gFont("Regular", 18)
16                 l.setFont(1, self.descriptionFont)
17                 l.setItemHeight(100)
18                 l.setBuildFunc(self.buildListboxEntry)
19
20         def applySkin(self, desktop, parent):
21                 attribs = [ ] 
22                 if self.skinAttributes is not None:
23                         for (attrib, value) in self.skinAttributes:
24                                 if attrib == "font":
25                                         self.l.setFont(0, parseFont(value, ((1,1),(1,1))))
26                                 elif attrib == "descriptionFont":
27                                         self.descriptionFont = parseFont(value, ((1,1),(1,1)))
28                                         self.l.setFont(1, self.descriptionFont)
29                                 elif attrib == "itemHeight":
30                                         self.l.setItemHeight(int(value))
31                                 else:
32                                         attribs.append((attrib, value))
33                 self.skinAttributes = attribs
34                 return MenuList.applySkin(self, desktop, parent)
35
36         def connectSelChanged(self, fnc):
37                 if not fnc in self.onSelectionChanged:
38                         self.onSelectionChanged.append(fnc)
39
40         def disconnectSelChanged(self, fnc):
41                 if fnc in self.onSelectionChanged:
42                         self.onSelectionChanged.remove(fnc)
43
44         def invalidate(self):
45                 self.l.invalidate()
46
47         def moveToEntry(self, feed):
48                 if feed is None:
49                         return
50
51                 idx = 0
52                 for x in self.list:
53                         if feed.uri == x[0].uri:
54                                 self.instance.moveSelectionTo(idx)
55                                 break
56                         idx += 1
57
58         def buildListboxEntry(self, feed):
59                 size = self.l.getItemSize()
60                 width = size.width()
61                 descriptionHeight = self.descriptionFont.pointSize + 2
62                 titleHeight = size.height() - descriptionHeight
63
64                 return [
65                         None,
66                         MultiContentEntryText(pos=(0, 0), size=(width, titleHeight), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = feed.title),
67                         MultiContentEntryText(pos=(0, titleHeight), size=(width, descriptionHeight), font=1, flags = RT_HALIGN_LEFT, text = feed.description)
68                 ]
69
70         def getCurrent(self):
71                 # We know that the list will never be empty...
72                 return self.l.getCurrentSelection()[0]
73