1 from Screen import Screen
2 import ChannelSelection
3 from ServiceReference import ServiceReference
4 from Components.config import ConfigSelection, ConfigText, ConfigSubList, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
5 from Components.ActionMap import NumberActionMap
6 from Components.ConfigList import ConfigListScreen
7 from Components.MenuList import MenuList
8 from Components.Button import Button
9 from Components.Label import Label
10 from Components.Pixmap import Pixmap
11 from Screens.ChoiceBox import ChoiceBox
12 from RecordTimer import AFTEREVENT
13 from enigma import eEPGCache
17 class TimerEntry(Screen, ConfigListScreen):
18 def __init__(self, session, timer):
19 Screen.__init__(self, session)
22 self.entryStartDate = None
23 self.entryEndDate = None
24 self.entryService = None
26 self["oktext"] = Label(_("OK"))
27 self["canceltext"] = Label(_("Cancel"))
29 self["cancel"] = Pixmap()
33 self["actions"] = NumberActionMap(["SetupActions"],
37 "cancel": self.keyCancel,
41 ConfigListScreen.__init__(self, self.list, session = session)
42 self.createSetup("config")
44 def createConfig(self):
45 justplay = self.timer.justplay
47 afterevent = { AFTEREVENT.NONE: "nothing", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.STANDBY: "standby"}[self.timer.afterEvent]
49 weekday_table = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
51 # calculate default values
56 if self.timer.repeated: # repeated
58 if (self.timer.repeated == 31): # Mon-Fri
60 elif (self.timer.repeated == 127): # daily
63 flags = self.timer.repeated
67 if flags == 1: # weekly
68 print "Set to weekday " + str(x)
70 if flags & 1 == 1: # set user defined flags
81 weekday = (int(time.strftime("%w", time.localtime(self.timer.begin))) - 1) % 7
84 self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "zap"}[justplay])
85 self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", _("go to deep standby"))], default = afterevent)
86 self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type)
87 self.timerentry_name = ConfigText(default = self.timer.name, visible_width = 50, fixed_size = False)
88 self.timerentry_description = ConfigText(default = self.timer.description, visible_width = 50, fixed_size = False)
90 self.timerentry_repeated = ConfigSelection(default = repeated, choices = [("daily", _("daily")), ("weekly", _("weekly")), ("weekdays", _("Mon-Fri")), ("user", _("user defined"))])
92 self.timerentry_startdate = ConfigDateTime(default = self.timer.begin, formatstring = _("%d.%B %Y"), increment = 86400)
93 self.timerentry_starttime = ConfigClock(default = self.timer.begin)
95 self.timerentry_enddate = ConfigDateTime(default = self.timer.end, formatstring = _("%d.%B %Y"), increment = 86400)
96 self.timerentry_endtime = ConfigClock(default = self.timer.end)
98 self.timerentry_repeatedbegindate = ConfigDateTime(default = self.timer.repeatedbegindate, formatstring = _("%d.%B %Y"), increment = 86400)
100 self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
102 self.timerentry_day = ConfigSubList()
104 self.timerentry_day.append(ConfigYesNo(default = day[x]))
106 # FIXME some service-chooser needed here
108 try: # no current service available?
109 servicename = str(self.timer.service_ref.getServiceName())
112 self.timerentry_service_ref = self.timer.service_ref
113 self.timerentry_service = ConfigSelection([servicename])
115 self.timerentry_startdate.addNotifier(self.checkDate)
116 self.timerentry_enddate.addNotifier(self.checkDate)
118 def checkDate(self, configElement):
119 if configElement is self.timerentry_startdate:
120 if self.timerentry_enddate.value < self.timerentry_startdate.value:
121 self.timerentry_enddate.value = self.timerentry_startdate.value
122 self["config"].invalidate(self.entryEndDate)
123 if configElement is self.timerentry_enddate:
124 if (self.timerentry_enddate.value < self.timerentry_startdate.value):
125 self.timerentry_startdate.value = self.timerentry_enddate.value
126 self["config"].invalidate(self.entryStartDate)
128 def createSetup(self, widget):
130 self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
131 self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
132 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
133 self.list.append(self.timerJustplayEntry)
134 self.timerTypeEntry = getConfigListEntry(_("Repeat Type"), self.timerentry_type)
135 self.list.append(self.timerTypeEntry)
137 if self.timerentry_type.value == "once":
138 self.frequencyEntry = None
140 self.frequencyEntry = getConfigListEntry(_("Frequency"), self.timerentry_repeated)
141 self.list.append(self.frequencyEntry)
142 self.repeatedbegindateEntry = getConfigListEntry(_("Starting on"), self.timerentry_repeatedbegindate)
143 self.list.append(self.repeatedbegindateEntry)
144 if self.timerentry_repeated.value == "daily":
146 if self.timerentry_repeated.value == "weekdays":
148 if self.timerentry_repeated.value == "weekly":
149 self.list.append(getConfigListEntry(_("Weekday"), self.timerentry_weekday))
151 if self.timerentry_repeated.value == "user":
152 self.list.append(getConfigListEntry(_("Monday"), self.timerentry_day[0]))
153 self.list.append(getConfigListEntry(_("Tuesday"), self.timerentry_day[1]))
154 self.list.append(getConfigListEntry(_("Wednesday"), self.timerentry_day[2]))
155 self.list.append(getConfigListEntry(_("Thursday"), self.timerentry_day[3]))
156 self.list.append(getConfigListEntry(_("Friday"), self.timerentry_day[4]))
157 self.list.append(getConfigListEntry(_("Saturday"), self.timerentry_day[5]))
158 self.list.append(getConfigListEntry(_("Sunday"), self.timerentry_day[6]))
160 #self.list.append(getConfigListEntry("StartDate", self.timerentry_startdate))
161 # self.list.append(getConfigListEntry("Weekday", self.timerentry_weekday))
163 self.entryStartDate = getConfigListEntry(_("Start"), self.timerentry_startdate)
164 if self.timerentry_type.value == "once":
165 self.list.append(self.entryStartDate)
166 self.list.append(getConfigListEntry(" ", self.timerentry_starttime))
168 self.list.append(getConfigListEntry(_("StartTime"), self.timerentry_starttime))
170 self.entryEndDate = getConfigListEntry(_("End"), self.timerentry_enddate)
171 if self.timerentry_type.value == "once":
172 if self.timerentry_justplay.value != "zap":
173 self.list.append(self.entryEndDate)
174 self.list.append(getConfigListEntry(" ", self.timerentry_endtime))
176 if self.timerentry_justplay.value != "zap":
177 self.list.append(getConfigListEntry(_("EndTime"), self.timerentry_endtime))
179 if self.timerentry_justplay.value != "zap":
180 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
182 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
183 self.list.append(self.channelEntry)
185 self[widget].list = self.list
186 self[widget].l.setList(self.list)
189 print "newConfig", self["config"].getCurrent()
190 if self["config"].getCurrent() == self.timerTypeEntry:
191 self.createSetup("config")
192 if self["config"].getCurrent() == self.timerJustplayEntry:
193 self.createSetup("config")
194 if self["config"].getCurrent() == self.frequencyEntry:
195 self.createSetup("config")
198 if self["config"].getCurrent() is self.channelEntry:
201 ConfigListScreen.keyLeft(self)
205 if self["config"].getCurrent() is self.channelEntry:
208 ConfigListScreen.keyRight(self)
212 if self["config"].getCurrent() == self.channelEntry:
213 self.session.openWithCallback(self.finishedChannelSelection, ChannelSelection.SimpleChannelSelection, _("Select channel to record from"))
217 def finishedChannelSelection(self, *args):
219 self.timerentry_service_ref = ServiceReference(args[0])
220 self.timerentry_service.setCurrentText(self.timerentry_service_ref.getServiceName())
221 self["config"].invalidate(self.channelEntry)
223 def getTimestamp(self, date, mytime):
224 d = time.localtime(date)
225 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
226 return int(time.mktime(dt.timetuple()))
228 def buildRepeatedBegin(self, rep_time, start_time):
229 d = time.localtime(rep_time)
230 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, start_time[0], start_time[1])
231 return int(time.mktime(dt.timetuple()))
233 def getBeginEnd(self):
234 enddate = self.timerentry_enddate.value
235 endtime = self.timerentry_endtime.value
237 startdate = self.timerentry_startdate.value
238 starttime = self.timerentry_starttime.value
240 begin = self.getTimestamp(startdate, starttime)
241 end = self.getTimestamp(enddate, endtime)
243 # because of the dateChecks, startdate can't be < enddate.
244 # however, the endtime can be less than the starttime.
245 # in this case, add 1 day.
251 self.timer.name = self.timerentry_name.value
252 self.timer.description = self.timerentry_description.value
253 self.timer.justplay = self.timerentry_justplay.value == "zap"
254 self.timer.resetRepeated()
255 self.timer.afterEvent = {"nothing": AFTEREVENT.NONE, "deepstandby": AFTEREVENT.DEEPSTANDBY, "standby": AFTEREVENT.STANDBY}[self.timerentry_afterevent.value]
256 self.timer.service_ref = self.timerentry_service_ref
258 if self.timerentry_type.value == "once":
259 self.timer.begin, self.timer.end = self.getBeginEnd()
260 if self.timerentry_type.value == "repeated":
261 if self.timerentry_repeated.value == "daily":
263 self.timer.setRepeated(x)
265 if self.timerentry_repeated.value == "weekly":
266 self.timer.setRepeated(self.timerentry_weekday.index)
268 if self.timerentry_repeated.value == "weekdays":
270 self.timer.setRepeated(x)
272 if self.timerentry_repeated.value == "user":
274 if self.timerentry_day[x].value:
275 self.timer.setRepeated(x)
277 self.timer.repeatedbegindate = self.buildRepeatedBegin(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
278 self.timer.begin = self.getTimestamp(time.time(), self.timerentry_starttime.value)
279 self.timer.end = self.getTimestamp(time.time(), self.timerentry_endtime.value)
281 # when a timer end is set before the start, add 1 day
282 if self.timer.end < self.timer.begin:
283 self.timer.end += 86400
285 if self.timer.eit is not None:
286 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
287 if event is not None:
288 n = event.getNumOfLinkageServices()
291 ref = self.session.nav.getCurrentlyPlayingServiceReference()
292 parent = self.timer.service_ref.ref
295 i = event.getLinkageService(parent, x)
296 if i.toString() == ref.toString():
298 tlist.append((i.getName(), i))
299 self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice to record..."), list = tlist, selection = selection)
303 self.close((True, self.timer))
305 def subserviceSelected(self, service):
306 if not service is None:
307 self.timer.service_ref = ServiceReference(service[1])
309 self.close((True, self.timer))
312 self.session.nav.RecordTimer.saveTimer()
317 class TimerLog(Screen):
318 def __init__(self, session, timer):
319 Screen.__init__(self, session)
321 self.log_entries = self.timer.log_entries[:]
325 self["loglist"] = MenuList(self.list)
326 self["logentry"] = Label()
328 self["key_red"] = Button(_("Delete entry"))
329 self["key_green"] = Button()
330 self["key_yellow"] = Button("")
331 self["key_blue"] = Button(_("Clear log"))
333 self.onShown.append(self.updateText)
335 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
338 "cancel": self.keyClose,
343 "red": self.deleteEntry,
344 "blue": self.clearLog
347 def deleteEntry(self):
348 cur = self["loglist"].getCurrent()
351 self.log_entries.remove(cur[1])
353 self["loglist"].l.setList(self.list)
356 def fillLogList(self):
358 for x in self.log_entries:
359 self.list.append((str(time.strftime("%Y-%m-%d %H-%M", time.localtime(x[0])) + " - " + x[2]), x))
362 self.log_entries = []
364 self["loglist"].l.setList(self.list)
368 if self.timer.log_entries != self.log_entries:
369 self.timer.log_entries = self.log_entries
370 self.close((True, self.timer))
375 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
379 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
383 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
387 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
390 def updateText(self):
391 if len(self.list) > 0:
392 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
394 self["logentry"].setText("")