5 from Tools import Notifications
7 from Components.config import config, ConfigYesNo, ConfigSelection, ConfigSubsection
9 from Screens.MessageBox import MessageBox
10 import Screens.Standby
12 config.SleepTimer = ConfigSubsection()
13 config.SleepTimer.ask = ConfigYesNo(default = True)
14 config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))])
16 class SleepTimerEntry(timer.TimerEntry):
17 def __init__(self, begin):
18 timer.TimerEntry.__init__(self, int(begin), int(begin))
22 def getNextActivation(self):
26 if self.state == self.StateRunning:
27 if config.SleepTimer.action.value == "shutdown":
28 if config.SleepTimer.ask.value and not Screens.Standby.inTryQuitMainloop:
29 Notifications.AddNotificationWithCallback(self.shutdown, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
32 elif config.SleepTimer.action.value == "standby":
33 if config.SleepTimer.ask.value and not Screens.Standby.inStandby:
34 Notifications.AddNotificationWithCallback(self.standby, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
43 def shutdown(self, answer):
44 if answer is not None:
45 if answer and not Screens.Standby.inTryQuitMainloop:
46 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)
48 def standby(self, answer):
49 if answer is not None:
50 if answer and not Screens.Standby.inStandby:
51 Notifications.AddNotification(Screens.Standby.Standby)
53 class SleepTimer(timer.Timer):
55 timer.Timer.__init__(self)
58 def setSleepTime(self, sleeptime):
60 self.addTimerEntry(SleepTimerEntry(time.time() + 60 * sleeptime))
65 def getCurrentSleepTime(self):
66 llen = len(self.timer_list)
69 timer = self.timer_list[idx]
70 return int(math.ceil((timer.begin - time.time()) / 60))
71 return self.defaultTime
74 return len(self.timer_list) > 0