initial checkin of MerlinSkinThemes
[enigma2-plugins.git] / simplerss / src / RSSList.py
1 from Components.MenuList import MenuList
2
3 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
4         RT_WRAP
5
6 from skin import parseFont
7
8 class RSSFeedList(MenuList):
9         def __init__(self, entries):
10                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
11
12                 l = self.l
13                 l.setFont(0, gFont("Regular", 22))
14                 self.descriptionFont = gFont("Regular", 18)
15                 l.setFont(1, self.descriptionFont)
16                 l.setItemHeight(100)
17                 l.setBuildFunc(self.buildListboxEntry)
18
19         def applySkin(self, desktop, parent):
20                 attribs = [ ] 
21                 if self.skinAttributes is not None:
22                         for (attrib, value) in self.skinAttributes:
23                                 if attrib == "font":
24                                         self.l.setFont(0, parseFont(value, ((1,1),(1,1))))
25                                 elif attrib == "descriptionFont":
26                                         self.descriptionFont = parseFont(value, ((1,1),(1,1)))
27                                         self.l.setFont(1, self.descriptionFont)
28                                 elif attrib == "itemHeight":
29                                         self.l.setItemHeight(int(value))
30                                 else:
31                                         attribs.append((attrib, value))
32                 self.skinAttributes = attribs
33                 return MenuList.applySkin(self, desktop, parent)
34
35         def connectSelChanged(self, fnc):
36                 if not fnc in self.onSelectionChanged:
37                         self.onSelectionChanged.append(fnc)
38
39         def disconnectSelChanged(self, fnc):
40                 if fnc in self.onSelectionChanged:
41                         self.onSelectionChanged.remove(fnc)
42
43         def invalidate(self):
44                 self.l.invalidate()
45
46         def moveToEntry(self, feed):
47                 if feed is None:
48                         return
49
50                 idx = 0
51                 for x in self.list:
52                         if feed.uri == x[0].uri:
53                                 self.instance.moveSelectionTo(idx)
54                                 break
55                         idx += 1
56
57         def buildListboxEntry(self, feed):
58                 size = self.l.getItemSize()
59                 width = size.width()
60                 descriptionHeight = self.descriptionFont.pointSize + 2
61                 titleHeight = size.height() - descriptionHeight
62
63                 return [
64                         None,
65                         (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, titleHeight, 0, RT_HALIGN_LEFT|RT_WRAP, feed.title),
66                         (eListboxPythonMultiContent.TYPE_TEXT, 0, titleHeight, width, descriptionHeight, 1, RT_HALIGN_LEFT, feed.description)
67                 ]
68
69         def getCurrent(self):
70                 # We know that the list will never be empty...
71                 return self.l.getCurrentSelection()[0]
72