reduce ammount of try/except-blocks used,
[vuplus_dvbapp-plugin] / 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         def getCurrent(self):
40                 cur = self.l.getCurrentSelection()
41                 return cur and cur[0]
42
43         def moveToEntry(self, entry):
44                 if entry is None:
45                         return
46
47                 idx = 0
48                 for x in self.list:
49                         if x[0] == entry:
50                                 self.instance.moveSelectionTo(idx)
51                                 break
52                         idx += 1
53
54 class AutoTimerPreviewList(MenuList):
55         """Preview Timers, emulates TimerList"""
56         
57         def __init__(self, entries):
58                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
59
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.setItemHeight(70)
64
65         #
66         #  | <Service>     <Name of the Event>  |
67         #  | <start, end>  <Name of AutoTimer>  |
68         #
69         def buildListboxEntry(self, name, begin, end, serviceref, timername):
70                 res = [ None ]
71                 width = self.l.getItemSize().width()
72
73                 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', '')))
74                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, width, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, name))
75
76                 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,)))))
77
78                 res.append((eListboxPythonMultiContent.TYPE_TEXT, width-240, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, timername))
79
80                 return res
81
82         def invalidate(self):
83                 self.l.invalidate()
84
85         def moveToEntry(self, entry):
86                 if entry is None:
87                         return
88
89                 idx = 0
90                 for x in self.list:
91                         if x == entry:
92                                 self.instance.moveSelectionTo(idx)
93                                 break
94                         idx += 1
95