1 from Components.ActionMap import ActionMap
2 from Components.Button import Button
3 from Components.config import config
4 from Components.MenuList import MenuList
5 from Components.TimerList import TimerList
6 from Components.TimerSanityCheck import TimerSanityCheck
7 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
8 from Screen import Screen
9 from Screens.ChoiceBox import ChoiceBox
10 from Screens.MessageBox import MessageBox
11 from ServiceReference import ServiceReference
12 from TimerEntry import TimerEntry, TimerLog
13 from Tools.BoundFunction import boundFunction
16 class TimerEditList(Screen):
23 def __init__(self, session):
24 Screen.__init__(self, session)
30 print "EMPTY:",self.EMPTY
31 print "ENABLE:",self.ENABLE
32 print "DISABLE:",self.DISABLE
33 print "CLEANUP:",self.CLEANUP
34 print "DELETE:",self.DELETE
36 self["timerlist"] = TimerList(list)
38 self.key_red_choice = self.EMPTY
39 self.key_yellow_choice = self.EMPTY
40 self.key_blue_choice = self.EMPTY
42 self["key_red"] = Button(" ")
43 self["key_green"] = Button(_("Add"))
44 self["key_yellow"] = Button(" ")
45 self["key_blue"] = Button(" ")
47 print "key_red_choice:",self.key_red_choice
49 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
53 "green": self.addCurrentTimer,
60 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
61 self.onShown.append(self.updateState)
64 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveUp)
68 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveDown)
72 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageUp)
76 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageDown)
79 def toggleDisabledState(self):
80 cur=self["timerlist"].getCurrent()
84 print "try to ENABLE timer"
86 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, cur)
87 if not timersanitycheck.check():
89 print "Sanity check failed"
90 self.session.openWithCallback(self.finishedEdit, TimerSanityConflict, timersanitycheck.getSimulTimerList())
92 print "Sanity check passed"
93 if timersanitycheck.doubleCheck():
99 list.append((_("Stop current event but not coming events"), "stoponlycurrent"))
100 list.append((_("Stop current event and disable coming events"), "stopall"))
101 list.append((_("Don't stop current event but disable coming events"), "stoponlycoming"))
102 self.session.openWithCallback(boundFunction(self.runningEventCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = list)
105 self.session.nav.RecordTimer.timeChanged(t)
109 def runningEventCallback(self, t, result):
110 if result is not None:
111 if result[1] == "stoponlycurrent" or result[1] == "stopall":
113 t.processRepeated(findRunningEvent = False)
114 self.session.nav.RecordTimer.doActivate(t)
115 if result[1] == "stoponlycoming" or result[1] == "stopall":
117 self.session.nav.RecordTimer.timeChanged(t)
121 def removeAction(self, descr):
122 actions = self["actions"].actions
126 def updateState(self):
127 cur = self["timerlist"].getCurrent()
129 if self.key_red_choice != self.DELETE:
130 self["actions"].actions.update({"red":self.removeTimerQuestion})
131 self["key_red"].setText(_("Delete"))
132 self.key_red_choice = self.DELETE
134 if cur.disabled and (self.key_yellow_choice != self.ENABLE):
135 self["actions"].actions.update({"yellow":self.toggleDisabledState})
136 self["key_yellow"].setText(_("Enable"))
137 self.key_yellow_choice = self.ENABLE
138 elif cur.isRunning() and not cur.repeated and (self.key_yellow_choice != self.EMPTY):
139 self.removeAction("yellow")
140 self["key_yellow"].setText(" ")
141 self.key_yellow_choice = self.EMPTY
142 elif ((not cur.isRunning())or cur.repeated ) and (not cur.disabled) and (self.key_yellow_choice != self.DISABLE):
143 self["actions"].actions.update({"yellow":self.toggleDisabledState})
144 self["key_yellow"].setText(_("Disable"))
145 self.key_yellow_choice = self.DISABLE
147 if self.key_red_choice != self.EMPTY:
148 self.removeAction("red")
149 self["key_red"].setText(" ")
150 self.key_red_choice = self.EMPTY
151 if self.key_yellow_choice != self.EMPTY:
152 self.removeAction("yellow")
153 self["key_yellow"].setText(" ")
154 self.key_yellow_choice = self.EMPTY
158 if (not x[0].disabled) and (x[1] == True):
163 if showCleanup and (self.key_blue_choice != self.CLEANUP):
164 self["actions"].actions.update({"blue":self.cleanupQuestion})
165 self["key_blue"].setText(_("Cleanup"))
166 self.key_blue_choice = self.CLEANUP
167 elif (not showCleanup) and (self.key_blue_choice != self.EMPTY):
168 self.removeAction("blue")
169 self["key_blue"].setText(" ")
170 self.key_blue_choice = self.EMPTY
172 def fillTimerList(self):
175 for timer in self.session.nav.RecordTimer.timer_list:
176 self.list.append((timer, False))
178 for timer in self.session.nav.RecordTimer.processed_timers:
179 self.list.append((timer, True))
180 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
183 cur=self["timerlist"].getCurrent()
185 self.session.openWithCallback(self.finishedEdit, TimerLog, cur)
188 cur=self["timerlist"].getCurrent()
190 self.session.openWithCallback(self.finishedEdit, TimerEntry, cur)
192 def cleanupQuestion(self):
193 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
195 def cleanupTimer(self, delete):
197 self.session.nav.RecordTimer.cleanup()
201 def removeTimerQuestion(self):
202 cur = self["timerlist"].getCurrent()
206 self.session.openWithCallback(self.removeTimer, MessageBox, _("Do you really want to delete %s?") % (cur.name))
208 def removeTimer(self, result):
211 list = self["timerlist"]
212 cur = list.getCurrent()
215 timer.afterEvent = AFTEREVENT.NONE
216 self.session.nav.RecordTimer.removeEntry(timer)
222 oldsize = len(self.list)
224 lst = self["timerlist"]
225 newsize = len(self.list)
226 if oldsize and oldsize != newsize:
227 idx = lst.getCurrentIndex()
228 lst.entryRemoved(idx)
232 def addCurrentTimer(self):
234 service = self.session.nav.getCurrentService()
235 if service is not None:
236 info = service.info()
238 event = info.getEvent(0)
240 # FIXME only works if already playing a service
241 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
244 data = (int(time()), int(time() + 60), "", "", None)
246 data = parseEvent(event, description = False)
248 self.addTimer(RecordTimerEntry(serviceref, checkOldTimers = True, dirname = config.movielist.last_timer_videodir.value, *data))
250 def addTimer(self, timer):
251 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
254 def finishedEdit(self, answer):
255 print "finished edit"
260 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, entry)
262 if not timersanitycheck.check():
263 simulTimerList = timersanitycheck.getSimulTimerList()
264 if simulTimerList is not None:
265 for x in simulTimerList:
266 if x.setAutoincreaseEnd(entry):
267 self.session.nav.RecordTimer.timeChanged(x)
268 if not timersanitycheck.check():
269 simulTimerList = timersanitycheck.getSimulTimerList()
270 if simulTimerList is not None:
271 self.session.openWithCallback(self.finishedEdit, TimerSanityConflict, timersanitycheck.getSimulTimerList())
277 print "Sanity check passed"
278 self.session.nav.RecordTimer.timeChanged(entry)
283 print "Timeredit aborted"
285 def finishedAdd(self, answer):
289 simulTimerList = self.session.nav.RecordTimer.record(entry)
290 if simulTimerList is not None:
291 for x in simulTimerList:
292 if x.setAutoincreaseEnd(entry):
293 self.session.nav.RecordTimer.timeChanged(x)
294 simulTimerList = self.session.nav.RecordTimer.record(entry)
295 if simulTimerList is not None:
296 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, simulTimerList)
300 print "Timeredit aborted"
302 def finishSanityCorrection(self, answer):
303 self.finishedAdd(answer)
306 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
309 def onStateChange(self, entry):
313 class TimerSanityConflict(Screen):
319 def __init__(self, session, timer):
320 Screen.__init__(self, session)
322 print "TimerSanityConflict"
324 self["timer1"] = TimerList(self.getTimerList(timer[0]))
330 self.list.append((_("Conflicting timer") + " " + str(count), x))
331 self.list2.append((timer[count], False))
334 self.list.append((_("Channel not in services list")))
336 self["list"] = MenuList(self.list)
337 self["timer2"] = TimerList(self.list2)
339 self["key_red"] = Button("Edit")
340 self["key_green"] = Button(" ")
341 self["key_yellow"] = Button(" ")
342 self["key_blue"] = Button(" ")
344 self.key_green_choice = self.EMPTY
345 self.key_yellow_choice = self.EMPTY
346 self.key_blue_choice = self.EMPTY
348 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
351 "cancel": self.leave_cancel,
352 "red": self.editTimer1,
356 self.onShown.append(self.updateState)
358 def getTimerList(self, timer):
359 return [(timer, False)]
361 def editTimer1(self):
362 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent())
364 def toggleTimer1(self):
365 if self.timer[0].disabled:
366 self.timer[0].disabled = False
368 if not self.timer[0].isRunning():
369 self.timer[0].disabled = True
370 self.finishedEdit((True, self.timer[0]))
372 def editTimer2(self):
373 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer2"].getCurrent())
375 def toggleTimer2(self):
376 x = self["list"].getSelectedIndex() + 1 # the first is the new timer so we do +1 here
377 if self.timer[x].disabled:
378 self.timer[x].disabled = False
379 elif not self.timer[x].isRunning():
380 self.timer[x].disabled = True
381 self.finishedEdit((True, self.timer[0]))
383 def finishedEdit(self, answer):
387 self.close((True, self.timer[0]))
389 def leave_cancel(self):
390 self.close((False, self.timer[0]))
393 self["list"].instance.moveSelection(self["list"].instance.moveUp)
394 self["timer2"].moveToIndex(self["list"].getSelectedIndex())
397 self["list"].instance.moveSelection(self["list"].instance.moveDown)
398 self["timer2"].moveToIndex(self["list"].getSelectedIndex())
400 def removeAction(self, descr):
401 actions = self["actions"].actions
405 def updateState(self):
406 if self.timer[0] is not None:
407 if self.timer[0].disabled and self.key_green_choice != self.ENABLE:
408 self["actions"].actions.update({"green":self.toggleTimer1})
409 self["key_green"].setText(_("Enable"))
410 self.key_green_choice = self.ENABLE
411 elif self.timer[0].isRunning() and not timer[0].repeated and self.key_green_choice != self.EMPTY:
412 self.removeAction("green")
413 self["key_green"].setText(" ")
414 self.key_green_choice = self.EMPTY
415 elif (not self.timer[0].isRunning() or self.timer[0].repeated ) and self.key_green_choice != self.DISABLE:
416 self["actions"].actions.update({"green":self.toggleTimer1})
417 self["key_green"].setText(_("Disable"))
418 self.key_green_choice = self.DISABLE
420 if len(self.timer) > 1:
421 x = self["list"].getSelectedIndex()
422 if self.timer[x] is not None:
423 if self.key_yellow_choice == self.EMPTY:
424 self["actions"].actions.update({"yellow":self.editTimer2})
425 self["key_yellow"].setText(_("Edit"))
426 self.key_yellow_choice = self.EDIT
427 if self.timer[x].disabled and self.key_blue_choice != self.ENABLE:
428 self["actions"].actions.update({"blue":self.toggleTimer2})
429 self["key_blue"].setText(_("Enable"))
430 self.key_blue_choice = self.ENABLE
431 elif self.timer[x].isRunning() and not timer[x].repeated and self.key_blue_choice != self.EMPTY:
432 self.removeAction("blue")
433 self["key_blue"].setText(" ")
434 self.key_blue_choice = self.EMPTY
435 elif (not self.timer[x].isRunning() or self.timer[x].repeated ) and self.key_blue_choice != self.DISABLE:
436 self["actions"].actions.update({"blue":self.toggleTimer2})
437 self["key_blue"].setText(_("Disable"))
438 self.key_blue_choice = self.DISABLE
440 #FIXME.... this doesnt hide the buttons self.... just the text
441 if self.key_yellow_choice != self.EMPTY:
442 self.removeAction("yellow")
443 self["key_yellow"].setText(" ")
444 self.key_yellow_choice = self.EMPTY
445 if self.key_blue_choice != self.EMPTY:
446 self.removeAction("blue")
447 self["key_blue"].setText(" ")
448 self.key_blue_choice = self.EMPTY