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