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 class SleepTimerEntry(timer.TimerEntry):
13 def __init__(self, begin):
14 timer.TimerEntry.__init__(self, int(begin), int(begin))
18 def getNextActivation(self):
22 if self.state == self.StateRunning:
23 if config.SleepTimer.action.value == "shutdown":
24 if config.SleepTimer.ask.value and not Screens.Standby.inTryQuitMainloop:
25 Notifications.AddNotificationWithCallback(self.shutdown, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
28 elif config.SleepTimer.action.value == "standby":
29 if config.SleepTimer.ask.value and not Screens.Standby.inStandby:
30 Notifications.AddNotificationWithCallback(self.standby, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20)
39 def shutdown(self, answer):
40 if answer is not None:
41 if answer and not Screens.Standby.inTryQuitMainloop:
42 Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)
44 def standby(self, answer):
45 if answer is not None:
46 if answer and not Screens.Standby.inStandby:
47 Notifications.AddNotification(Screens.Standby.Standby)
49 class SleepTimer(timer.Timer):
51 config.SleepTimer = ConfigSubsection()
52 config.SleepTimer.ask = ConfigYesNo(default = True)
53 config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))])
54 timer.Timer.__init__(self)
57 def setSleepTime(self, sleeptime):
59 self.addTimerEntry(SleepTimerEntry(time.time() + 60 * sleeptime))
64 def getCurrentSleepTime(self):
65 llen = len(self.timer_list)
68 timer = self.timer_list[idx]
69 return int(math.ceil((timer.begin - time.time()) / 60))
70 return self.defaultTime
73 return len(self.timer_list) > 0