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 self["timerlist"].getCurrent()[0].disabled = not self["timerlist"].getCurrent()[0].disabled
67 self.session.nav.RecordTimer.timeChanged(self["timerlist"].getCurrent()[0])
71 def updateState(self):
72 if len(self.list) > 0:
73 if self["timerlist"].getCurrent()[0].disabled:
74 self["key_yellow"].setText(_("Enable"))
76 self["key_yellow"].setText(_("Disable"))
77 self["key_yellow"].instance.invalidate()
79 def fillTimerList(self):
82 for timer in self.session.nav.RecordTimer.timer_list:
83 self.list.append(TimerEntryComponent(timer, processed=False))
85 for timer in self.session.nav.RecordTimer.processed_timers:
86 self.list.append(TimerEntryComponent(timer, processed=True))
87 self.list.sort(cmp = lambda x, y: x[0].begin < y[0].begin)
90 self.session.openWithCallback(self.finishedEdit, TimerLog, self["timerlist"].getCurrent()[0])
93 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
94 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
96 def cleanupQuestion(self):
97 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
99 def cleanupTimer(self, delete):
101 self.session.nav.RecordTimer.cleanup()
104 def removeTimer(self):
105 list = self["timerlist"]
106 timer = list.getCurrent()[0]
107 self.session.nav.RecordTimer.removeEntry(timer)
112 self["timerlist"].invalidate()
114 def addCurrentTimer(self):
116 service = self.session.nav.getCurrentService()
117 if service is not None:
118 info = service.info()
120 event = info.getEvent(0)
122 # FIXME only works if already playing a service
123 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
126 data = (int(time()), int(time() + 60), "unknown event", "", None)
128 data = parseEvent(event)
130 self.addTimer(RecordTimerEntry(serviceref, *data))
132 def addTimer(self, timer):
133 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
135 def finishedEdit(self, answer):
136 print "finished edit"
140 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
141 if not timersanitycheck.check():
142 print "Sanity check failed"
144 print "Sanity check passed"
145 self.session.nav.RecordTimer.timeChanged(answer[1])
148 print "Timeredit aborted"
150 def finishedAdd(self, answer):
153 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
154 if not timersanitycheck.check():
155 print "Sanity check failed"
156 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, timersanitycheck.getSimulTimerList())
158 print "Sanity check passed"
160 self.session.nav.RecordTimer.record(entry)
163 print "Timeredit aborted"
165 def finishSanityCorrection(self, answer):
166 self.finishedAdd(answer)
169 self.session.nav.RecordTimer.saveTimer()
170 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
173 def onStateChange(self, entry):
176 class TimerSanityConflict(Screen):
177 def __init__(self, session, timer):
178 Screen.__init__(self, session)
180 print "TimerSanityConflict", timer
182 self["timer1"] = TimerList(self.getTimerList(timer[0]))
184 self["timer2"] = TimerList(self.getTimerList(timer[1]))
186 self["timer2"] = Button("No conflict")
192 self.list.append((_("Conflicting timer") + " " + str(count), x))
195 self["list"] = MenuList(self.list)
197 self["key_red"] = Button("Edit")
198 self["key_green"] = Button("Disable")
199 self["key_yellow"] = Button("Edit")
200 self["key_blue"] = Button("Disable")
202 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
205 #"cancel": self.leave,
206 "red": self.editTimer1,
207 "green": self.disableTimer1,
208 # "yellow": self.editTimer2,
209 # "blue": self.disableTimer2,
210 #"log": self.showLog,
212 #"right": self.right,
217 def getTimerList(self, timer):
218 return [TimerEntryComponent(timer, processed=False)]
220 def editTimer1(self):
221 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent()[0])
223 def disableTimer1(self):
224 self.timer[0].disabled = True
225 self.finishedEdit((True, self.timer[0]))
227 def finishedEdit(self, answer):
228 self.close((True, self.timer[0]))
231 self["list"].instance.moveSelection(self["list"].instance.moveUp)
232 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))
235 self["list"].instance.moveSelection(self["list"].instance.moveDown)
236 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))