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