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.TimeInput import TimeInput
7 from Components.Label import Label
8 from Components.Button import Button
9 from Screens.MessageBox import MessageBox
10 from TimerEntry import TimerEntry, TimerLog
11 from RecordTimer import RecordTimerEntry, parseEvent
13 from ServiceReference import ServiceReference
14 from Components.config import *
15 from Components.TimerSanityCheck import TimerSanityCheck
17 class TimerEditList(Screen):
18 def __init__(self, session):
19 Screen.__init__(self, session)
25 self["timerlist"] = TimerList(list)
27 self["key_red"] = Button(_("Delete"))
28 self["key_green"] = Button(_("Add"))
29 self["key_yellow"] = Button("")
30 self["key_blue"] = Button(_("Cleanup"))
32 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
36 "red": self.removeTimer,
37 "green": self.addCurrentTimer,
38 "blue": self.cleanupQuestion,
39 "yellow": self.toggleDisabledState,
46 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
47 self.onShown.append(self.updateState)
50 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveUp)
54 self["timerlist"].instance.moveSelection(self["timerlist"].instance.moveDown)
58 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageUp)
62 self["timerlist"].instance.moveSelection(self["timerlist"].instance.pageDown)
65 def toggleDisabledState(self):
66 cur=self["timerlist"].getCurrent()
75 self.session.nav.RecordTimer.timeChanged(t)
79 def updateState(self):
80 if len(self.list) > 0:
81 if self["timerlist"].getCurrent()[0].disabled:
82 self["key_yellow"].setText(_("Enable"))
84 self["key_yellow"].setText(_("Disable"))
85 self["key_yellow"].instance.invalidate()
87 def fillTimerList(self):
90 for timer in self.session.nav.RecordTimer.timer_list:
91 self.list.append(TimerEntryComponent(timer, processed=False))
93 for timer in self.session.nav.RecordTimer.processed_timers:
94 self.list.append(TimerEntryComponent(timer, processed=True))
95 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
98 cur=self["timerlist"].getCurrent()
100 self.session.openWithCallback(self.finishedEdit, TimerLog, cur[0])
103 cur=self["timerlist"].getCurrent()
105 self.session.openWithCallback(self.finishedEdit, TimerEntry, cur[0])
107 def cleanupQuestion(self):
108 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
110 def cleanupTimer(self, delete):
112 self.session.nav.RecordTimer.cleanup()
115 def removeTimer(self):
116 list = self["timerlist"]
117 cur = list.getCurrent()
120 self.session.nav.RecordTimer.removeEntry(timer)
125 self["timerlist"].invalidate()
127 def addCurrentTimer(self):
129 service = self.session.nav.getCurrentService()
130 if service is not None:
131 info = service.info()
133 event = info.getEvent(0)
135 # FIXME only works if already playing a service
136 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
139 data = (int(time()), int(time() + 60), "unknown event", "", None)
141 data = parseEvent(event)
143 self.addTimer(RecordTimerEntry(serviceref, *data))
145 def addTimer(self, timer):
146 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
148 def finishedEdit(self, answer):
149 print "finished edit"
153 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
154 if not timersanitycheck.check():
155 print "Sanity check failed"
157 print "Sanity check passed"
158 self.session.nav.RecordTimer.timeChanged(answer[1])
161 print "Timeredit aborted"
163 def finishedAdd(self, answer):
166 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
167 if not timersanitycheck.check():
168 print "Sanity check failed"
169 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, timersanitycheck.getSimulTimerList())
171 print "Sanity check passed"
173 self.session.nav.RecordTimer.record(entry)
176 print "Timeredit aborted"
178 def finishSanityCorrection(self, answer):
179 self.finishedAdd(answer)
182 self.session.nav.RecordTimer.saveTimer()
183 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
186 def onStateChange(self, entry):
189 class TimerSanityConflict(Screen):
190 def __init__(self, session, timer):
191 Screen.__init__(self, session)
193 print "TimerSanityConflict", timer
195 self["timer1"] = TimerList(self.getTimerList(timer[0]))
197 self["timer2"] = TimerList(self.getTimerList(timer[1]))
199 self["timer2"] = Button("No conflict")
205 self.list.append((_("Conflicting timer") + " " + str(count), x))
208 self["list"] = MenuList(self.list)
210 self["key_red"] = Button("Edit")
211 self["key_green"] = Button("Disable")
212 self["key_yellow"] = Button("Edit")
213 self["key_blue"] = Button("Disable")
215 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
218 #"cancel": self.leave,
219 "red": self.editTimer1,
220 "green": self.disableTimer1,
221 # "yellow": self.editTimer2,
222 # "blue": self.disableTimer2,
223 #"log": self.showLog,
225 #"right": self.right,
230 def getTimerList(self, timer):
231 return [TimerEntryComponent(timer, processed=False)]
233 def editTimer1(self):
234 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent()[0])
236 def disableTimer1(self):
237 self.timer[0].disabled = True
238 self.finishedEdit((True, self.timer[0]))
240 def finishedEdit(self, answer):
241 self.close((True, self.timer[0]))
244 self["list"].instance.moveSelection(self["list"].instance.moveUp)
245 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))
248 self["list"].instance.moveSelection(self["list"].instance.moveDown)
249 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))