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