New Items displayed in Feeds,
[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 RSSList(GUIComponent):
6         """Simple List Component used for RSS-Feeds. Displays first two Elements of a 4-Tupel."""
7         def __init__(self, entries):
8                 GUIComponent.__init__(self)
9                 self.list = entries
10                 self.l = eListboxPythonMultiContent()
11                 self.l.setFont(0, gFont("Regular", 22))
12                 self.l.setFont(1, gFont("Regular", 18))
13                 self.l.setBuildFunc(self.buildListboxEntry)
14                 self.l.setList(entries)
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                         x()
29
30         GUI_WIDGET = eListbox
31
32         def postWidgetCreate(self, instance):
33                 instance.setContent(self.l)
34                 instance.setItemHeight(100)
35                 instance.selectionChanged.get().append(self.selectionChanged)
36
37         def buildListboxEntry(self, title, link, summary, enclosures):
38                 res = [ None ]
39                 width = self.l.getItemSize().width()
40                 res.append(MultiContentEntryText(pos=(0, 0), size=(width, 75), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = title))
41                 res.append(MultiContentEntryText(pos=(0, 75), size=(width, 20), font=1, flags = RT_HALIGN_LEFT, text = link))
42                 return res
43
44         def getCurrentEntry(self):
45                 return self.l.getCurrentSelection()
46
47         def getCurrentIndex(self):
48                 return self.instance.getCurrentIndex()
49
50         def moveToIndex(self, index):
51                 self.instance.moveSelectionTo(index)
52
53         def moveToEntry(self, entry):
54                 if entry is None:
55                         return
56
57                 count = 0
58                 for x in self.list:
59                         if entry[0] == x[0]:
60                                 self.instance.moveSelectionTo(count)
61                                 break
62                         count += 1
63
64         def moveDown(self):
65                 self.instance.moveSelection(self.instance.moveDown)
66
67         def moveUp(self):
68                 self.instance.moveSelection(self.instance.moveUp)