Simplify the Sleeptimer.
authorLittlesat <littlesat99@yahoo.com>
Thu, 28 Feb 2013 20:00:02 +0000 (21:00 +0100)
committerLittlesat <littlesat99@yahoo.com>
Thu, 28 Feb 2013 20:00:02 +0000 (21:00 +0100)
Makefile.am
Navigation.py
SleepTimer.py [deleted file]
lib/python/Components/UsageConfig.py
lib/python/Screens/InfoBar.py
lib/python/Screens/InfoBarGenerics.py
lib/python/Screens/SleepTimerEdit.py

index cae7114..c01394c 100755 (executable)
@@ -4,7 +4,7 @@ ACLOCAL_AMFLAGS = -I m4
 
 installdir = $(pkglibdir)/python
 install_PYTHON = \
-       Navigation.py NavigationInstance.py RecordTimer.py SleepTimer.py ServiceReference.py \
+       Navigation.py NavigationInstance.py RecordTimer.py ServiceReference.py \
        keyids.py keymapparser.py mytest.py skin.py timer.py GlobalActions.py \
        e2reactor.py
 
index 7004b7d..407ca27 100644 (file)
@@ -4,7 +4,6 @@ from Tools.BoundFunction import boundFunction
 from Tools.StbHardware import setFPWakeuptime, getFPWakeuptime, getFPWasTimerWakeup
 from time import time
 import RecordTimer
-import SleepTimer
 import Screens.Standby
 import NavigationInstance
 import ServiceReference
@@ -39,7 +38,6 @@ class Navigation:
                                self.recordshutdowntimer = eTimer()
                                self.recordshutdowntimer.callback.append(self.checkShutdownAfterRecording)
                                self.recordshutdowntimer.start(30000, True)
-               self.SleepTimer = SleepTimer.SleepTimer()
 
        def checkShutdownAfterRecording(self):
                if len(self.getRecordings()) or abs(self.RecordTimer.getNextRecordingTime() - time()) <= 360:
diff --git a/SleepTimer.py b/SleepTimer.py
deleted file mode 100644 (file)
index 14b7365..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-import timer
-import time
-import math
-
-from Tools import Notifications
-
-from Components.config import config, ConfigYesNo, ConfigSelection, ConfigSubsection
-
-from Screens.MessageBox import MessageBox
-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):
-               timer.TimerEntry.__init__(self, int(begin), int(begin))
-               
-               self.prepare_time = 0
-               
-       def getNextActivation(self):
-               return self.begin
-               
-       def activate(self):
-               if self.state == self.StateRunning:
-                       if config.SleepTimer.action.value == "shutdown":
-                               if config.SleepTimer.ask.value and not Screens.Standby.inTryQuitMainloop:
-                                       Notifications.AddNotificationWithCallback(self.shutdown, MessageBox, _("A sleep timer wants to shut down\nyour receiver. Shutdown now?"), timeout = 20)
-                               else:
-                                       self.shutdown(True)
-                       elif config.SleepTimer.action.value == "standby":
-                               if config.SleepTimer.ask.value and not Screens.Standby.inStandby:
-                                       Notifications.AddNotificationWithCallback(self.standby, MessageBox, _("A sleep timer wants to set your\nreceiver to standby. Do that now?"), timeout = 20)
-                               else:
-                                       self.standby(True)
-
-               return True
-               
-       def shouldSkip(self):
-               return False
-       
-       def shutdown(self, answer):
-               if answer is not None:
-                       if answer and not Screens.Standby.inTryQuitMainloop:
-                               Notifications.AddNotification(Screens.Standby.TryQuitMainloop, 1)
-
-       def standby(self, answer):
-               if answer is not None:
-                       if answer and not Screens.Standby.inStandby:
-                               Notifications.AddNotification(Screens.Standby.Standby)
-
-class SleepTimer(timer.Timer):
-       def __init__(self):
-               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):
-               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
index 6709b75..4e20077 100644 (file)
@@ -88,15 +88,32 @@ def InitUsageConfig():
                ("shutdown", _("Immediate shutdown")),
                ("standby", _("Standby")) ] )
 
