factor out loadPNG into generic LoadPixmap
[enigma2.git] / lib / python / Components / TimerList.py
1 from HTMLComponent import HTMLComponent
2 from GUIComponent import GUIComponent
3
4 from Tools.FuzzyDate import FuzzyTime
5
6 from enigma import eListboxPythonMultiContent, eListbox, gFont, \
7         RT_HALIGN_LEFT, RT_HALIGN_RIGHT, RT_VALIGN_CENTER
8 from Tools.LoadPixmap import LoadPixmap
9 from timer import TimerEntry
10 from Tools.Directories import resolveFilename, SCOPE_SKIN_IMAGE
11
12 class TimerList(HTMLComponent, GUIComponent, object):
13 #
14 #  | <Service>     <Name of the Timer>  |
15 #  | <start, end>              <state>  |
16 #
17         def buildTimerEntry(self, timer, processed):
18                 width = self.l.getItemSize().width()
19                 res = [ None ]
20                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, width, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.service_ref.getServiceName()))
21                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, width, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.name))
22
23                 repeatedtext = ""
24                 days = [ _("Mon"), _("Tue"), _("Wed"), _("Thu"), _("Fri"), _("Sat"), _("Sun") ]
25                 if timer.repeated:
26                         flags = timer.repeated
27                         count = 0
28                         for x in range(0, 7):
29                                         if (flags & 1 == 1):
30                                                 if (count != 0):
31                                                         repeatedtext += ", "
32                                                 repeatedtext += days[x]
33                                                 count += 1
34                                         flags = flags >> 1
35                         if timer.justplay:
36                                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ((" %s "+ _("(ZAP)")) % (FuzzyTime(timer.begin)[1]))))
37                         else:
38                                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ((" %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(timer.begin)[1], FuzzyTime(timer.end)[1], (timer.end - timer.begin) / 60))))
39                 else:
40                         if timer.justplay:
41                                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (("%s, %s " + _("(ZAP)")) % (FuzzyTime(timer.begin)))))
42                         else:
43                                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 400, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (("%s, %s ... %s (%d " + _("mins") + ")") % (FuzzyTime(timer.begin) + FuzzyTime(timer.end)[1:] + ((timer.end - timer.begin) / 60,)))))
44
45                 if not processed:
46                         if timer.state == TimerEntry.StateWaiting:
47                                 state = _("waiting")
48                         elif timer.state == TimerEntry.StatePrepared:
49                                 state = _("about to start")
50                         elif timer.state == TimerEntry.StateRunning:
51                                 if timer.justplay:
52                                         state = _("zapped")
53                                 else:
54                                         state = _("recording...")
55                         else:
56                                 state = _("<unknown>")
57                 else:
58                         state = _("done!")
59
60                 if timer.disabled:
61                         state = _("disabled")
62
63                 res.append((eListboxPythonMultiContent.TYPE_TEXT, width-240, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, state))
64
65                 if timer.disabled:
66                         png = LoadPixmap(resolveFilename(SCOPE_SKIN_IMAGE, "redx.png"))
67                         res.append((eListboxPythonMultiContent.TYPE_PIXMAP_ALPHATEST, 490, 5, 40, 40, png))
68                 return res
69
70         def __init__(self, list):
71                 GUIComponent.__init__(self)
72                 self.l = eListboxPythonMultiContent()
73                 self.l.setBuildFunc(self.buildTimerEntry)
74                 self.l.setFont(0, gFont("Regular", 20))
75                 self.l.setFont(1, gFont("Regular", 18))
76                 self.l.setItemHeight(70)
77                 self.l.setList(list)
78         
79         def getCurrent(self):
80                 cur = self.l.getCurrentSelection()
81                 return cur and cur[0]
82         
83         GUI_WIDGET = eListbox
84         
85         def postWidgetCreate(self, instance):
86                 instance.setContent(self.l)
87
88         def moveToIndex(self, index):
89                 self.instance.moveSelectionTo(index)
90
91         def getCurrentIndex(self):
92                 return self.instance.getCurrentIndex()
93
94         currentIndex = property(moveToIndex, getCurrentIndex)
95         currentSelection = property(getCurrent)
96
97         def moveDown(self):
98                 self.instance.moveSelection(self.instance.moveDown)
99
100         def invalidate(self):
101                 self.l.invalidate()
102
103         def entryRemoved(self, idx):
104                 self.l.entryRemoved(idx)
105