PEP8: Fix whitespace
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / TimerEntry.py
1 from Screen import Screen
2 import ChannelSelection
3 from ServiceReference import ServiceReference
4 from Components.config import config, 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 Components.SystemInfo import SystemInfo
12 from Components.UsageConfig import defaultMoviePath
13 from Screens.MovieSelection import getPreferredTagEditor
14 from Screens.LocationBox import MovieLocationBox
15 from Screens.ChoiceBox import ChoiceBox
16 from Screens.MessageBox import MessageBox
17 from Screens.VirtualKeyBoard import VirtualKeyBoard
18 from RecordTimer import AFTEREVENT
19 from enigma import eEPGCache, eServiceReference
20 from time import localtime, mktime, time, strftime
21 from datetime import datetime
22
23 class TimerEntry(Screen, ConfigListScreen):
24         def __init__(self, session, timer):
25                 Screen.__init__(self, session)
26                 self.timer = timer
27
28                 self.entryDate = None
29                 self.entryService = None
30
31                 self["oktext"] = Label(_("OK"))
32                 self["canceltext"] = Label(_("Cancel"))
33                 self["ok"] = Pixmap()
34                 self["cancel"] = Pixmap()
35                 self["key_yellow"] = Label(_("Timer type"))
36                 self["key_blue"] = Label()
37
38                 self.createConfig()
39
40                 self["actions"] = NumberActionMap(["SetupActions", "GlobalActions", "PiPSetupActions", "ColorActions"],
41                 {
42                         "ok": self.keySelect,
43                         "save": self.keyGo,
44                         "cancel": self.keyCancel,
45                         "volumeUp": self.incrementStart,
46                         "volumeDown": self.decrementStart,
47                         "size+": self.incrementEnd,
48                         "size-": self.decrementEnd,
49                         "yellow": self.changeTimerType,
50                         "blue": self.changeZapWakeupType
51                 }, -2)
52
53                 self.list = []
54                 ConfigListScreen.__init__(self, self.list, session = session)
55                 self.setTitle(_("Timer entry"))
56                 self.createSetup("config")
57
58         def createConfig(self):
59                         justplay = self.timer.justplay
60                         always_zap = self.timer.always_zap
61                         zap_wakeup = self.timer.zap_wakeup
62                         rename_repeat = self.timer.rename_repeat
63                         conflict_detection = self.timer.conflict_detection
64
65                         afterevent = {
66                                 AFTEREVENT.NONE: "nothing",
67                                 AFTEREVENT.DEEPSTANDBY: "deepstandby",
68                                 AFTEREVENT.STANDBY: "standby",
69                                 AFTEREVENT.AUTO: "auto"
70                                 }[self.timer.afterEvent]
71
72                         if self.timer.record_ecm and self.timer.descramble:
73                                 recordingtype = "descrambled+ecm"
74                         elif self.timer.record_ecm:
75                                 recordingtype = "scrambled+ecm"
76                         elif self.timer.descramble:
77                                 recordingtype = "normal"
78
79                         weekday_table = ("mon", "tue", "wed", "thu", "fri", "sat", "sun")
80
81                         # calculate default values
82                         day = []
83                         weekday = 0
84                         for x in (0, 1, 2, 3, 4, 5, 6):
85                                 day.append(0)
86                         if self.timer.repeated: # repeated
87                                 type = "repeated"
88                                 if (self.timer.repeated == 31): # Mon-Fri
89                                         repeated = "weekdays"
90                                 elif (self.timer.repeated == 127): # daily
91                                         repeated = "daily"
92                                 else:
93                                         flags = self.timer.repeated
94                                         repeated = "user"
95                                         count = 0
96                                         for x in (0, 1, 2, 3, 4, 5, 6):
97                                                 if flags == 1: # weekly
98                                                         print "Set to weekday " + str(x)
99                                                         weekday = x
100                                                 if flags & 1 == 1: # set user defined flags
101                                                         day[x] = 1
102                                                         count += 1
103                                                 else:
104                                                         day[x] = 0
105                                                 flags = flags >> 1
106                                         if count == 1:
107                                                 repeated = "weekly"
108                         else: # once
109                                 type = "once"
110                                 repeated = None
111                                 weekday = int(strftime("%u", localtime(self.timer.begin))) - 1
112                                 day[weekday] = 1
113
114                         self.timerentry_justplay = ConfigSelection(choices = [
115                                 ("zap", _("zap")), ("record", _("record")), ("zap+record", _("zap and record"))],
116                                 default = {0: "record", 1: "zap", 2: "zap+record"}[justplay + 2*always_zap])
117                         if SystemInfo["DeepstandbySupport"]:
118                                 shutdownString = _("go to deep standby")
119                                 choicelist = [("always", _("always")), ("from_standby", _("only from standby")), ("from_deep_standby", _("only from deep standby")), ("never", _("never"))]
120                         else:
121                                 shutdownString = _("shut down")
122                                 choicelist = [("always", _("always")), ("never", _("never"))]
123                         self.timerentry_zapwakeup = ConfigSelection(choices = choicelist, default = zap_wakeup)
124                         self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("standby", _("go to standby")), ("deepstandby", shutdownString), ("auto", _("auto"))], default = afterevent)
125                         self.timerentry_recordingtype = ConfigSelection(choices = [("normal", _("normal")), ("descrambled+ecm", _("descramble and record ecm")), ("scrambled+ecm", _("don't descramble, record ecm"))], default = recordingtype)
126                         self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type)
127                         self.timerentry_name = ConfigText(default = self.timer.name, visible_width = 50, fixed_size = False)
128                         self.timerentry_description = ConfigText(default = self.timer.description, visible_width = 50, fixed_size = False)
129                         self.timerentry_tags = self.timer.tags[:]
130                         self.timerentry_tagsset = ConfigSelection(choices = [not self.timerentry_tags and "None" or " ".join(self.timerentry_tags)])
131
132                         self.timerentry_repeated = ConfigSelection(default = repeated, choices = [("weekly", _("weekly")), ("daily", _("daily")), ("weekdays", _("Mon-Fri")), ("user", _("user defined"))])
133                         self.timerentry_renamerepeat = ConfigYesNo(default = rename_repeat)
134
135                         self.timerentry_conflictdetection = ConfigYesNo(default = conflict_detection)
136
137                         self.timerentry_date = ConfigDateTime(default = self.timer.begin, formatstring = _("%d.%B %Y"), increment = 86400)
138                         self.timerentry_starttime = ConfigClock(default = self.timer.begin)
139                         self.timerentry_endtime = ConfigClock(default = self.timer.end)
140                         self.timerentry_showendtime = ConfigSelection(default = ((self.timer.end - self.timer.begin) > 4), choices = [(True, _("yes")), (False, _("no"))])
141
142                         default = self.timer.dirname or defaultMoviePath()
143                         tmp = config.movielist.videodirs.value
144                         if default not in tmp:
145                                 tmp.append(default)
146                         self.timerentry_dirname = ConfigSelection(default = default, choices = tmp)
147
148                         self.timerentry_repeatedbegindate = ConfigDateTime(default = self.timer.repeatedbegindate, formatstring = _("%d.%B %Y"), increment = 86400)
149
150                         self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
151
152                         self.timerentry_day = ConfigSubList()
153                         for x in (0, 1, 2, 3, 4, 5, 6):
154                                 self.timerentry_day.append(ConfigYesNo(default = day[x]))
155
156                         # FIXME some service-chooser needed here
157                         servicename = "N/A"
158                         try: # no current service available?
159                                 servicename = str(self.timer.service_ref.getServiceName())
160                         except:
161                                 pass
162                         self.timerentry_service_ref = self.timer.service_ref
163                         self.timerentry_service = ConfigSelection([servicename])
164
165         def createSetup(self, widget):
166                 self.list = []
167                 self.entryName = getConfigListEntry(_("Name"), self.timerentry_name)
168                 self.list.append(self.entryName)
169                 self.entryDescription = getConfigListEntry(_("Description"), self.timerentry_description)
170                 self.list.append(self.entryDescription)
171                 self.timerJustplayEntry = getConfigListEntry(_("Timer type"), self.timerentry_justplay)
172                 self.list.append(self.timerJustplayEntry)
173                 self.timerTypeEntry = getConfigListEntry(_("Repeat type"), self.timerentry_type)
174                 self.list.append(self.timerTypeEntry)
175
176                 if self.timerentry_type.value == "once":
177                         self.frequencyEntry = None
178                 else: # repeated
179                         self.frequencyEntry = getConfigListEntry(_("Repeats"), self.timerentry_repeated)
180                         self.list.append(self.frequencyEntry)
181                         self.repeatedbegindateEntry = getConfigListEntry(_("Starting on"), self.timerentry_repeatedbegindate)
182                         self.list.append(self.repeatedbegindateEntry)
183                         if self.timerentry_repeated.value == "daily":
184                                 pass
185                         if self.timerentry_repeated.value == "weekdays":
186                                 pass
187                         if self.timerentry_repeated.value == "weekly":
188                                 self.list.append(getConfigListEntry(_("Weekday"), self.timerentry_weekday))
189
190                         if self.timerentry_repeated.value == "user":
191                                 self.list.append(getConfigListEntry(_("Monday"), self.timerentry_day[0]))
192                                 self.list.append(getConfigListEntry(_("Tuesday"), self.timerentry_day[1]))
193                                 self.list.append(getConfigListEntry(_("Wednesday"), self.timerentry_day[2]))
194                                 self.list.append(getConfigListEntry(_("Thursday"), self.timerentry_day[3]))
195                                 self.list.append(getConfigListEntry(_("Friday"), self.timerentry_day[4]))
196                                 self.list.append(getConfigListEntry(_("Saturday"), self.timerentry_day[5]))
197                                 self.list.append(getConfigListEntry(_("Sunday"), self.timerentry_day[6]))
198                         if self.timerentry_justplay.value != "zap":
199                                 self.list.append(getConfigListEntry(_("Rename name and description for new events"), self.timerentry_renamerepeat))
200
201                 self.entryDate = getConfigListEntry(_("Date"), self.timerentry_date)
202                 if self.timerentry_type.value == "once":
203                         self.list.append(self.entryDate)
204
205                 self.entryStartTime = getConfigListEntry(_("Start time"), self.timerentry_starttime)
206                 self.list.append(self.entryStartTime)
207
208                 self.entryShowEndTime = getConfigListEntry(_("Set end time"), self.timerentry_showendtime)
209                 self.entryZapWakeup = getConfigListEntry(_("Wakeup receiver for start timer"), self.timerentry_zapwakeup)
210                 if self.timerentry_justplay.value == "zap":
211                         self.list.append(self.entryZapWakeup)
212                         self.list.append(self.entryShowEndTime)
213                         self["key_blue"].setText(_("Wakeup type"))
214                 else:
215                         self["key_blue"].setText("")
216                 self.entryEndTime = getConfigListEntry(_("End time"), self.timerentry_endtime)
217                 if self.timerentry_justplay.value != "zap" or self.timerentry_showendtime.value:
218                         self.list.append(self.entryEndTime)
219
220                 self.conflictDetectionEntry = getConfigListEntry(_("Enable timer conflict detection"), self.timerentry_conflictdetection)
221                 self.list.append(self.conflictDetectionEntry)
222
223                 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
224                 self.list.append(self.channelEntry)
225
226                 self.dirname = getConfigListEntry(_("Location"), self.timerentry_dirname)
227                 self.tagsSet = getConfigListEntry(_("Tags"), self.timerentry_tagsset)
228                 if self.timerentry_justplay.value != "zap":
229                         if config.usage.setup_level.index >= 2: # expert+
230                                 self.list.append(self.dirname)
231                         if getPreferredTagEditor():
232                                 self.list.append(self.tagsSet)
233                         self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
234                         self.list.append(getConfigListEntry(_("Recording type"), self.timerentry_recordingtype))
235
236                 self[widget].list = self.list
237                 self[widget].l.setList(self.list)
238
239         def newConfig(self):
240                 print "newConfig", self["config"].getCurrent()
241                 if self["config"].getCurrent() in (self.timerTypeEntry, self.timerJustplayEntry, self.frequencyEntry, self.entryShowEndTime):
242                         self.createSetup("config")
243
244         def keyLeft(self):
245                 cur = self["config"].getCurrent()
246                 if cur in (self.channelEntry, self.tagsSet):
247                         self.keySelect()
248                 elif cur in (self.entryName, self.entryDescription):
249                         self.renameEntry()
250                 else:
251                         ConfigListScreen.keyLeft(self)
252                         self.newConfig()
253
254         def keyRight(self):
255                 cur = self["config"].getCurrent()
256                 if cur in (self.channelEntry, self.tagsSet):
257                         self.keySelect()
258                 elif cur in (self.entryName, self.entryDescription):
259                         self.renameEntry()
260                 else:
261                         ConfigListScreen.keyRight(self)
262                         self.newConfig()
263
264         def renameEntry(self):
265                 cur = self["config"].getCurrent()
266                 if cur == self.entryName:
267                         title_text = _("Please enter new name:")
268                         old_text = self.timerentry_name.value
269                 else:
270                         title_text = _("Please enter new description:")
271                         old_text = self.timerentry_description.value
272                 self.session.openWithCallback(self.renameEntryCallback, VirtualKeyBoard, title=title_text, text=old_text)
273
274         def renameEntryCallback(self, answer):
275                 if answer:
276                         cur = self["config"].getCurrent()
277                         if cur == self.entryName:
278                                 self.timerentry_name.value = answer
279                                 self["config"].invalidate(self.entryName)
280                         else:
281                                 self.timerentry_description.value = answer
282                                 self["config"].invalidate(self.entryDescription)
283
284         def handleKeyFileCallback(self, answer):
285                 if self["config"].getCurrent() in (self.channelEntry, self.tagsSet):
286                         self.keySelect()
287                 else:
288                         ConfigListScreen.handleKeyFileCallback(self, answer)
289                         self.newConfig()
290
291         def openMovieLocationBox(self, answer=""):
292                 self.session.openWithCallback(
293                         self.pathSelected,
294                         MovieLocationBox,
295                         _("Select target folder"),
296                         self.timerentry_dirname.value,
297                         filename = answer,
298                         minFree = 100 # We require at least 100MB free space
299                         )
300
301         def keySelect(self):
302                 cur = self["config"].getCurrent()
303                 if cur == self.channelEntry:
304                         self.session.openWithCallback(
305                                 self.finishedChannelSelection,
306                                 ChannelSelection.SimpleChannelSelection,
307                                 _("Select channel to record from"),
308                                 currentBouquet=True
309                         )
310                 elif config.usage.setup_level.index >= 2 and cur == self.dirname:
311                         menu = [(_("Open select location"), "empty")]
312                         if self.timerentry_type.value == "repeated" and self.timerentry_name.value:
313                                 menu.append((_("Open select location as timer name"), "timername"))
314                         if len(menu) == 1:
315                                 self.openMovieLocationBox()
316                         elif len(menu) == 2:
317                                 text = _("Select action")
318                                 def selectAction(choice):
319                                         if choice:
320                                                 if choice[1] == "timername":
321                                                         self.openMovieLocationBox(self.timerentry_name.value)
322                                                 elif choice[1] == "empty":
323                                                         self.openMovieLocationBox()
324                                 self.session.openWithCallback(selectAction, ChoiceBox, title=text, list=menu)
325
326                 elif getPreferredTagEditor() and cur == self.tagsSet:
327                         self.session.openWithCallback(
328                                 self.tagEditFinished,
329                                 getPreferredTagEditor(),
330                                 self.timerentry_tags
331                         )
332                 else:
333                         self.keyGo()
334
335         def finishedChannelSelection(self, *args):
336                 if args:
337                         self.timerentry_service_ref = ServiceReference(args[0])
338                         self.timerentry_service.setCurrentText(self.timerentry_service_ref.getServiceName())
339                         self["config"].invalidate(self.channelEntry)
340
341         def getTimestamp(self, date, mytime):
342                 d = localtime(date)
343                 dt = datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
344                 return int(mktime(dt.timetuple()))
345
346         def getBeginEnd(self):
347                 date = self.timerentry_date.value
348                 endtime = self.timerentry_endtime.value
349                 starttime = self.timerentry_starttime.value
350
351                 begin = self.getTimestamp(date, starttime)
352                 end = self.getTimestamp(date, endtime)
353
354                 # if the endtime is less than the starttime, add 1 day.
355                 if end < begin:
356                         end += 86400
357                 return begin, end
358
359         def selectChannelSelector(self, *args):
360                 self.session.openWithCallback(
361                                 self.finishedChannelSelectionCorrection,
362                                 ChannelSelection.SimpleChannelSelection,
363                                 _("Select channel to record from")
364                         )
365
366         def finishedChannelSelectionCorrection(self, *args):
367                 if args:
368                         self.finishedChannelSelection(*args)
369                         self.keyGo()
370
371         def keyGo(self, result = None):
372                 if not self.timerentry_service_ref.isRecordable():
373                         self.session.openWithCallback(self.selectChannelSelector, MessageBox, _("You didn't select a channel to record from."), MessageBox.TYPE_ERROR)
374                         return
375                 self.timer.name = self.timerentry_name.value
376                 self.timer.description = self.timerentry_description.value
377                 self.timer.justplay = self.timerentry_justplay.value == "zap"
378                 self.timer.always_zap = self.timerentry_justplay.value == "zap+record"
379                 self.timer.zap_wakeup = self.timerentry_zapwakeup.value
380                 self.timer.rename_repeat = self.timerentry_renamerepeat.value
381                 self.timer.conflict_detection = self.timerentry_conflictdetection.value
382                 if self.timerentry_justplay.value == "zap":
383                         if not self.timerentry_showendtime.value:
384                                 self.timerentry_endtime.value = self.timerentry_starttime.value
385                                 self.timerentry_afterevent.value = "nothing"
386                 self.timer.resetRepeated()
387                 self.timer.afterEvent = {
388                         "nothing": AFTEREVENT.NONE,
389                         "deepstandby": AFTEREVENT.DEEPSTANDBY,
390                         "standby": AFTEREVENT.STANDBY,
391                         "auto": AFTEREVENT.AUTO
392                         }[self.timerentry_afterevent.value]
393                 self.timer.descramble = {
394                         "normal": True,
395                         "descrambled+ecm": True,
396                         "scrambled+ecm": False,
397                         }[self.timerentry_recordingtype.value]
398                 self.timer.record_ecm = {
399                         "normal": False,
400                         "descrambled+ecm": True,
401                         "scrambled+ecm": True,
402                         }[self.timerentry_recordingtype.value]
403                 self.timer.service_ref = self.timerentry_service_ref
404                 self.timer.tags = self.timerentry_tags
405
406                 if self.timer.dirname or self.timerentry_dirname.value != defaultMoviePath():
407                         self.timer.dirname = self.timerentry_dirname.value
408                         config.movielist.last_timer_videodir.value = self.timer.dirname
409                         config.movielist.last_timer_videodir.save()
410
411                 if self.timerentry_type.value == "once":
412                         self.timer.begin, self.timer.end = self.getBeginEnd()
413                 if self.timerentry_type.value == "repeated":
414                         if self.timerentry_repeated.value == "daily":
415                                 for x in (0, 1, 2, 3, 4, 5, 6):
416                                         self.timer.setRepeated(x)
417
418                         if self.timerentry_repeated.value == "weekly":
419                                 self.timer.setRepeated(self.timerentry_weekday.index)
420
421                         if self.timerentry_repeated.value == "weekdays":
422                                 for x in (0, 1, 2, 3, 4):
423                                         self.timer.setRepeated(x)
424
425                         if self.timerentry_repeated.value == "user":
426                                 for x in (0, 1, 2, 3, 4, 5, 6):
427                                         if self.timerentry_day[x].value:
428                                                 self.timer.setRepeated(x)
429
430                         self.timer.repeatedbegindate = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
431                         if self.timer.repeated:
432                                 self.timer.begin = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_starttime.value)
433                                 self.timer.end = self.getTimestamp(self.timerentry_repeatedbegindate.value, self.timerentry_endtime.value)
434                         else:
435                                 self.timer.begin = self.getTimestamp(time(), self.timerentry_starttime.value)
436                                 self.timer.end = self.getTimestamp(time(), self.timerentry_endtime.value)
437
438                         # when a timer end is set before the start, add 1 day
439                         if self.timer.end < self.timer.begin:
440                                 self.timer.end += 86400
441
442                 if self.timer.eit is not None:
443                         event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
444                         if event:
445                                 n = event.getNumOfLinkageServices()
446                                 if n > 1:
447                                         tlist = []
448                                         ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
449                                         parent = self.timer.service_ref.ref
450                                         selection = 0
451                                         for x in range(n):
452                                                 i = event.getLinkageService(parent, x)
453                                                 if i.toString() == ref.toString():
454                                                         selection = x
455                                                 tlist.append((i.getName(), i))
456                                         self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice to record..."), list = tlist, selection = selection)
457                                         return
458                                 elif n > 0:
459                                         parent = self.timer.service_ref.ref
460                                         self.timer.service_ref = ServiceReference(event.getLinkageService(parent, 0))
461                 self.saveTimer()
462                 self.close((True, self.timer))
463
464         def changeTimerType(self):
465                 self.timerentry_justplay.selectNext()
466                 self.timerJustplayEntry = getConfigListEntry(_("Timer type"), self.timerentry_justplay)
467                 self["config"].invalidate(self.timerJustplayEntry)
468                 self.createSetup("config")
469
470         def changeZapWakeupType(self):
471                 if self.timerentry_justplay.value == "zap":
472                         self.timerentry_zapwakeup.selectNext()
473                         self["config"].invalidate(self.entryZapWakeup)
474
475         def incrementStart(self):
476                 self.timerentry_starttime.increment()
477                 self["config"].invalidate(self.entryStartTime)
478                 if self.timerentry_type.value == "once" and self.timerentry_starttime.value == [0, 0]:
479                         self.timerentry_date.value = self.timerentry_date.value + 86400
480                         self["config"].invalidate(self.entryDate)
481
482         def decrementStart(self):
483                 self.timerentry_starttime.decrement()
484                 self["config"].invalidate(self.entryStartTime)
485                 if self.timerentry_type.value == "once" and self.timerentry_starttime.value == [23, 59]:
486                         self.timerentry_date.value = self.timerentry_date.value - 86400
487                         self["config"].invalidate(self.entryDate)
488
489         def incrementEnd(self):
490                 if self.entryEndTime is not None:
491                         self.timerentry_endtime.increment()
492                         self["config"].invalidate(self.entryEndTime)
493
494         def decrementEnd(self):
495                 if self.entryEndTime is not None:
496                         self.timerentry_endtime.decrement()
497                         self["config"].invalidate(self.entryEndTime)
498
499         def subserviceSelected(self, service):
500                 if not service is None:
501                         self.timer.service_ref = ServiceReference(service[1])
502                 self.saveTimer()
503                 self.close((True, self.timer))
504
505         def saveTimer(self):
506                 self.session.nav.RecordTimer.saveTimer()
507
508         def keyCancel(self):
509                 self.close((False,))
510
511         def pathSelected(self, res):
512                 if res is not None:
513                         if config.movielist.videodirs.value != self.timerentry_dirname.choices:
514                                 self.timerentry_dirname.setChoices(config.movielist.videodirs.value, default=res)
515                         self.timerentry_dirname.value = res
516
517         def tagEditFinished(self, ret):
518                 if ret is not None:
519                         self.timerentry_tags = ret
520                         self.timerentry_tagsset.setChoices([not ret and "None" or " ".join(ret)])
521                         self["config"].invalidate(self.tagsSet)
522
523 class TimerLog(Screen):
524         def __init__(self, session, timer):
525                 Screen.__init__(self, session)
526                 self.timer = timer;
527                 self.log_entries = self.timer.log_entries[:]
528
529                 self.fillLogList()
530
531                 self["loglist"] = MenuList(self.list)
532                 self["logentry"] = Label()
533
534                 self["key_red"] = Button(_("Delete entry"))
535                 self["key_green"] = Button()
536                 self["key_yellow"] = Button("")
537                 self["key_blue"] = Button(_("Clear log"))
538
539                 self.onShown.append(self.updateText)
540
541                 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
542                 {
543                         "ok": self.keyClose,
544                         "cancel": self.keyClose,
545                         "up": self.up,
546                         "down": self.down,
547                         "left": self.left,
548                         "right": self.right,
549                         "red": self.deleteEntry,
550                         "blue": self.clearLog
551                 }, -1)
552                 self.setTitle(_("Timer log"))
553
554         def deleteEntry(self):
555                 cur = self["loglist"].getCurrent()
556                 if cur is None:
557                         return
558                 self.log_entries.remove(cur[1])
559                 self.fillLogList()
560                 self["loglist"].l.setList(self.list)
561                 self.updateText()
562
563         def fillLogList(self):
564                 self.list = [(str(strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x) for x in self.log_entries]
565
566         def clearLog(self):
567                 self.log_entries = []
568                 self.fillLogList()
569                 self["loglist"].l.setList(self.list)
570                 self.updateText()
571
572         def keyClose(self):
573                 if self.timer.log_entries != self.log_entries:
574                         self.timer.log_entries = self.log_entries
575                         self.close((True, self.timer))
576                 else:
577                         self.close((False,))
578
579         def up(self):
580                 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
581                 self.updateText()
582
583         def down(self):
584                 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
585                 self.updateText()
586
587         def left(self):
588                 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
589                 self.updateText()
590
591         def right(self):
592                 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
593                 self.updateText()
594
595         def updateText(self):
596                 if self.list:
597                         self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
598                 else:
599                         self["logentry"].setText("")