Show Overview by default (Setup when no feeds are present),
[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(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(100)
38                 instance.selectionChanged.get().append(self.selectionChanged)
39
40         def buildListboxEntry(self, title, link, summary, enclosures):
41                 res = [ None ]
42                 width = self.l.getItemSize().width()
43                 res.append(MultiContentEntryText(pos=(0, 0), size=(width, 75), font=0, flags = RT_HALIGN_LEFT|RT_WRAP, text = title))
44                 res.append(MultiContentEntryText(pos=(0, 75), size=(width, 20), font=1, flags = RT_HALIGN_LEFT, text = link))
45                 return res
46
47         def getCurrentEntry(self):
48                 return self.l.getCurrentSelection()
49
50         def getCurrentIndex(self):
51                 return self.instance.getCurrentIndex()
52
53         def moveToIndex(self, index):
54                 self.instance.moveSelectionTo(index)
55
56         def moveToEntry(self, entry):
57                 if entry is None:
58                         return
59
60                 count = 0
61                 for x in self.list:
62                         if entry[0] == x[0]:
63                                 self.instance.moveSelectionTo(count)
64                                 break
65                         count += 1
66
67         def moveDown(self):
68                 self.instance.moveSelection(self.instance.moveDown)
69
70         def moveUp(self):
71                 self.instance.moveSelection(self.instance.moveUp)