- Fix clipping issues with RSSEntryList
[enigma2-plugins.git] / simplerss / src / RSSList.py
1 from Components.GUIComponent import GUIComponent
2 from Components.MultiContent import MultiContentEntryText
3 from enigma import eListboxPythonMultiContent, eListbox, gFont, RT_HALIGN_LEFT, RT_WRAP
4
5 class RSSBaseList(GUIComponent):
6         """Base List Component for RSSFeeds."""
7         def __init__(self, entries, itemheight):
8                 GUIComponent.__init__(self)
9                 self.list = entries
10                 self.itemheight = itemheight
11                 self.l = eListboxPythonMultiContent()
12                 self.l.setFont(0, gFont("Regular", 22))
13                 self.l.setFont(1, gFont("Regular", 18))
14                 self.l.setList(self.list)
15
16                 self.onSelectionChanged = [ ]
17
18         def connectSelChanged(self, fnc):
19                 if not fnc in self.onSelectionChanged:
20                         self.onSelectionChanged.append(fnc)
21
22         def disconnectSelChanged(self, fnc):
23                 if fnc in self.onSelectionChanged:
24                         self.onSelectionChanged.remove(fnc)
25
26         def selectionChanged(self):
27                 for x in self.onSelectionChanged:
28                         try:
29                                 x()
30                         except:
31                                 pass
32
33         GUI_WIDGET = eListbox
34
35         def postWidgetCreate(self, instance):
36                 instance.setContent(self.l)
37                 instance.setItemHeight(self.itemheight)
38                 instance.selectionChanged.get().append(self.selectionChanged)
39
40         def getCurrentEntry(self):
41                 return self.l.getCurrentSelection()
42
43         def getCurrentIndex(self):
44                 return self.instance.getCurrentIndex()
45
46         def moveToIndex(self, index):
47                 self.instance.moveSelectionTo(index)
48
49         def moveToEntry(self, identifier):
50                 pass
51
52         def moveDown(self):
53                 self.instance.moveSelection(self.instance.moveDown)
54
55         def moveUp(self):
56                 self.instance.moveSelection(self.instance.moveUp)
57
58         def invalidate(self):
59                 self.l.invalidate()
60
61 class RSSFeedList(RSSBaseList):
62         def __init__(self, entries):
63                 RSSBaseList.__init__(self, entries, 100)
64                 self.l.setBuildFunc(self.buildListboxEntry)
65
66         def moveToEntry(self, feed):
67                 if feed is None:
68                         return
69
70                 idx = 0
71                 for x in self.list:
72                         if feed.uri == x[0].uri:
73                                 self.instance.moveSelectionTo(idx)
74                                 break
75                         idx += 1
76
77         def buildListboxEntry(self, feed):
78                 res = [ None ]
79                 width = self.l.getItemSize().width()
80                 res.append(MultiContentEntryText(pos=(0, 0), size=(width, 75), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = feed.title))
81                 res.append(MultiContentEntryText(pos=(0, 75), size=(width, 20), font=1, flags = RT_HALIGN_LEFT, text = feed.description))
82                 return res
83
84         def getCurrentEntry(self):
85                 # We know that the list will never be empty...
86                 return self.l.getCurrentSelection()[0]
87
88 class RSSEntryList(RSSBaseList):
89         def __init__(self, entries):
90                 RSSBaseList.__init__(self, entries, 50)
91                 self.l.setBuildFunc(self.buildListboxEntry)
92
93         def moveToEntry(self, entry):
94                 if entry is None:
95                         return
96
97                 idx = 0
98                 for x in self.list:
99                         if entry[0] == x[0]:
100                                 self.instance.moveSelectionTo(idx)
101                                 break
102                         idx += 1
103
104         def buildListboxEntry(self, title, link, summary, enclosures):
105                 res = [ None ]
106                 width = self.l.getItemSize().width()
107                 res.append(MultiContentEntryText(pos=(0, 3), size=(width, 50), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = title))
108                 return res