1 from Screens.InfoBar import InfoBar
2 from Screens.Screen import Screen
3 from Screens.MessageBox import MessageBox
4 from Components.ActionMap import ActionMap
5 from Components.ConfigList import ConfigListScreen
6 from Components.Label import Label
7 from Components.Sources.StaticText import StaticText
8 from Components.config import config, getConfigListEntry
9 from enigma import eEPGCache
12 class SleepTimerEdit(ConfigListScreen, Screen):
13 def __init__(self, session):
14 Screen.__init__(self, session)
15 self.skinName = ["SleepTimerSetup", "Setup"]
16 self.setup_title = _("SleepTimer Configuration")
18 self["key_red"] = StaticText(_("Cancel"))
19 self["key_green"] = StaticText(_("Save"))
20 self["description"] = Label("")
23 ConfigListScreen.__init__(self, self.list, session = session)
26 self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
30 "cancel": self.cancel,
34 self.onLayoutFinish.append(self.layoutFinished)
36 def layoutFinished(self):
37 self.setTitle(self.setup_title)
39 def createSetup(self):
41 self.list.append(getConfigListEntry(_("Sleeptimer"),
42 config.usage.sleep_timer,
43 _("Configure the duration in minutes and action, which could be shut down or standby, for the sleeptimer. Select this entry and click OK or green to start/stop the sleeptimer")))
44 self.list.append(getConfigListEntry(_("Inactivity Sleeptimer"),
45 config.usage.inactivity_timer,
46 _("Configure the duration in hours and action, which could be shut down or standby, when the receiver is not controlled.")))
47 if int(config.usage.inactivity_timer.value):
48 self.list.append(getConfigListEntry(_("Specify timeframe to ignore inactivity sleeptimer"),
49 config.usage.inactivity_timer_blocktime,
50 _("When enabled you can specify a timeframe were the inactivity sleeptimer is ignored. Not the detection is disabled during this timeframe but the inactivity timeout is disabled")))
51 if config.usage.inactivity_timer_blocktime.value:
52 self.list.append(getConfigListEntry(_("Start time to ignore inactivity sleeptimer"),
53 config.usage.inactivity_timer_blocktime_begin,
54 _("Specify the start time when the inactivity sleeptimer should be ignored")))
55 self.list.append(getConfigListEntry(_("End time to ignore inactivity sleeptimer"),
56 config.usage.inactivity_timer_blocktime_end,
57 _("Specify the end time until the inactivity sleeptimer should be ignored")))
58 self.list.append(getConfigListEntry(_("Shutdown when in Standby"),
59 config.usage.standby_to_shutdown_timer,
60 _("Configure the duration when the receiver should go to shut down in case the receiver is in standby mode.")))
61 if int(config.usage.standby_to_shutdown_timer.value):
62 self.list.append(getConfigListEntry(_("Specify timeframe to ignore the shutdown in standby"),
63 config.usage.standby_to_shutdown_timer_blocktime,
64 _("When enabled you can specify a timeframe were the inactivity sleeptimer is ignored. Not the detection is disabled during this timeframe but the inactivity timeout is disabled")))
65 if config.usage.inactivity_timer_blocktime.value:
66 self.list.append(getConfigListEntry(_("Start time to ignore shutdown in standby"),
67 config.usage.standby_to_shutdown_timer_blocktime_begin,
68 _("Specify the start time to ignore the shutdown timer when the receiver is in standby mode")))
69 self.list.append(getConfigListEntry(_("End time to ignore shutdown in standby"),
70 config.usage.standby_to_shutdown_timer_blocktime_end,
71 _("Specify the end time to ignore the shutdown timer when the receiver is in standby mode")))
72 self["config"].list = self.list
73 self["config"].l.setList(self.list)
76 config.usage.sleep_timer.save()
77 config.usage.inactivity_timer.save()
78 config.usage.inactivity_timer_blocktime.save()
79 config.usage.inactivity_timer_blocktime_begin.save()
80 config.usage.inactivity_timer_blocktime_end.save()
81 config.usage.standby_to_shutdown_timer.save()
82 config.usage.standby_to_shutdown_timer_blocktime.save()
83 config.usage.standby_to_shutdown_timer_blocktime_begin.save()
84 config.usage.standby_to_shutdown_timer_blocktime_end.save()
86 if self.getCurrentEntry() == _("Sleeptimer"):
87 sleepTimer = config.usage.sleep_timer.value
88 if sleepTimer == "event_shutdown":
89 sleepTimer = -self.currentEventTime()
90 elif sleepTimer == "event_standby":
91 sleepTimer = self.currentEventTime()
93 sleepTimer = int(sleepTimer)
94 InfoBar.instance.setSleepTimer(sleepTimer)
98 def cancel(self, answer = None):
100 if self["config"].isChanged():
101 self.session.openWithCallback(self.cancel, MessageBox, _("Really close without saving settings?"))
105 for x in self["config"].list:
110 ConfigListScreen.keyLeft(self)
114 ConfigListScreen.keyRight(self)
117 def currentEventTime(self):
119 ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
123 service = self.session.nav.getCurrentService()
124 seek = service and service.seek()
126 length = seek.getLength()
127 position = seek.getPlayPosition()
128 if length and position:
129 remaining = length[1] - position[1]
131 remaining = remaining / 90000
133 epg = eEPGCache.getInstance()
134 event = epg.lookupEventTime(ref, -1, 0)
137 start = event.getBeginTime()
138 duration = event.getDuration()
139 end = start + duration
140 remaining = end - now
141 return remaining + config.recording.margin_after.value * 60