X-Git-Url: https://git.cweiske.de/enigma2.git/blobdiff_plain/a304ed63ef86c02d1c74b342b619edff642a164b..2c83d31ceec4b7014783a8c207b66b8f5ae0c318:/SleepTimer.py diff --git a/SleepTimer.py b/SleepTimer.py index ea18ceed..221e8f0b 100644 --- a/SleepTimer.py +++ b/SleepTimer.py @@ -2,14 +2,16 @@ import timer import time import math -from enigma import quitMainloop - from Tools import Notifications from Components.config import config, ConfigYesNo, ConfigSelection, ConfigSubsection from Screens.MessageBox import MessageBox -from Screens.Standby import Standby +import Screens.Standby + +config.SleepTimer = ConfigSubsection() +config.SleepTimer.ask = ConfigYesNo(default = True) +config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))]) class SleepTimerEntry(timer.TimerEntry): def __init__(self, begin): @@ -23,13 +25,13 @@ class SleepTimerEntry(timer.TimerEntry): def activate(self): if self.state == self.StateRunning: if config.SleepTimer.action.value == "shutdown": - if config.SleepTimer.ask.value: - Notifications.AddNotificationWithCallback(self.shutdown, MessageBox, _("A sleep timer want's to shut down") + "\n" + _("your Dreambox. Shutdown now?"), timeout = 20) + if config.SleepTimer.ask.value and not Screens.Standby.inTryQuitMainloop: + Notifications.AddNotificationWithCallback(self.shutdown, MessageBox, _("A sleep timer wants to shut down\nyour Dreambox. Shutdown now?"), timeout = 20) else: self.shutdown(True) elif config.SleepTimer.action.value == "standby": - if config.SleepTimer.ask.value: - Notifications.AddNotificationWithCallback(self.standby, MessageBox, _("A sleep timer want's to set your") + "\n" + _("Dreambox to standby. Do that now?"), timeout = 20) + if config.SleepTimer.ask.value and not Screens.Standby.inStandby: + Notifications.AddNotificationWithCallback(self.standby, MessageBox, _("A sleep timer wants to set your\nDreambox to standby. Do that now?"), timeout = 20) else: self.standby(True) @@ -40,36 +42,33 @@ class SleepTimerEntry(timer.TimerEntry): def shutdown(self, answer): if answer is not None: - if answer: - quitMainloop(1) + if answer and not Screens.Standby.inTryQuitMainloop: + Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1) def standby(self, answer): if answer is not None: - if answer: - Notifications.AddNotification(Standby, self) - + if answer and not Screens.Standby.inStandby: + Notifications.AddNotification(Screens.Standby.Standby) + class SleepTimer(timer.Timer): def __init__(self): - config.SleepTimer = ConfigSubsection() - config.SleepTimer.ask = ConfigYesNo(default = True) - config.SleepTimer.action = ConfigSelection(default = "shutdown", choices = [("shutdown", _("shutdown")), ("standby", _("standby"))]) - timer.Timer.__init__(self) self.defaultTime = 30 - + def setSleepTime(self, sleeptime): self.clear() self.addTimerEntry(SleepTimerEntry(time.time() + 60 * sleeptime)) def clear(self): self.timer_list = [] - + def getCurrentSleepTime(self): - if (self.getNextRecordingTime() == -1): - return self.defaultTime - return int(math.ceil((self.getNextRecordingTime() - time.time()) / 60)) + llen = len(self.timer_list) + idx = 0 + while idx < llen: + timer = self.timer_list[idx] + return int(math.ceil((timer.begin - time.time()) / 60)) + return self.defaultTime def isActive(self): return len(self.timer_list) > 0 - - \ No newline at end of file