1 from Components.ActionMap import ActionMap
2 from Components.Button import Button
3 from Components.MenuList import MenuList
4 from Components.TimerList import TimerList
5 from Components.TimerSanityCheck import TimerSanityCheck
6 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
7 from Screen import Screen
8 from Screens.ChoiceBox import ChoiceBox
9 from Screens.MessageBox import MessageBox
10 from ServiceReference import ServiceReference
11 from TimerEntry import TimerEntry, TimerLog
12 from Tools.BoundFunction import boundFunction
15 class TimerEditList(Screen):
16 def __init__(self, session):
17 Screen.__init__(self, session)
23 self["timerlist"] = TimerList(list)
25 self["key_red"] = Button(_("Delete"))
26 self["key_green"] = Button(_("Add"))
27 self["key_yellow"] = Button("")
28 self["key_blue"] = Button(_("Cleanup"))
30 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
34 "red": self.removeTimerQuestion,
35 "green": self.addCurrentTimer,
36 "blue": self.cleanupQuestion,
37 "yellow": self.toggleDisabledState,
44 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
45 self.onShown.append(self.updateState)
48 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveUp)
52 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveDown)
56 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageUp)
60 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageDown)
63 def toggleDisabledState(self):
64 cur=self["timerlist"].getCurrent()
70 self.session.nav.RecordTimer.timeChanged(t)
73 if t.isRunning() and t.repeated:
75 list.append((_("Stop current event but not coming events"), "stoponlycurrent"))
76 list.append((_("Stop current event and disable coming events"), "stopall"))
77 list.append((_("Don't stop current event but disable coming events"), "stoponlycoming"))
78 self.session.openWithCallback(boundFunction(self.runningEventCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = list)
81 self.session.nav.RecordTimer.timeChanged(t)
85 def runningEventCallback(self, t, result):
86 if result is not None:
87 if result[1] == "stoponlycurrent" or result[1] == "stopall":
89 t.processRepeated(findRunningEvent = False)
90 self.session.nav.RecordTimer.doActivate(t)
91 if result[1] == "stoponlycoming" or result[1] == "stopall":
93 self.session.nav.RecordTimer.timeChanged(t)
98 def updateState(self):
99 if len(self.list) > 0:
100 if self["timerlist"].getCurrent().disabled:
101 self["key_yellow"].setText(_("Enable"))
103 self["key_yellow"].setText(_("Disable"))
104 self["key_yellow"].instance.invalidate()
106 def fillTimerList(self):
109 for timer in self.session.nav.RecordTimer.timer_list:
110 self.list.append((timer, False))
112 for timer in self.session.nav.RecordTimer.processed_timers:
113 self.list.append((timer, True))
114 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
117 cur=self["timerlist"].getCurrent()
119 self.session.openWithCallback(self.finishedEdit, TimerLog, cur)
122 cur=self["timerlist"].getCurrent()
124 self.session.openWithCallback(self.finishedEdit, TimerEntry, cur)
126 def cleanupQuestion(self):
127 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
129 def cleanupTimer(self, delete):
131 self.session.nav.RecordTimer.cleanup()
134 def removeTimerQuestion(self):
135 if not self["timerlist"].getCurrent():
137 self.session.openWithCallback(self.removeTimer, MessageBox, _("Really delete this timer?"))
139 def removeTimer(self, result):
142 list = self["timerlist"]
143 cur = list.getCurrent()
146 timer.afterEvent = AFTEREVENT.NONE
147 self.session.nav.RecordTimer.removeEntry(timer)
151 oldsize = len(self.list)
153 lst = self["timerlist"]
154 newsize = len(self.list)
155 if oldsize and oldsize != newsize:
156 idx = lst.getCurrentIndex()
157 lst.entryRemoved(idx)
161 def addCurrentTimer(self):
163 service = self.session.nav.getCurrentService()
164 if service is not None:
165 info = service.info()
167 event = info.getEvent(0)
169 # FIXME only works if already playing a service
170 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
173 data = (int(time()), int(time() + 60), "", "", None)
175 data = parseEvent(event, description = False)
177 self.addTimer(RecordTimerEntry(serviceref, checkOldTimers = True, *data))
179 def addTimer(self, timer):
180 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
182 def finishedEdit(self, answer):
183 print "finished edit"
187 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
188 if not timersanitycheck.check():
189 print "Sanity check failed"
191 print "Sanity check passed"
192 self.session.nav.RecordTimer.timeChanged(answer[1])
195 print "Timeredit aborted"
197 def finishedAdd(self, answer):
200 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
201 if not timersanitycheck.check():
202 print "Sanity check failed"
203 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, timersanitycheck.getSimulTimerList())
205 print "Sanity check passed"
207 self.session.nav.RecordTimer.record(entry)
210 print "Timeredit aborted"
212 def finishSanityCorrection(self, answer):
213 self.finishedAdd(answer)
216 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
219 def onStateChange(self, entry):
222 class TimerSanityConflict(Screen):
223 def __init__(self, session, timer):
224 Screen.__init__(self, session)
226 print "TimerSanityConflict", timer
228 self["timer1"] = TimerList(self.getTimerList(timer[0]))
230 self["timer2"] = TimerList(self.getTimerList(timer[1]))
232 self["timer2"] = TimerList([])
238 self.list.append((_("Conflicting timer") + " " + str(count), x))
241 self["list"] = MenuList(self.list)
243 self["key_red"] = Button("Edit")
244 self["key_green"] = Button("Disable")
245 self["key_yellow"] = Button("Edit")
246 self["key_blue"] = Button("Disable")
248 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
251 #"cancel": self.leave,
252 "red": self.editTimer1,
253 "green": self.disableTimer1,
254 # "yellow": self.editTimer2,
255 # "blue": self.disableTimer2,
256 #"log": self.showLog,
258 #"right": self.right,
263 def getTimerList(self, timer):
264 return [(timer, False)]
266 def editTimer1(self):
267 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent())
269 def disableTimer1(self):
270 self.timer[0].disabled = True
271 self.finishedEdit((True, self.timer[0]))
273 def finishedEdit(self, answer):
274 self.close((True, self.timer[0]))
277 self["list"].instance.moveSelection(self["list"].instance.moveUp)
278 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()))
281 self["list"].instance.moveSelection(self["list"].instance.moveDown)
282 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()))