intial commit of autotimer, epgrefresh and werbezapper to enigma2-plugins
[enigma2-plugins.git] / autotimer / src / AutoTimerList.py
1 # GUI (Components)
2 from Components.GUIComponent import GUIComponent
3 from Components.MultiContent import MultiContentEntryText
4 from enigma import eListboxPythonMultiContent, eListbox, gFont, RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_VALIGN_CENTER
5
6 from ServiceReference import ServiceReference
7 from Tools.FuzzyDate import FuzzyTime
8
9 class AutoTimerList(GUIComponent):
10         """Defines a simple Component to show Timer name"""
11         
12         def __init__(self, entries):
13                 GUIComponent.__init__(self)
14
15                 self.list = entries
16                 self.l = eListboxPythonMultiContent()
17                 self.l.setFont(0, gFont("Regular", 22))
18                 self.l.setBuildFunc(self.buildListboxEntry)
19                 self.l.setList(self.list)
20
21         GUI_WIDGET = eListbox
22
23         def postWidgetCreate(self, instance):
24                 instance.setContent(self.l)
25                 instance.setItemHeight(25)
26
27 #
28 #  | <Name of AutoTimer> |
29 #
30         def buildListboxEntry(self, timer):
31                 res = [ None ]
32                 width = self.l.getItemSize().width()
33
34                 if timer.enabled:
35                         # Append with default color
36                         res.append(MultiContentEntryText(pos=(5, 0), size=(width, 25), font=0, flags = RT_HALIGN_LEFT, text = timer.name))
37                 else:
38                         # Append with grey as color
39                         res.append(MultiContentEntryText(pos=(5, 0), size=(width, 25), font=0, flags = RT_HALIGN_LEFT, text = timer.name, color = 12368828))
40
41                 return res
42
43         def getCurrent(self):
44                 return self.l.getCurrentSelection()
45
46         def setList(self, l):
47                 return self.l.setList(l)
48
49 class AutoTimerPreviewList(GUIComponent):
50         """Preview Timers, emulates TimerList"""
51         
52         def __init__(self, entries):
53                 GUIComponent.__init__(self)
54
55                 self.list = entries
56                 self.l = eListboxPythonMultiContent()
57                 self.l.setFont(0, gFont("Regular", 20))
58                 self.l.setFont(1, gFont("Regular", 18))
59                 self.l.setBuildFunc(self.buildListboxEntry)
60                 self.l.setList(self.list)
61
62         GUI_WIDGET = eListbox
63
64         def postWidgetCreate(self, instance):
65                 instance.setContent(self.l)
66                 instance.setItemHeight(70)
67
68 #
69 #  | <Service>     <Name of the Event>  |
70 #  | <start, end>  <Name of AutoTimer>  |
71 #
72         def buildListboxEntry(self, name, begin, end, serviceref, timername):
73                 res = [ None ]
74                 width = self.l.getItemSize().width()
75
76                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, ServiceReference(serviceref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')))
77                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, width, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, name))
78
79                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(begin) + FuzzyTime(end)[1:] + ((end - begin) / 60,)))))
80
81                 res.append((eListboxPythonMultiContent.TYPE_TEXT, width-240, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, timername))
82
83                 return res
84
85         def invalidate(self):
86                 self.l.invalidate()
87
88         def getCurrent(self):
89                 return self.l.getCurrentSelection()
90
91         def setList(self, l):
92                 return self.l.setList(l)
93
94         def moveToEntry(self, entry):
95                 if entry is None:
96                         return
97
98                 idx = 0
99                 for x in self.list:
100                         if x == entry:
101                                 self.instance.moveSelectionTo(idx)
102                                 break
103                         idx += 1