improve this a bit
[vuplus_dvbapp-plugin] / 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 enigma import eListboxPythonMultiContent, gFont, RT_HALIGN_LEFT, \
8         RT_HALIGN_RIGHT, RT_VALIGN_CENTER
9
10 from skin import parseColor, parseFont
11
12 from ServiceReference import ServiceReference
13 from Tools.FuzzyDate import FuzzyTime
14
15 class AutoTimerList(MenuList):
16         """Defines a simple Component to show Timer name"""
17
18         def __init__(self, entries):
19                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
20
21                 self.l.setFont(0, gFont("Regular", 22))
22                 self.l.setBuildFunc(self.buildListboxEntry)
23                 self.l.setItemHeight(25)
24                 self.colorDisabled = 12368828
25
26         def applySkin(self, desktop, parent):
27                 attribs = [ ] 
28                 if self.skinAttributes is not None:
29                         for (attrib, value) in self.skinAttributes:
30                                 if attrib == "font":
31                                         self.l.setFont(0, parseFont(value, ((1,1),(1,1))))
32                                 elif attrib == "itemHeight":
33                                         self.l.setItemHeight(int(value))
34                                 elif attrib == "colorDisabled":
35                                         self.colorDisabled = int(parseColor(value))
36                                 else:
37                                         attribs.append((attrib, value))
38                 self.skinAttributes = attribs
39                 return MenuList.applySkin(self, desktop, parent)
40
41         #
42         #  | <Name of AutoTimer> |
43         #
44         def buildListboxEntry(self, timer):
45                 size = self.l.getItemSize()
46
47                 color = None
48                 if not timer.enabled:
49                         color = self.colorDisabled
50
51                 return [
52                         None,
53                         (eListboxPythonMultiContent.TYPE_TEXT, 5, 0, size.width() - 5, size.height(), 0, RT_HALIGN_LEFT, timer.name, color, color)
54                 ]
55
56         def getCurrent(self):
57                 cur = self.l.getCurrentSelection()
58                 return cur and cur[0]
59
60         def moveToEntry(self, entry):
61                 if entry is None:
62                         return
63
64                 idx = 0
65                 for x in self.list:
66                         if x[0] == entry:
67                                 self.instance.moveSelectionTo(idx)
68                                 break
69                         idx += 1
70
71 class AutoTimerPreviewList(MenuList):
72         """Preview Timers, emulates TimerList"""
73
74         def __init__(self, entries):
75                 MenuList.__init__(self, entries, False, content = eListboxPythonMultiContent)
76
77                 self.serviceNameFont = gFont("Regular", 20)
78                 self.l.setFont(0, self.serviceNameFont)
79                 self.font = gFont("Regular", 18)
80                 self.l.setFont(1, self.font)
81                 self.l.setBuildFunc(self.buildListboxEntry)
82                 self.l.setItemHeight(70)
83
84         def applySkin(self, desktop, parent):
85                 attribs = [ ] 
86                 if self.skinAttributes is not None:
87                         for (attrib, value) in self.skinAttributes:
88                                 if attrib == "font":
89                                         self.font = parseFont(value, ((1,1),(1,1)))
90                                         self.l.setFont(1, self.font)
91                                 elif attrib == "serviceNameFont":
92                                         self.serviceNameFont = parseFont(value, ((1,1),(1,1)))
93                                         self.l.setFont(0, self.serviceNameFont)
94                                 elif attrib == "colorDisabled":
95                                         self.colorDisabled = int(parseColor(value))
96                                 elif attrib == "itemHeight":
97                                         self.l.setItemHeight(int(value))
98                                 else:
99                                         attribs.append((attrib, value))
100                 self.skinAttributes = attribs
101                 return MenuList.applySkin(self, desktop, parent)
102
103         #
104         #  | <Service>     <Name of the Event>  |
105         #  | <start, end>  <Name of AutoTimer>  |
106         #
107         def buildListboxEntry(self, name, begin, end, serviceref, timername):
108                 size = self.l.getItemSize()
109                 width = size.width()
110                 snameHeight = self.serviceNameFont.pointSize + 10
111                 fontSize = self.font.pointSize + 2
112                 lastRow = snameHeight + fontSize
113
114                 return [
115                         None,
116                         (eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, snameHeight, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, \
117                                         ServiceReference(serviceref).getServiceName().replace('\xc2\x86', '').replace('\xc2\x87', '')),
118                         (eListboxPythonMultiContent.TYPE_TEXT, 0, snameHeight, width, fontSize, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, name),
119                         (eListboxPythonMultiContent.TYPE_TEXT, 0, lastRow, 400, fontSize, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, \
120                                         (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(begin) + FuzzyTime(end)[1:] + ((end - begin) / 60,)))),
121                         (eListboxPythonMultiContent.TYPE_TEXT, width - 245, lastRow, 240, fontSize, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, timername)
122                 ]
123
124         def invalidate(self):
125                 self.l.invalidate()
126
127         def moveToEntry(self, entry):
128                 if entry is None:
129                         return
130
131                 idx = 0
132                 for x in self.list:
133                         if x == entry:
134                                 self.instance.moveSelectionTo(idx)
135                                 break
136                         idx += 1
137