moving the list generation to a seperate method
[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         print time.strftime("%c", time.localtime(timer.begin))
30         print time.strftime("%c", time.localtime(timer.end))
31                 
32         res.append((0, 0, 400, 30, 0, RT_HALIGN_LEFT, timer.service_ref.getServiceName()))
33         repeatedtext = ""
34         days = [ "Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun" ]
35         if (timer.repeated != 0):
36                 flags = timer.repeated
37                 count = 0
38                 for x in range(0, 7):
39                                 if (flags & 1 == 1):
40                                         if (count != 0):
41                                                 repeatedtext += ", "
42                                         repeatedtext += days[x]
43                                         count += 1
44                                 flags = flags >> 1
45                 res.append((0, 30, 200, 20, 1, RT_HALIGN_LEFT, repeatedtext + (" %s ... %s" % (FuzzyTime(timer.begin)[1], FuzzyTime(timer.end)[1]))))
46         else:
47                 res.append((0, 30, 200, 20, 1, RT_HALIGN_LEFT, repeatedtext + ("%s, %s ... %s" % (FuzzyTime(timer.begin) + FuzzyTime(timer.end)[1:]))))
48
49         res.append((300, 0, 200, 20, 1, RT_HALIGN_RIGHT, timer.description))
50         
51         if not processed:
52                 if timer.state == TimerEntry.StateWait:
53                         state = "waiting"
54                 elif timer.state == TimerEntry.StatePrepare:
55                         state = "about to start"
56                 elif timer.state == TimerEntry.StateRunning:
57                         state = "recording..."
58                 else:
59                         state = "<unknown>"
60         else:
61                 state = "done!"
62         
63         res.append((300, 30, 200, 20, 1, RT_HALIGN_RIGHT, state))
64         
65         return res
66
67 class TimerList(HTMLComponent, GUIComponent):
68         def __init__(self, list):
69                 GUIComponent.__init__(self)
70                 self.l = eListboxPythonMultiContent()
71                 self.l.setList(list)
72                 self.l.setFont(0, gFont("Arial", 20))
73                 self.l.setFont(1, gFont("Arial", 18))
74         
75         def getCurrent(self):
76                 return self.l.getCurrentSelection()
77         
78         def GUIcreate(self, parent):
79                 self.instance = eListbox(parent)
80                 self.instance.setContent(self.l)
81                 self.instance.setItemHeight(50)
82         
83         def GUIdelete(self):
84                 self.instance.setContent(None)
85                 self.instance = None
86
87         def invalidate(self):
88                 self.l.invalidate()
89