1 from Screen import Screen
2 from Components.TimerList import TimerList, TimerEntryComponent
3 from Components.ConfigList import ConfigList
4 from Components.MenuList import MenuList
5 from Components.ActionMap import ActionMap
6 from Components.Label import Label
7 from Components.Button import Button
8 from Screens.MessageBox import MessageBox
9 from TimerEntry import TimerEntry, TimerLog
10 from RecordTimer import RecordTimerEntry, parseEvent
12 from ServiceReference import ServiceReference
13 from Components.config import *
14 from Components.TimerSanityCheck import TimerSanityCheck
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.removeTimer,
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()
74 self.session.nav.RecordTimer.timeChanged(t)
78 def updateState(self):
79 if len(self.list) > 0:
80 if self["timerlist"].getCurrent()[0].disabled:
81 self["key_yellow"].setText(_("Enable"))
83 self["key_yellow"].setText(_("Disable"))
84 self["key_yellow"].instance.invalidate()
86 def fillTimerList(self):
89 for timer in self.session.nav.RecordTimer.timer_list:
90 self.list.append(TimerEntryComponent(timer, processed=False))
92 for timer in self.session.nav.RecordTimer.processed_timers:
93 self.list.append(TimerEntryComponent(timer, processed=True))
94 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
97 cur=self["timerlist"].getCurrent()
99 self.session.openWithCallback(self.finishedEdit, TimerLog, cur[0])
102 cur=self["timerlist"].getCurrent()
104 self.session.openWithCallback(self.finishedEdit, TimerEntry, cur[0])
106 def cleanupQuestion(self):
107 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
109 def cleanupTimer(self, delete):
111 self.session.nav.RecordTimer.cleanup()
114 def removeTimer(self):
115 list = self["timerlist"]
116 cur = list.getCurrent()
119 self.session.nav.RecordTimer.removeEntry(timer)
124 self["timerlist"].invalidate()
126 def addCurrentTimer(self):
128 service = self.session.nav.getCurrentService()
129 if service is not None:
130 info = service.info()
132 event = info.getEvent(0)
134 # FIXME only works if already playing a service
135 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
138 data = (int(time()), int(time() + 60), "unknown event", "", None)
140 data = parseEvent(event)
142 self.addTimer(RecordTimerEntry(serviceref, *data))
144 def addTimer(self, timer):
145 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
147 def finishedEdit(self, answer):
148 print "finished edit"
152 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
153 if not timersanitycheck.check():
154 print "Sanity check failed"
156 print "Sanity check passed"
157 self.session.nav.RecordTimer.timeChanged(answer[1])
160 print "Timeredit aborted"
162 def finishedAdd(self, answer):
165 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
166 if not timersanitycheck.check():
167 print "Sanity check failed"
168 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, timersanitycheck.getSimulTimerList())
170 print "Sanity check passed"
172 self.session.nav.RecordTimer.record(entry)
175 print "Timeredit aborted"
177 def finishSanityCorrection(self, answer):
178 self.finishedAdd(answer)
181 self.session.nav.RecordTimer.saveTimer()
182 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
185 def onStateChange(self, entry):
188 class TimerSanityConflict(Screen):
189 def __init__(self, session, timer):
190 Screen.__init__(self, session)
192 print "TimerSanityConflict", timer
194 self["timer1"] = TimerList(self.getTimerList(timer[0]))
196 self["timer2"] = TimerList(self.getTimerList(timer[1]))
198 self["timer2"] = Button("No conflict")
204 self.list.append((_("Conflicting timer") + " " + str(count), x))
207 self["list"] = MenuList(self.list)
209 self["key_red"] = Button("Edit")
210 self["key_green"] = Button("Disable")
211 self["key_yellow"] = Button("Edit")
212 self["key_blue"] = Button("Disable")
214 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
217 #"cancel": self.leave,
218 "red": self.editTimer1,
219 "green": self.disableTimer1,
220 # "yellow": self.editTimer2,
221 # "blue": self.disableTimer2,
222 #"log": self.showLog,
224 #"right": self.right,
229 def getTimerList(self, timer):
230 return [TimerEntryComponent(timer, processed=False)]
232 def editTimer1(self):
233 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent()[0])
235 def disableTimer1(self):
236 self.timer[0].disabled = True
237 self.finishedEdit((True, self.timer[0]))
239 def finishedEdit(self, answer):
240 self.close((True, self.timer[0]))
243 self["list"].instance.moveSelection(self["list"].instance.moveUp)
244 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))
247 self["list"].instance.moveSelection(self["list"].instance.moveDown)
248 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))