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, TimerLog
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", "TimerEditActions"],
32 "red": self.removeTimer,
33 "green": self.addCurrentTimer,
36 self.session.nav.RecordTimer.on_state_change.append(self.onStateChange)
38 def fillTimerList(self):
41 for timer in self.session.nav.RecordTimer.timer_list:
42 self.list.append(TimerEntryComponent(timer, processed=False))
44 for timer in self.session.nav.RecordTimer.processed_timers:
45 self.list.append(TimerEntryComponent(timer, processed=True))
48 self.session.openWithCallback(self.finishedEdit, TimerLog, self["timerlist"].getCurrent()[0])
51 self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0])
52 #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0])
54 def removeTimer(self):
55 list = self["timerlist"]
56 currentIndex = list.getCurrentIndex()
58 if list.getCurrentIndex() == currentIndex:
60 list.moveToIndex(currentIndex)
61 self.session.nav.RecordTimer.removeEntry(list.getCurrent()[0])
66 self["timerlist"].invalidate()
68 def addCurrentTimer(self):
70 service = self.session.nav.getCurrentService()
71 if service is not None:
74 event = info.getEvent(0)
76 # FIXME only works if already playing a service
77 serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference())
80 data = (int(time()), int(time() + 60), "unknown event", "", None)
82 data = parseEvent(event)
84 self.addTimer(RecordTimerEntry(serviceref, *data))
86 def addTimer(self, timer):
87 self.session.openWithCallback(self.finishedAdd, TimerEntry, timer)
89 def finishedEdit(self, answer):
93 self.session.nav.RecordTimer.timeChanged(answer[1])
96 print "Timeredit aborted"
98 def finishedAdd(self, answer):
102 self.session.nav.RecordTimer.record(entry)
105 print "Timeredit aborted"
108 self.session.nav.RecordTimer.saveTimer()
109 self.session.nav.RecordTimer.on_state_change.remove(self.onStateChange)
112 def onStateChange(self, entry):