5 from Tools import Notifications
7 from Components.config import config, ConfigYesNo, ConfigSelection, ConfigSubsection
9 from Screens.MessageBox import MessageBox
10 from Screens.Standby import Standby, TryQuitMainloop, inStandby, inTryQuitMainloop
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 global inTryQuitMainloop
25 if config.SleepTimer.ask.value and not inTryQuitMainloop:
26 Notifications.AddNotificationWithCallback(self.shutdown, MessageBox, _("A sleep timer want's to shut down\nyour Dreambox. Shutdown now?"), timeout = 20)
29 elif config.SleepTimer.action.value == "standby":
31 if config.SleepTimer.ask.value and not inStandby:
32 Notifications.AddNotificationWithCallback(self.standby, MessageBox, _("A sleep timer want's to set your\nDreambox to standby. Do that now?"), timeout = 20)
41 def shutdown(self, answer):
42 global inTryQuitMainloop
43 if answer is not None:
44 if answer and not inTryQuitMainloop:
45 Notifications.AddNotification(TryQuitMainloop, 1)
47 def standby(self, answer):
48 if answer is not None:
50 if answer and not inStandby:
51 Notifications.AddNotification(Standby)
53 class SleepTimer(timer.Timer):
55 config.SleepTimer = ConfigSubsection()
56 config.SleepTimer.ask = ConfigYesNo(default = True)
57 config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))])
59 timer.Timer.__init__(self)
62 def setSleepTime(self, sleeptime):
64 self.addTimerEntry(SleepTimerEntry(time.time() + 60 * sleeptime))
69 def getCurrentSleepTime(self):
70 if (self.getNextRecordingTime() == -1):
71 return self.defaultTime
72 return int(math.ceil((self.getNextRecordingTime() - time.time()) / 60))
75 return len(self.timer_list) > 0