1 from Screen import Screen
2 from Components.TimerList import TimerList, TimerEntryComponent
3 from Components.MenuList import MenuList
4 from Components.ActionMap import ActionMap
5 from Components.Label import Label
6 from Components.Button import Button
7 from Screens.MessageBox import MessageBox
8 from TimerEntry import TimerEntry, TimerLog
9 from RecordTimer import RecordTimerEntry, parseEvent, AFTEREVENT
11 from ServiceReference import ServiceReference
12 from Components.TimerSanityCheck import TimerSanityCheck
14 class TimerEditList(Screen):
15 def __init__(self, session):
16 Screen.__init__(self, session)
22 self["timerlist"] = TimerList(list)
24 self["key_red"] = Button(_("Delete"))
25 self["key_green"] = Button(_("Add"))
26 self["key_yellow"] = Button("")
27 self["key_blue"] = Button(_("Cleanup"))
29 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
33 "red": self.removeTimerQuestion,
34 "green": self.addCurrentTimer,
35 "blue": self.cleanupQuestion,
36 "yellow": self.toggleDisabledState,
43 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
44 self.onShown.append(self.updateState)
47 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveUp)
51 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveDown)
55 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageUp)
59 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageDown)
62 def toggleDisabledState(self):
63 cur=self["timerlist"].getCurrent()
72 self.session.nav.RecordTimer.timeChanged(t)
76 def updateState(self):
77 if len(self.list) > 0:
78 if self["timerlist"].getCurrent()[0].disabled:
79 self["key_yellow"].setText(_("Enable"))
81 self["key_yellow"].setText(_("Disable"))
82 self["key_yellow"].instance.invalidate()
84 def fillTimerList(self):
87 for timer in self.session.nav.RecordTimer.timer_list:
88 self.list.append(TimerEntryComponent(timer, processed=False))
90 for timer in self.session.nav.RecordTimer.processed_timers:
91 self.list.append(TimerEntryComponent(timer, processed=True))
92 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
95 cur=self["timerlist"].getCurrent()
97 self.session.openWithCallback(self.finishedEdit, TimerLog, cur[0])
100 cur=self["timerlist"].getCurrent()
102 self.session.openWithCallback(self.finishedEdit, TimerEntry, cur[0])
104 def cleanupQuestion(self):
105 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
107 def cleanupTimer(self, delete):
109 self.session.nav.RecordTimer.cleanup()
112 def removeTimerQuestion(self):
113 self.session.openWithCallback(self.removeTimer, MessageBox, _("Really delete this timer?"))
115 def removeTimer(self, result):
118 list = self["timerlist"]
119 cur = list.getCurrent()
122 timer.afterEvent = AFTEREVENT.NONE
123 self.session.nav.RecordTimer.removeEntry(timer)
128 self["timerlist"].invalidate()
130 def addCurrentTimer(self):
132 service = self.session.nav.getCurrentService()
133 if service is not None:
134 info = service.info()
136 event = info.getEvent(0)
138 # FIXME only works if already playing a service
139 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
142 data = (int(time()), int(time() + 60), "", "", None)
144 data = parseEvent(event, description = False)
146 self.addTimer(RecordTimerEntry(serviceref, checkOldTimers = True, *data))
148 def addTimer(self, timer):
149 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
151 def finishedEdit(self, answer):
152 print "finished edit"
156 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
157 if not timersanitycheck.check():
158 print "Sanity check failed"
160 print "Sanity check passed"
161 self.session.nav.RecordTimer.timeChanged(answer[1])
164 print "Timeredit aborted"
166 def finishedAdd(self, answer):
169 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
170 if not timersanitycheck.check():
171 print "Sanity check failed"
172 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, timersanitycheck.getSimulTimerList())
174 print "Sanity check passed"
176 self.session.nav.RecordTimer.record(entry)
179 print "Timeredit aborted"
181 def finishSanityCorrection(self, answer):
182 self.finishedAdd(answer)
185 self.session.nav.RecordTimer.saveTimer()
186 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
189 def onStateChange(self, entry):
192 class TimerSanityConflict(Screen):
193 def __init__(self, session, timer):
194 Screen.__init__(self, session)
196 print "TimerSanityConflict", timer
198 self["timer1"] = TimerList(self.getTimerList(timer[0]))
200 self["timer2"] = TimerList(self.getTimerList(timer[1]))
202 self["timer2"] = Button("No conflict")
208 self.list.append((_("Conflicting timer") + " " + str(count), x))
211 self["list"] = MenuList(self.list)
213 self["key_red"] = Button("Edit")
214 self["key_green"] = Button("Disable")
215 self["key_yellow"] = Button("Edit")
216 self["key_blue"] = Button("Disable")
218 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
221 #"cancel": self.leave,
222 "red": self.editTimer1,
223 "green": self.disableTimer1,
224 # "yellow": self.editTimer2,
225 # "blue": self.disableTimer2,
226 #"log": self.showLog,
228 #"right": self.right,
233 def getTimerList(self, timer):
234 return [TimerEntryComponent(timer, processed=False)]
236 def editTimer1(self):
237 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent()[0])
239 def disableTimer1(self):
240 self.timer[0].disabled = True
241 self.finishedEdit((True, self.timer[0]))
243 def finishedEdit(self, answer):
244 self.close((True, self.timer[0]))
247 self["list"].instance.moveSelection(self["list"].instance.moveUp)
248 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))
251 self["list"].instance.moveSelection(self["list"].instance.moveDown)
252 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))