X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/301bab11f8453a6899153b7be338a352803b22cb..a22d3f73478b27ed19f8e412ccf15fad033e7bd4:/lib/python/Screens/TimerEdit.py?ds=sidebyside diff --git a/lib/python/Screens/TimerEdit.py b/lib/python/Screens/TimerEdit.py index 173b1ba2..73733913 100644 --- a/lib/python/Screens/TimerEdit.py +++ b/lib/python/Screens/TimerEdit.py @@ -1,72 +1,94 @@ from Screen import Screen -from Components.TimerList import TimerList, TimerEntry +from Components.TimerList import TimerList, TimerEntryComponent from Components.ActionMap import ActionMap from Components.TimeInput import TimeInput from Components.Label import Label from Components.Button import Button from Components.TextInput import TextInput +from TimerEntry import TimerEntry +from RecordTimer import RecordTimerEntry, parseEvent +from time import * +from ServiceReference import ServiceReference +from Components.config import * -class TimerEdit(Screen): - def __init__(self, session, entry): +class TimerEditList(Screen): + def __init__(self, session): Screen.__init__(self, session) + + list = [ ] + self.list = list + self.fillTimerList() - self["actions"] = ActionMap(["OkCancelActions"], - { - "ok": self.apply, - "cancel": self.close - }) + self["timerlist"] = TimerList(list) - self["shortcuts"] = ActionMap(["ShortcutActions"], + self["key_red"] = Button(_("Delete")) + self["key_green"] = Button(_("Add")) + self["key_yellow"] = Button("") + self["key_blue"] = Button("") + + self["actions"] = ActionMap(["OkCancelActions", "ShortcutActions"], { - "red": self.beginFocus, - "yellow": self.endFocus, - "green": self.descFocus + "ok": self.openEdit, + "cancel": self.leave, + "red": self.removeTimer, + "green": self.addCurrentTimer }) + + def fillTimerList(self): + del self.list[:] - self.entry = entry - # begin, end, description, service - self["begin"] = TimeInput() - self["end"] = TimeInput() - - self["lbegin"] = Label("Begin") - self["lend"] = Label("End") + for timer in self.session.nav.RecordTimer.timer_list: + self.list.append(TimerEntryComponent(timer, 0)) - self["description"] = TextInput() - self["apply"] = Button("Apply") - self["service"] = Button() + for timer in self.session.nav.RecordTimer.processed_timers: + self.list.append(TimerEntryComponent(timer, 1)) + + def openEdit(self): + self.session.openWithCallback(self.finishedEdit, TimerEntry, self["timerlist"].getCurrent()[0]) + #self.session.open(TimerEdit, self["timerlist"].getCurrent()[0]) - self["description"].setText(entry.description); - - def beginFocus(self): - self.setFocus(self["begin"]) - - def endFocus(self): - self.setFocus(self["end"]) + def removeTimer(self): + # FIXME doesn't work... + self.session.nav.RecordTimer.removeEntry(self["timerlist"].getCurrent()[0]) + self.fillTimerList() + self["timerlist"].invalidate() - def descFocus(self): - self.setFocus(self["description"]) - - def apply(self): - print "applied!" - -class TimerEditList(Screen): - def __init__(self, session): - Screen.__init__(self, session) + def addCurrentTimer(self): + event = None + service = self.session.nav.getCurrentService() + if service is not None: + info = service.info() + if info is not None: + event = info.getEvent(0) + + # FIXME only works if already playing a service + serviceref = ServiceReference(self.session.nav.getCurrentlyPlayingServiceReference()) - list = [ ] - for timer in session.nav.RecordTimer.timer_list: - list.append(TimerEntry(timer, 0)) + if event is None: + data = (int(time()), int(time() + 60), "unknown event", "", None) + else: + data = parseEvent(event) + + self.addTimer(RecordTimerEntry(serviceref, *data)) - for timer in session.nav.RecordTimer.processed_timers: - list.append(TimerEntry(timer, 1)) + def addTimer(self, timer): + self.session.openWithCallback(self.finishedAdd, TimerEntry, timer) - self["timerlist"] = TimerList(list) - - self["actions"] = ActionMap(["OkCancelActions"], - { -# "ok": self.openEdit, - "cancel": self.close - }) + def finishedEdit(self, answer): + if (answer[0]): + print "Edited timer" + self.session.nav.RecordTimer.timeChanged(answer[1]) + self.fillTimerList() + else: + print "Timeredit aborted" + + def finishedAdd(self, answer): + if (answer[0]): + self.session.nav.RecordTimer.record(answer[1]) + self.fillTimerList() + else: + print "Timeredit aborted" - def openEdit(self): - self.session.open(TimerEdit, self["timerlist"].getCurrent()[0]) + def leave(self): + self.session.nav.RecordTimer.saveTimer() + self.close()