add subservice selection to timer (when linkage services are avail for the selected...
[enigma2.git] / lib / python / Components / TimerList.py
1 from HTMLComponent import *
2 from GUIComponent import *
3
4 from Tools.FuzzyDate import FuzzyTime
5 import time
6
7 from enigma import eListboxPythonMultiContent, eListbox, gFont
8 from timer import TimerEntry
9
10 RT_HALIGN_LEFT = 0
11 RT_HALIGN_RIGHT = 1
12 RT_HALIGN_CENTER = 2
13 RT_HALIGN_BLOCK = 4
14
15 RT_VALIGN_TOP = 0
16 RT_VALIGN_CENTER = 8
17 RT_VALIGN_BOTTOM = 16
18
19 RT_WRAP = 32
20
21
22 #
23 #  | <Service>     <Name of the Timer>  |
24 #  | <start, end>              <state>  |
25 #
26 def TimerEntryComponent(timer, processed):
27         res = [ timer ]
28         
29         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 0, 560, 30, 0, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.service_ref.getServiceName()))
30         res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 30, 560, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, timer.name))
31         
32         repeatedtext = ""
33         days = [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" ]
34         if (timer.repeated != 0):
35                 flags = timer.repeated
36                 count = 0
37                 for x in range(0, 7):
38                                 if (flags & 1 == 1):
39                                         if (count != 0):
40                                                 repeatedtext += ", "
41                                         repeatedtext += days[x]
42                                         count += 1
43                                 flags = flags >> 1
44                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 300, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + (" %s ... %s" % (FuzzyTime(timer.begin)[1], FuzzyTime(timer.end)[1]))))
45         else:
46                 res.append((eListboxPythonMultiContent.TYPE_TEXT, 0, 50, 300, 20, 1, RT_HALIGN_LEFT|RT_VALIGN_CENTER, repeatedtext + ("%s, %s ... %s" % (FuzzyTime(timer.begin) + FuzzyTime(timer.end)[1:]))))
47
48         if not processed:
49                 if timer.state == TimerEntry.StateWait:
50                         state = "waiting"
51                 elif timer.state == TimerEntry.StatePrepare:
52                         state = "about to start"
53                 elif timer.state == TimerEntry.StateRunning:
54                         state = "recording..."
55                 else:
56                         state = "<unknown>"
57         else:
58                 state = "done!"
59         
60         res.append((eListboxPythonMultiContent.TYPE_TEXT, 320, 50, 240, 20, 1, RT_HALIGN_RIGHT|RT_VALIGN_CENTER, state))
61         
62         return res
63
64 class TimerList(HTMLComponent, GUIComponent):
65         def __init__(self, list):
66                 GUIComponent.__init__(self)
67                 self.l = eListboxPythonMultiContent()
68                 self.l.setList(list)
69                 self.l.setFont(0, gFont("Regular", 20))
70                 self.l.setFont(1, gFont("Regular", 18))
71         
72         def getCurrent(self):
73                 return self.l.getCurrentSelection()
74         
75         def GUIcreate(self, parent):
76                 self.instance = eListbox(parent)
77                 self.instance.setContent(self.l)
78                 self.instance.setItemHeight(70)
79         
80         def GUIdelete(self):
81                 self.instance.setContent(None)
82                 self.instance = None
83
84         def invalidate(self):
85                 self.l.invalidate()
86