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