fix redraw problem when adding a timer
[enigma2.git] / lib / python / Screens / TimerEdit.py
1 from Screen import Screen
2 from Components.TimerList import TimerList, TimerEntryComponent
3 from Components.ActionMap import ActionMap
4 from Components.TimeInput import TimeInput
5 from Components.Label import Label
6 from Components.Button import Button
7 from Components.TextInput import TextInput
8 from TimerEntry import TimerEntry
9 from RecordTimer import RecordTimerEntry
10 from time import *
11 from ServiceReference import ServiceReference
12 from Components.config import *
13
14 class TimerEditList(Screen):
15         def __init__(self, session):
16                 Screen.__init__(self, session)
17                 
18                 list = [ ]
19                 self.list = list
20                 self.fillTimerList()
21
22                 self["timerlist"] = TimerList(list)
23                 
24                 self["key_red"] = Button("Delete")
25                 self["key_green"] = Button("Add")
26                 self["key_yellow"] = Button("")
27                 self["key_blue"] = Button("")
28
29                 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"], 
30                         {
31                                 "ok": self.openEdit,
32                                 "cancel": self.close,
33                                 "red": self.removeTimer,
34                                 "green": self.addCurrentTimer
35                         })
36
37         def fillTimerList(self):
38                 del self.list[:]
39                 
40                 for timer in self.session.nav.RecordTimer.timer_list:
41                         self.list.append(TimerEntryComponent(timer, 0))
42                 
43                 for timer in self.session.nav.RecordTimer.processed_timers:
44                         self.list.append(TimerEntryComponent(timer, 1))
45
46         def openEdit(self):
47                 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
48                 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
49                 
50         def removeTimer(self):
51                 # FIXME doesn't work...
52                 self.session.nav.RecordTimer.removeEntry(self["timerlist"].getCurrent()[0])
53                 self.fillTimerList()
54         
55         def addCurrentTimer(self):
56                 begin = time()
57                 end = time() + 60
58                 
59                 epg = None
60                 try:
61                         service = self.session.nav.getCurrentService()
62                         info = service.info()
63                         ev = info.getEvent(0)
64                         epg = ev
65                 except:
66                         pass
67                 
68                 if (epg == None):
69                         description = "unknown event"
70                 else:
71                         description = ev.getEventName()
72                         # FIXME we need a timestamp here:
73                         begin = ev.getBeginTime()
74                         
75                         print begin
76                         print ev.getDuration()
77                         end = begin + ev.getDuration()
78
79
80                 # FIXME only works if already playing a service
81                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
82                 
83                 self.addTimer(RecordTimerEntry(begin, end, serviceref, epg, description))
84                 
85         def addTimer(self, timer):
86                 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
87                 
88         def finishedEdit(self, answer):
89                 if (answer[0]):
90                         print "Edited timer"
91                         self.fillTimerList()
92                 else:
93                         print "Timeredit aborted"
94                         
95         def finishedAdd(self, answer):
96                 if (answer[0]):
97                         self.session.nav.RecordTimer.record(answer[1])
98                         self.fillTimerList()
99                 else:
100                         print "Timeredit aborted"