-       choicelist = [("0", "Do nothing")]
-       for i in range(-3600, -21601, -3600):
-               h = -i / 3600
-               choicelist.append(("%d" % i, "Shutdown in " + ngettext("%d hour", "%d hours", h) % h))
-       for i in range(3600, 21601, 3600):
-               h = i / 3600
-               choicelist.append(("%d" % i, "Standby in " + ngettext("%d hour", "%d hours", h) % h))
+       choicelist = []
+       for i in range(-21600, 21601, 3600):
+               h = abs(i / 3600)
+               h = ngettext("%d hour", "%d hours", h) % h
+               if i < 0:
+                       choicelist.append(("%d" % i, _("Shutdown in ") + h))
+               elif i > 0:
+                       choicelist.append(("%d" % i, _("Standby in ") + h))
+               else:
+                       choicelist.append(("0", "Do nothing"))
        config.usage.inactivity_timer = ConfigSelection(default = "0", choices = choicelist)
 
+       choicelist = []
+       for i in range(-7200, 7201, 900):
+               m = abs(i / 60)
+               m = ngettext("%d minute", "%d minutes", m) % m
+               if i < 0:
+                       choicelist.append(("%d" % i, _("Shutdown in ") + m))
+               elif i > 0:
+                       choicelist.append(("%d" % i, _("Standby in ") + m))
+               else:
+                       choicelist.append(("event_shutdown", _("Shutdown after current event")))
+                       choicelist.append(("0", "Disabled"))
+                       choicelist.append(("event_standby", _("Standby after current event")))
+       config.usage.sleep_timer = ConfigSelection(default = "0", choices = choicelist)
+
        config.usage.check_timeshift = ConfigYesNo(default = True)
 
        config.usage.alternatives_priority = ConfigSelection(default = "0", choices = [
index c405f26..2d808a5 100644 (file)
@@ -18,7 +18,7 @@ from Screens.InfoBarGenerics import InfoBarShowHide, \
        InfoBarSubserviceSelection, InfoBarShowMovies, InfoBarTimeshift,  \
        InfoBarServiceNotifications, InfoBarPVRState, InfoBarCueSheetSupport, InfoBarSimpleEventView, \
        InfoBarSummarySupport, InfoBarMoviePlayerSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions, \
-       InfoBarSubtitleSupport, InfoBarPiP, InfoBarPlugins, InfoBarServiceErrorPopupSupport, InfoBarJobman, InfoBarInactivity, \
+       InfoBarSubtitleSupport, InfoBarPiP, InfoBarPlugins, InfoBarServiceErrorPopupSupport, InfoBarJobman, InfoBarPowersaver, \
        setResumePoint, delResumePoint
 
 profile("LOAD:InitBar_Components")
@@ -35,7 +35,7 @@ class InfoBar(InfoBarBase, InfoBarShowHide,
        HelpableScreen, InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarUnhandledKey,
        InfoBarSubserviceSelection, InfoBarTimeshift, InfoBarSeek,
        InfoBarSummarySupport, InfoBarTimeshiftState, InfoBarTeletextPlugin, InfoBarExtensions,
-       InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarServiceErrorPopupSupport, InfoBarJobman, InfoBarInactivity,
+       InfoBarPiP, InfoBarPlugins, InfoBarSubtitleSupport, InfoBarServiceErrorPopupSupport, InfoBarJobman, InfoBarPowersaver,
        Screen):
        
        ALLOW_SUSPEND = True
@@ -58,7 +58,7 @@ class InfoBar(InfoBarBase, InfoBarShowHide,
                                InfoBarInstantRecord, InfoBarAudioSelection, InfoBarRedButton, InfoBarTimerButton, InfoBarUnhandledKey, \
                                InfoBarAdditionalInfo, InfoBarNotifications, InfoBarDish, InfoBarSubserviceSelection, \
                                InfoBarTimeshift, InfoBarSeek, InfoBarSummarySupport, InfoBarTimeshiftState, \
-                               InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarJobman, InfoBarInactivity, \
+                               InfoBarTeletextPlugin, InfoBarExtensions, InfoBarPiP, InfoBarSubtitleSupport, InfoBarJobman, InfoBarPowersaver, \
                                InfoBarPlugins, InfoBarServiceErrorPopupSupport:
                        x.__init__(self)
 
index 448899d..fdf25ed 100644 (file)
@@ -2519,11 +2519,14 @@ class InfoBarServiceErrorPopupSupport:
                        else:
                                Notifications.RemovePopup(id = "ZapError")
 
-class InfoBarInactivity:
+class InfoBarPowersaver:
        def __init__(self):
                self.inactivityTimer = eTimer()
-               self.inactivityTimer.callback.append(self.inactiveTimeout)
+               self.inactivityTimer.callback.append(self.inactivityTimeout)
                self.restartInactiveTimer()
+               self.sleepTimer = eTimer()
+               self.sleepTimer.callback.append(self.sleepTimerTimeout)
+               self.setSleepTimer(0)
                eActionMap.getInstance().bindAction('', -maxint - 1, self.keypress)
 
        def keypress(self, key, flag):
@@ -2537,24 +2540,60 @@ class InfoBarInactivity:
                else:
                        self.inactivityTimer.stop()
 
-       def inactiveTimeout(self, answer = None):
-               self.inactivityTimer.stop()
-               if answer == None and not Screens.Standby.inStandby:
+       def inactivityTimeout(self, answer = None):
+               if Screens.Standby.inStandby:
+                       answer = True
+               if answer is None:
                        if int(config.usage.inactivity_timer.value) < 0:
-                               message = _("Your receiver will shutdown due to inactivity\nDo you want to abort this?")
+                               message = _("Your receiver will shutdown due to inactivity.")
                        else:
-                               message = _("Your receiver will got to standby due to inactivity\nDo you want to abort this?")
-                       self.session.openWithCallback(self.inactiveTimeout, MessageBox, message, MessageBox.TYPE_YESNO, timeout=60, default=False, simple = True)
+                               message = _("Your receiver will got to standby due to inactivity.")
+                       message += "\n" + _("Do you want this?")
+                       self.session.openWithCallback(self.inactivityTimeout, MessageBox, message, timeout=60, simple = True)   
                elif answer:
-                       print "[InfoBarInactivity] abort"
-                       self.restartInactiveTimer()
-               elif int(config.usage.inactivity_timer.value) < 0:
+                       self.goShutdownOrStandby(int(config.usage.inactivity_timer.value))
+               else:
+                       print "[InfoBarPowersaver] abort"
+
+       def setSleepTimer(self, time):
+               print "[InfoBarPowersaver] set sleeptimer", time
+               if time:
+                       self.sleepTimer.startLongTimer(abs(time))
+               else:
+                       self.sleepTimer.stop()
+               self.sleepTimerSetting = time
+
+       def sleepTimerTimeout(self, answer = None):
+               if Screens.Standby.inStandby:
+                       answer = True
+               if answer is None:
+                       list = [ (_("Yes"), True), (_("Extend sleeptimer 15 minutes"), "extend"), (_("No"), False) ]
+                       if self.sleepTimerSetting < 0:
+                               message = _("Your receiver will shutdown due to the sleeptimer.")
+                       elif self.sleepTimerSetting > 0:
+                               message = _("Your receiver will got to stand by due to the sleeptimer.")
+                       message += "\n" + _("Do you want this?")
+                       self.session.openWithCallback(self.sleepTimerTimeout, MessageBox, message, timeout=60, simple = True, list = list)      
+               elif answer == "extend":
+                       print "[InfoBarPowersaver] extend sleeptimer"
+                       if self.sleepTimerSetting < 0:
+                               self.setSleepTimer(-900)
+                       else:
+                               self.setSleepTimer(900)
+               elif answer:
+                       self.goShutdownOrStandby(self.sleepTimerSetting)
+               else:
+                       print "[InfoBarPowersaver] abort"
+                       self.setSleepTimer(0)
+
+       def goShutdownOrStandby(self, value):
+               if value < 0:
                        if Screens.Standby.inStandby:
-                               print "[InfoBarInactivity] already in standby now shut down"
+                               print "[InfoBarPowersaver] already in standby now shut down"
                                RecordTimerEntry.TryQuitMainloop(True)
                        elif not Screens.Standby.inTryQuitMainloop:
-                               print "[InfoBarInactivity] goto shutdown"
+                               print "[InfoBarPowersaver] goto shutdown"
                                self.session.open(Screens.Standby.TryQuitMainloop, 1)
                elif not Screens.Standby.inStandby:
-                       print "[InfoBarInactivity] goto standby"
+                       print "[InfoBarPowersaver] goto standby"
                        self.session.open(Screens.Standby.Standby)
\ No newline at end of file
index dfbbb7b..4bfaf33 100644 (file)
+from Screens.InfoBar import InfoBar
 from Screens.Screen import Screen
 from Screens.MessageBox import MessageBox
-from Components.ActionMap import NumberActionMap
-from Components.Input import Input
+from Components.ActionMap import ActionMap
+from Components.ConfigList import ConfigListScreen
 from Components.Label import Label
-from Components.Pixmap import Pixmap
-from Components.config import config, ConfigInteger
-from Components.SystemInfo import SystemInfo
+from Components.Sources.StaticText import StaticText
+from Components.config import config, getConfigListEntry
 from Tools.Notifications import AddPopup
 from enigma import eEPGCache
-from SleepTimer import SleepTimer
 from time import time
 
-config.SleepTimer.defaulttime = ConfigInteger(default = 30)
-
-class SleepTimerEdit(Screen):
+class SleepTimerEdit(ConfigListScreen, Screen):
        def __init__(self, session):
                Screen.__init__(self, session)
+               self.skinName = ["SleepTimerSetup", "Setup" ]
+               self.setup_title = _("SleepTimer Configuration")
+               self.onChangedEntry = [ ]
+
+               self["key_red"] = StaticText(_("Cancel"))
+               self["key_green"] = StaticText(_("Save"))
+               self["description"] = Label("")
+
+               self.list = []
+               self.list.append(getConfigListEntry(_("Sleeptimer"),
+                       config.usage.sleep_timer,
+                       _("Configure the duration in minutes and action (shut down or standby) for the sleeptimer.")))
+               self.list.append(getConfigListEntry(_("Action when receiver is not controlled"),
+                       config.usage.inactivity_timer,
+                       _("Configure the duration in hours and action (shut down or standby) when the receiver is not controlled.")))
+
+               ConfigListScreen.__init__(self, self.list, session = session)
                
-               self["red"] = Pixmap()
-               self["green"] = Pixmap()
-               self["yellow"] = Pixmap()
-               self["blue"] = Pixmap()
-               self["key_red"] = self["red_text"] = Label()
-               self["key_green"] = self["green_text"] = Label()
-               self["key_yellow"] = self["yellow_text"] = Label()
-               self["key_blue"] = self["blue_text"] = Label()
-               self["current_status"] = Label()
-               self.is_active = self.session.nav.SleepTimer.isActive()
-               if self.is_active:
-                       self["current_status"].setText(_("Timer status:") + " " + _("enabled"))
-               else:
-                       self["current_status"].setText(_("Timer status:") + " " + _("disabled"))
-               
-               if self.is_active:
-                       self.time = self.session.nav.SleepTimer.getCurrentSleepTime()
-               else:
-                       self.time = config.SleepTimer.defaulttime.value
-               self["input"] = Input(text = str(self.time), maxSize = False, type = Input.NUMBER)
-               
-               self.status = True
-               self.updateColors()
-               
-               self["pretext"] = Label(_("Shutdown receiver after"))
-               self["aftertext"] = Label(_("minutes"))
-               
-               self["actions"] = NumberActionMap(["SleepTimerEditorActions", "TextEntryActions", "KeyboardInputActions"], 
+               self["setupActions"] = ActionMap(["SetupActions", "ColorActions"],
                {
-                       "exit": self.cancel,
-                       "select": self.select,
-                       "1": self.keyNumberGlobal,
-                       "2": self.keyNumberGlobal,
-                       "3": self.keyNumberGlobal,
-                       "4": self.keyNumberGlobal,
-                       "5": self.keyNumberGlobal,
-                       "6": self.keyNumberGlobal,
-                       "7": self.keyNumberGlobal,
-                       "8": self.keyNumberGlobal,
-                       "9": self.keyNumberGlobal,
-                       "0": self.keyNumberGlobal,
-                       "selectLeft": self.selectLeft,
-                       "selectRight": self.selectRight,
-                       "left": self.selectLeft,
-                       "right": self.selectRight,
-                       "home": self.selectHome,
-                       "end": self.selectEnd,
-                       "deleteForward": self.deleteForward,
-                       "deleteBackward": self.deleteBackward,
-                       "disableTimer": self.disableTimer,
-                       "toggleAction": self.toggleAction,
-                       "toggleAsk": self.toggleAsk,
-                       "useServiceTime": self.useServiceTime
-               }, -1)
+                   "green": self.ok,
+                   "red": self.cancel,
+                   "cancel": self.cancel,
+                   "ok": self.ok,
+               }, -2)
+
+       def layoutFinished(self):
+               self.setTitle(self.setup_title)
 
-       def updateColors(self):
-               if self.status:
-                       self["red_text"].setText(_("Action:") + " " + _("Enable timer"))
+       def ok(self):
+               sleepTimer = config.usage.sleep_timer.value
+               message = None
+               if sleepTimer == "event_shutdown":
+                       sleepTimer = -self.currentEventTime()
+               elif sleepTimer == "event_standby":
+                       sleepTimer = self.currentEventTime()
                else:
-                       self["red_text"].setText(_("Action:") + " " + _("Disable timer"))
-               
-               if config.SleepTimer.action.value == "shutdown":
-                       if SystemInfo["DeepstandbySupport"]:
-                               shutdownString = _("Deep standby")
+                       sleepTimer = int(sleepTimer)
+               if sleepTimer:
+                       if sleepTimer < 0:
+                               message = _("And will shutdown your receiver over ")
                        else:
-                               shutdownString = _("Shutdown")
-                       self["green_text"].setText(_("Sleep timer action:") + " " + shutdownString)
-               elif config.SleepTimer.action.value == "standby":
-                       self["green_text"].setText(_("Sleep timer action:") + " " + _("Standby"))
-               
-               if config.SleepTimer.ask.value:
-                       self["yellow_text"].setText(_("Confirm shutdown:") + " " + _("yes"))
+                               message = _("And will put your receiver in standby over ")
+                       m = abs(sleepTimer / 60)
+                       message = _("The sleep timer has been activated.") + "\n" + message + ngettext("%d minute", "%d minutes", m) % m
+                       InfoBar.instance.setSleepTimer(sleepTimer)
                else:
-                       self["yellow_text"].setText(_("Confirm shutdown:") + " " + _("no"))
-               self["blue_text"].setText(_("Use time of currently running service"))
+                       message = _("The sleep timer has been disabled.")
+                       InfoBar.instance.setSleepTimer(0)
+               AddPopup(message, type = MessageBox.TYPE_INFO, timeout = 5)
+               config.usage.sleep_timer.save()
+               config.usage.inactivity_timer.save()
+               self.close(True)
 
        def cancel(self):
-               config.SleepTimer.ask.cancel()
-               config.SleepTimer.action.cancel()
                self.close()
 
-       def select(self):
-               if self.status:
-                       time = int(self["input"].getText())
-                       config.SleepTimer.defaulttime.setValue(time)
-                       config.SleepTimer.defaulttime.save()
-                       config.SleepTimer.action.save()
-                       config.SleepTimer.ask.save()
-                       self.session.nav.SleepTimer.setSleepTime(time)
-                       AddPopup(_("The sleep timer has been activated."), type = MessageBox.TYPE_INFO, timeout = 3)
-                       self.close(True)
-               else:
-                       self.session.nav.SleepTimer.clear()
-                       AddPopup(_("The sleep timer has been disabled."), type = MessageBox.TYPE_INFO, timeout = 3)
-                       self.close(True)
-
-       def keyNumberGlobal(self, number):
-               self["input"].number(number)
-
-       def selectLeft(self):
-               self["input"].left()
+       def getCurrentEntry(self):
+               return self["config"].getCurrent()[0]
 
-       def selectRight(self):
-               self["input"].right()
+       def getCurrentValue(self):
+               return str(self["config"].getCurrent()[1].getText())
 
-       def selectHome(self):
-               self["input"].home()
+       def getCurrentDescription(self):
+               return self["config"].getCurrent() and len(self["config"].getCurrent()) > 2 and self["config"].getCurrent()[2] or ""
 
-       def selectEnd(self):
-               self["input"].end()
+       def createSummary(self):
+               from Screens.Setup import SetupSummary
+               return SetupSummary
 
-       def deleteForward(self):
-               self["input"].delete()
-
-       def deleteBackward(self):
-               self["input"].deleteBackward()
-
-       def disableTimer(self):
-               self.status = not self.status
-               self.updateColors()
-
-       def toggleAction(self):
-               if config.SleepTimer.action.value == "shutdown":
-                       config.SleepTimer.action.value = "standby"
-               elif config.SleepTimer.action.value == "standby":
-                       config.SleepTimer.action.value = "shutdown"
-               self.updateColors()
-
-       def toggleAsk(self):
-               config.SleepTimer.ask.value = not config.SleepTimer.ask.value
-               self.updateColors()
-               
-       def useServiceTime(self):
-               remaining = None
+       def currentEventTime(self):
+               remaining = 0
                ref = self.session.nav.getCurrentlyPlayingServiceOrGroup()
                if ref:
                        path = ref.getPath()
@@ -173,6 +107,4 @@ class SleepTimerEdit(Screen):
                                        duration = event.getDuration()
                                        end = start + duration
                                        remaining = end - now
-               if remaining:
-                       config.SleepTimer.defaulttime.value = (remaining / 60) + 2
-                       self["input"].setText(str((remaining / 60) + 2))
+               return remaining + config.recording.margin_after.value * 60