smaller fixes, bump required e2 version, add sample for custom destination path
[enigma2-plugins.git] / autotimer / src / AutoTimerList.py
1 # GUI (Components)
2 from Components.MenuList import MenuList
3 from Components.MultiContent import MultiContentEntryText
4 from enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
5         RT_HALIGN_RIGHT, RT_VALIGN_CENTER
6
7 from ServiceReference import ServiceReference
8 from Tools.FuzzyDate import FuzzyTime
9
10 class AutoTimerList(MenuList):
11         """Defines a simple Component to show Timer name"""
12         
13         def __init__(self, entries):
14                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
15
16                 self.l.setFont(0, gFont("Regular", 22))
17                 self.l.setBuildFunc(self.buildListboxEntry)
18                 self.l.setItemHeight(25)
19
20         #
21         #  | <Name of AutoTimer> |
22         #
23         def buildListboxEntry(self, timer):
24                 res = [ None ]
25                 width = self.l.getItemSize().width()
26
27                 if timer.enabled:
28                         # Append with default color
29                         res.append(MultiContentEntryText(pos=(5, 0), size=(width, 25), font=0, flags = RT_HALIGN_LEFT, text = timer.name))
30                 else:
31                         # Append with grey as color
32                         res.append(MultiContentEntryText(pos=(5, 0), size=(width, 25), font=0, flags = RT_HALIGN_LEFT, text = timer.name, color = 12368828))
33
34                 return res
35
36 class AutoTimerPreviewList(MenuList):
37         """Preview Timers, emulates TimerList"""
38         
39         def __init__(self, entries):
40                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
41
42                 self.l.setFont(0, gFont("Regular", 20))
43                 self.l.setFont(1, gFont("Regular", 18))
44                 self.l.setBuildFunc(self.buildListboxEntry)
45                 self.l.setItemHeight(70)
46
47         #
48         #  | <Service>     <Name of the Event>  |
49         #  | <start, end>  <Name of AutoTimer>  |
50         #
51         def buildListboxEntry(self, name, begin, end, serviceref, timername):
52                 res = [ None ]
53                 width = self.l.getItemSize().width()
54
55                 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', '')))
56                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, width, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, name))
57
58                 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,)))))
59
60                 res.append((eListboxPythonMultiContent.TYPE_TEXT, width-240, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, timername))
61
62                 return res
63
64         def invalidate(self):
65                 self.l.invalidate()
66
67         def moveToEntry(self, entry):
68                 if entry is None:
69                         return
70
71                 idx = 0
72                 for x in self.list:
73                         if x == entry:
74                                 self.instance.moveSelectionTo(idx)
75                                 break
76                         idx += 1