add prewidgetremove,
[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         def preWidgetRemove(self, instance):
28                 instance.setContent(None)
29
30         #
31         #  | <Name of AutoTimer> |
32         #
33         def buildListboxEntry(self, timer):
34                 res = [ None ]
35                 width = self.l.getItemSize().width()
36
37                 if timer.enabled:
38                         # Append with default color
39                         res.append(MultiContentEntryText(pos=(5, 0), size=(width, 25), font=0, flags = RT_HALIGN_LEFT, text = timer.name))
40                 else:
41                         # Append with grey as color
42                         res.append(MultiContentEntryText(pos=(5, 0), size=(width, 25), font=0, flags = RT_HALIGN_LEFT, text = timer.name, color = 12368828))
43
44                 return res
45
46         def getCurrent(self):
47                 return self.l.getCurrentSelection()
48
49         def setList(self, l):
50                 return self.l.setList(l)
51
52 class AutoTimerPreviewList(GUIComponent):
53         """Preview Timers, emulates TimerList"""
54         
55         def __init__(self, entries):
56                 GUIComponent.__init__(self)
57
58                 self.list = entries
59                 self.l = eListboxPythonMultiContent()
60                 self.l.setFont(0, gFont("Regular", 20))
61                 self.l.setFont(1, gFont("Regular", 18))
62                 self.l.setBuildFunc(self.buildListboxEntry)
63                 self.l.setList(self.list)
64
65         GUI_WIDGET = eListbox
66
67         def postWidgetCreate(self, instance):
68                 instance.setContent(self.l)
69                 instance.setItemHeight(70)
70
71         def preWidgetRemove(self, instance):
72                 instance.setContent(None)
73
74         #
75         #  | <Service>     <Name of the Event>  |
76         #  | <start, end>  <Name of AutoTimer>  |
77         #
78         def buildListboxEntry(self, name, begin, end, serviceref, timername):
79                 res = [ None ]
80                 width = self.l.getItemSize().width()
81
82                 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', '')))
83                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, width, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, name))
84
85                 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,)))))
86
87                 res.append((eListboxPythonMultiContent.TYPE_TEXT, width-240, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, timername))
88
89                 return res
90
91         def invalidate(self):
92                 self.l.invalidate()
93
94         def getCurrent(self):
95                 return self.l.getCurrentSelection()
96
97         def setList(self, l):
98                 return self.l.setList(l)
99
100         def moveToEntry(self, entry):
101                 if entry is None:
102                         return
103
104                 idx = 0
105                 for x in self.list:
106                         if x == entry:
107                                 self.instance.moveSelectionTo(idx)
108                                 break
109                         idx += 1