1 from Components.ActionMap import ActionMap
2 from Components.Button import Button
3 from Components.Label import Label
4 from Components.MenuList import MenuList
5 from Components.TimerList import TimerList, TimerEntryComponent
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):
17 def __init__(self, session):
18 Screen.__init__(self, session)
24 self["timerlist"] = TimerList(list)
26 self["key_red"] = Button(_("Delete"))
27 self["key_green"] = Button(_("Add"))
28 self["key_yellow"] = Button("")
29 self["key_blue"] = Button(_("Cleanup"))
31 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
35 "red": self.removeTimerQuestion,
36 "green": self.addCurrentTimer,
37 "blue": self.cleanupQuestion,
38 "yellow": self.toggleDisabledState,
45 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
46 self.onShown.append(self.updateState)
49 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveUp)
53 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveDown)
57 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageUp)
61 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageDown)
64 def toggleDisabledState(self):
65 cur=self["timerlist"].getCurrent()
71 self.session.nav.RecordTimer.timeChanged(t)
74 if t.isRunning() and t.repeated:
76 list.append((_("Stop current event but not coming events"), "stoponlycurrent"))
77 list.append((_("Stop current event and disable coming events"), "stopall"))
78 list.append((_("Don't stop current event but disable coming events"), "stoponlycoming"))
79 self.session.openWithCallback(boundFunction(self.runningEventCallback, t), ChoiceBox, title=_("Repeating event currently recording... What do you want to do?"), list = list)
82 self.session.nav.RecordTimer.timeChanged(t)
86 def runningEventCallback(self, t, result):
87 if result is not None:
88 if result[1] == "stoponlycurrent" or result[1] == "stopall":
90 t.processRepeated(findRunningEvent = False)
91 self.session.nav.RecordTimer.doActivate(t)
92 if result[1] == "stoponlycoming" or result[1] == "stopall":
94 self.session.nav.RecordTimer.timeChanged(t)
99 def updateState(self):
100 if len(self.list) > 0:
101 if self["timerlist"].getCurrent()[0].disabled:
102 self["key_yellow"].setText(_("Enable"))
104 self["key_yellow"].setText(_("Disable"))
105 self["key_yellow"].instance.invalidate()
107 def fillTimerList(self):
110 for timer in self.session.nav.RecordTimer.timer_list:
111 self.list.append(TimerEntryComponent(timer, processed=False))
113 for timer in self.session.nav.RecordTimer.processed_timers:
114 self.list.append(TimerEntryComponent(timer, processed=True))
115 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
118 cur=self["timerlist"].getCurrent()
120 self.session.openWithCallback(self.finishedEdit, TimerLog, cur[0])
123 cur=self["timerlist"].getCurrent()
125 self.session.openWithCallback(self.finishedEdit, TimerEntry, cur[0])
127 def cleanupQuestion(self):
128 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
130 def cleanupTimer(self, delete):
132 self.session.nav.RecordTimer.cleanup()
135 def removeTimerQuestion(self):
136 self.session.openWithCallback(self.removeTimer, MessageBox, _("Really delete this timer?"))
138 def removeTimer(self, result):
141 list = self["timerlist"]
142 cur = list.getCurrent()
145 timer.afterEvent = AFTEREVENT.NONE
146 self.session.nav.RecordTimer.removeEntry(timer)
151 self["timerlist"].invalidate()
153 def addCurrentTimer(self):
155 service = self.session.nav.getCurrentService()
156 if service is not None:
157 info = service.info()
159 event = info.getEvent(0)
161 # FIXME only works if already playing a service
162 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
165 data = (int(time()), int(time() + 60), "", "", None)
167 data = parseEvent(event, description = False)
169 self.addTimer(RecordTimerEntry(serviceref, checkOldTimers = True, *data))
171 def addTimer(self, timer):
172 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
174 def finishedEdit(self, answer):
175 print "finished edit"
179 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
180 if not timersanitycheck.check():
181 print "Sanity check failed"
183 print "Sanity check passed"
184 self.session.nav.RecordTimer.timeChanged(answer[1])
187 print "Timeredit aborted"
189 def finishedAdd(self, answer):
192 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
193 if not timersanitycheck.check():
194 print "Sanity check failed"
195 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, timersanitycheck.getSimulTimerList())
197 print "Sanity check passed"
199 self.session.nav.RecordTimer.record(entry)
202 print "Timeredit aborted"
204 def finishSanityCorrection(self, answer):
205 self.finishedAdd(answer)
208 self.session.nav.RecordTimer.saveTimer()
209 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
212 def onStateChange(self, entry):
215 class TimerSanityConflict(Screen):
216 def __init__(self, session, timer):
217 Screen.__init__(self, session)
219 print "TimerSanityConflict", timer
221 self["timer1"] = TimerList(self.getTimerList(timer[0]))
223 self["timer2"] = TimerList(self.getTimerList(timer[1]))
225 self["timer2"] = TimerList([])
231 self.list.append((_("Conflicting timer") + " " + str(count), x))
234 self["list"] = MenuList(self.list)
236 self["key_red"] = Button("Edit")
237 self["key_green"] = Button("Disable")
238 self["key_yellow"] = Button("Edit")
239 self["key_blue"] = Button("Disable")
241 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
244 #"cancel": self.leave,
245 "red": self.editTimer1,
246 "green": self.disableTimer1,
247 # "yellow": self.editTimer2,
248 # "blue": self.disableTimer2,
249 #"log": self.showLog,
251 #"right": self.right,
256 def getTimerList(self, timer):
257 return [TimerEntryComponent(timer, processed=False)]
259 def editTimer1(self):
260 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent()[0])
262 def disableTimer1(self):
263 self.timer[0].disabled = True
264 self.finishedEdit((True, self.timer[0]))
266 def finishedEdit(self, answer):
267 self.close((True, self.timer[0]))
270 self["list"].instance.moveSelection(self["list"].instance.moveUp)
271 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))
274 self["list"].instance.moveSelection(self["list"].instance.moveDown)
275 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))