1 from Screen import Screen
2 from Components.TimerList import TimerList, TimerEntryComponent
3 from Components.ActionMap import ActionMap
4 from Components.TimeInput import TimeInput
5 from Components.Label import Label
6 from Components.Button import Button
7 from TimerEntry import TimerEntry
8 from RecordTimer import RecordTimerEntry, parseEvent
10 from ServiceReference import ServiceReference
11 from Components.config import *
13 class TimerEditList(Screen):
14 def __init__(self, session):
15 Screen.__init__(self, session)
21 self["timerlist"] = TimerList(list)
23 self["key_red"] = Button(_("Delete"))
24 self["key_green"] = Button(_("Add"))
25 self["key_yellow"] = Button("")
26 self["key_blue"] = Button("")
28 self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"],
32 "red": self.removeTimer,
33 "green": self.addCurrentTimer
35 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
37 def fillTimerList(self):
40 for timer in self.session.nav.RecordTimer.timer_list:
41 self.list.append(TimerEntryComponent(timer, processed=False))
43 for timer in self.session.nav.RecordTimer.processed_timers:
44 self.list.append(TimerEntryComponent(timer, processed=True))
47 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
48 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
50 def removeTimer(self):
51 list = self["timerlist"]
52 currentIndex = list.getCurrentIndex()
54 if list.getCurrentIndex() == currentIndex:
56 list.moveToIndex(currentIndex)
57 self.session.nav.RecordTimer.removeEntry(list.getCurrent()[0])
62 self["timerlist"].invalidate()
64 def addCurrentTimer(self):
66 service = self.session.nav.getCurrentService()
67 if service is not None:
70 event = info.getEvent(0)
72 # FIXME only works if already playing a service
73 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
76 data = (int(time()), int(time() + 60), "unknown event", "", None)
78 data = parseEvent(event)
80 self.addTimer(RecordTimerEntry(serviceref, *data))
82 def addTimer(self, timer):
83 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
85 def finishedEdit(self, answer):
89 self.session.nav.RecordTimer.timeChanged(answer[1])
92 print "Timeredit aborted"
94 def finishedAdd(self, answer):
98 self.session.nav.RecordTimer.record(entry)
101 print "Timeredit aborted"
104 self.session.nav.RecordTimer.saveTimer()
105 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
108 def onStateChange(self, entry):