add a small text input component
[openblackhole/openblackhole-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 TimerEntry import TimerEntry
8 from RecordTimer import RecordTimerEntry, parseEvent
9 from time import *
10 from ServiceReference import ServiceReference
11 from Components.config import *
12
13 class TimerEditList(Screen):
14         def __init__(self, session):
15                 Screen.__init__(self, session)
16                 
17                 list = [ ]
18                 self.list = list
19                 self.fillTimerList()
20
21                 self["timerlist"] = TimerList(list)
22                 
23                 self["key_red"] = Button(_("Delete"))
24                 self["key_green"] = Button(_("Add"))
25                 self["key_yellow"] = Button("")
26                 self["key_blue"] = Button("")
27
28                 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"], 
29                         {
30                                 "ok": self.openEdit,
31                                 "cancel": self.leave,
32                                 "red": self.removeTimer,
33                                 "green": self.addCurrentTimer
34                         })
35                 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
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, processed=False))
42                 
43                 for timer in self.session.nav.RecordTimer.processed_timers:
44                         self.list.append(TimerEntryComponent(timer, processed=True))
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.refill()
54         
55         def refill(self):
56                 self.fillTimerList()
57                 self["timerlist"].invalidate()
58         
59         def addCurrentTimer(self):
60                 event = None
61                 service = self.session.nav.getCurrentService()
62                 if service is not None:
63                         info = service.info()
64                         if info is not None:
65                                 event = info.getEvent(0)
66
67                 # FIXME only works if already playing a service
68                 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
69                 
70                 if event is None:       
71                         data = (int(time()), int(time() + 60), "unknown event", "", None)
72                 else:
73                         data = parseEvent(event)
74
75                 self.addTimer(RecordTimerEntry(serviceref, *data))
76                 
77         def addTimer(self, timer):
78                 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
79                 
80         def finishedEdit(self, answer):
81                 print "finished edit"
82                 if answer[0]:
83                         print "Edited timer"
84                         self.session.nav.RecordTimer.timeChanged(answer[1])
85                         self.fillTimerList()
86                 else:
87                         print "Timeredit aborted"
88
89         def finishedAdd(self, answer):
90                 print "finished add"
91                 if answer[0]:
92                         entry = answer[1]
93                         self.session.nav.RecordTimer.record(entry)
94                         self.fillTimerList()
95                 else:
96                         print "Timeredit aborted"               
97
98         def leave(self):
99                 self.session.nav.RecordTimer.saveTimer()
100                 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
101                 self.close()
102
103         def onStateChange(self, entry):
104                 self.refill()