SleepTimerEdit: indicate if sleeptimer is active or not
authorlittlesat <littlesat99@yahoo.com>
Sat, 26 Jul 2014 16:54:45 +0000 (18:54 +0200)
committerlittlesat <littlesat99@yahoo.com>
Sat, 26 Jul 2014 16:56:27 +0000 (18:56 +0200)
And give an indication about the remaining time
In addition fix a bug when the sleeptimer config was changed

Thanks Dima73 for the suggestions

lib/python/Screens/InfoBarGenerics.py
lib/python/Screens/SleepTimerEdit.py

index ea6ff53..bd4d191 100644 (file)
@@ -3079,6 +3079,7 @@ class InfoBarPowersaver:
                self.inactivityTimer.callback.append(self.inactivityTimeout)
                self.restartInactiveTimer()
                self.sleepTimer = eTimer()
+               self.sleepStartTime = 0
                self.sleepTimer.callback.append(self.sleepTimerTimeout)
                eActionMap.getInstance().bindAction('', -maxint - 1, self.keypress)
 
@@ -3119,13 +3120,18 @@ class InfoBarPowersaver:
                else:
                        print "[InfoBarPowersaver] abort"
 
-       def setSleepTimer(self, time):
-               print "[InfoBarPowersaver] set sleeptimer", time
-               if time:
-                       message = _("And will put your receiver in standby over ")
-                       m = abs(time / 60)
-                       message = _("The sleep timer has been activated.") + "\n" + message + ngettext("%d minute", "%d minutes", m) % m
-                       self.sleepTimer.startLongTimer(time)
+       def sleepTimerState(self):
+               if self.sleepTimer.isActive():
+                       return (self.sleepStartTime - time()) / 60
+               return 0
+
+       def setSleepTimer(self, sleepTime):
+               print "[InfoBarPowersaver] set sleeptimer", sleepTime
+               if sleepTime:
+                       m = abs(sleepTime / 60)
+                       message = _("The sleep timer has been activated.") + "\n" + _("And will put your receiver in standby over ") + ngettext("%d minute", "%d minutes", m) % m
+                       self.sleepTimer.startLongTimer(sleepTime)
+                       self.sleepStartTime = time() + sleepTime
                else:
                        message = _("The sleep timer has been disabled.")
                        self.sleepTimer.stop()
index 0fc3995..2ae42b0 100644 (file)
@@ -38,7 +38,11 @@ class SleepTimerEdit(ConfigListScreen, Screen):
 
        def createSetup(self):
                self.list = []
-               self.list.append(getConfigListEntry(_("Sleeptimer"),
+               if InfoBar.instance and InfoBar.instance.sleepTimer.isActive():
+                       statusSleeptimerText = _("(activated +%d min)") % InfoBar.instance.sleepTimerState()
+               else:
+                       statusSleeptimerText = _("(not activated)")
+               self.list.append(getConfigListEntry(_("Sleeptimer") + " " + statusSleeptimerText,
                        config.usage.sleep_timer,
                        _("Configure the duration in minutes for the sleeptimer. Select this entry and click OK or green to start/stop the sleeptimer")))
                self.list.append(getConfigListEntry(_("Inactivity Sleeptimer"),
@@ -76,8 +80,7 @@ class SleepTimerEdit(ConfigListScreen, Screen):
                if self["config"].isChanged():
                        for x in self["config"].list:
                                x[1].save()
-                       self.close()
-               if self.getCurrentEntry() == _("Sleeptimer"):
+               if self.getCurrentEntry().startswith(_("Sleeptimer")):
                        sleepTimer = config.usage.sleep_timer.value
                        if sleepTimer == "event_standby":
                                sleepTimer = self.currentEventTime()