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
70 def updateState(self):
71 if len(self.list) > 0:
72 if self["timerlist"].getCurrent()[0].disabled:
73 self["key_yellow"].setText(_("Enable"))
75 self["key_yellow"].setText(_("Disable"))
76 self["key_yellow"].instance.invalidate()
78 def fillTimerList(self):
81 for timer in self.session.nav.RecordTimer.timer_list:
82 self.list.append(TimerEntryComponent(timer, processed=False))
84 for timer in self.session.nav.RecordTimer.processed_timers:
85 self.list.append(TimerEntryComponent(timer, processed=True))
88 self.session.openWithCallback(self.finishedEdit, TimerLog, self["timerlist"].getCurrent()[0])
91 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
92 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
94 def cleanupQuestion(self):
95 self.session.openWithCallback(self.cleanupTimer, MessageBox, _("Really delete done timers?"))
97 def cleanupTimer(self, delete):
99 self.session.nav.RecordTimer.cleanup()
102 def removeTimer(self):
103 list = self["timerlist"]
104 timer = list.getCurrent()[0]
105 currentIndex = list.getCurrentIndex()
106 self.session.nav.RecordTimer.removeEntry(timer)
108 if list.getCurrentIndex() == currentIndex:
111 list.moveToIndex(currentIndex)
115 self["timerlist"].invalidate()
117 def addCurrentTimer(self):
119 service = self.session.nav.getCurrentService()
120 if service is not None:
121 info = service.info()
123 event = info.getEvent(0)
125 # FIXME only works if already playing a service
126 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
129 data = (int(time()), int(time() + 60), "unknown event", "", None)
131 data = parseEvent(event)
133 self.addTimer(RecordTimerEntry(serviceref, *data))
135 def addTimer(self, timer):
136 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
138 def finishedEdit(self, answer):
139 print "finished edit"
143 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
144 if not timersanitycheck.check():
145 print "Sanity check failed"
147 print "Sanity check passed"
148 self.session.nav.RecordTimer.timeChanged(answer[1])
151 print "Timeredit aborted"
153 def finishedAdd(self, answer):
156 timersanitycheck = TimerSanityCheck(self.session.nav.RecordTimer.timer_list, answer[1])
157 if not timersanitycheck.check():
158 print "Sanity check failed"
159 self.session.openWithCallback(self.finishSanityCorrection, TimerSanityConflict, timersanitycheck.getSimulTimerList())
161 print "Sanity check passed"
163 self.session.nav.RecordTimer.record(entry)
166 print "Timeredit aborted"
168 def finishSanityCorrection(self, answer):
169 self.finishedAdd(answer)
172 self.session.nav.RecordTimer.saveTimer()
173 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
176 def onStateChange(self, entry):
179 class TimerSanityConflict(Screen):
180 def __init__(self, session, timer):
181 Screen.__init__(self, session)
185 self["timer1"] = TimerList(self.getTimerList(timer[0]))
187 self["timer2"] = TimerList(self.getTimerList(timer[1]))
189 self["timer2"] = Button("No conflict")
195 self.list.append((_("Conflicting timer") + " " + str(count), x))
198 self["list"] = MenuList(self.list)
200 self["key_red"] = Button("Edit")
201 self["key_green"] = Button("Disable")
202 self["key_yellow"] = Button("Edit")
203 self["key_blue"] = Button("Disable")
205 self["actions"] = ActionMap(["OkCancelActions", "DirectionActions", "ShortcutActions", "TimerEditActions"],
208 #"cancel": self.leave,
209 "red": self.editTimer1,
210 "green": self.disableTimer1,
211 # "yellow": self.editTimer2,
212 # "blue": self.disableTimer2,
213 #"log": self.showLog,
215 #"right": self.right,
220 def getTimerList(self, timer):
221 return [TimerEntryComponent(timer, processed=False)]
223 def editTimer1(self):
224 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timer1"].getCurrent()[0])
226 def disableTimer1(self):
227 self.timer[0].disabled = True
228 self.finishedEdit((True, self.timer[0]))
230 def finishedEdit(self, answer):
231 self.close((True, self.timer[0]))
234 self["list"].instance.moveSelection(self["list"].instance.moveUp)
235 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))
238 self["list"].instance.moveSelection(self["list"].instance.moveDown)
239 self["timer2"].l.setList(self.getTimerList(self["list"].getCurrent()[1]))