adding a sleep timer
[openblackhole/openblackhole-enigma2.git] / lib / python / Screens / SleepTimerEdit.py
1 from Screens.Screen import Screen
2 from Screens.MessageBox import MessageBox
3 from Components.ActionMap import NumberActionMap
4 from Components.Input import Input
5 from Components.Label import Label
6 from Components.Pixmap import Pixmap
7 from Components.config import config
8 from SleepTimer import SleepTimerEntry
9 import time
10
11 class SleepTimerEdit(Screen):
12         def __init__(self, session):
13                 Screen.__init__(self, session)
14                 
15                 self["red"] = Pixmap()
16                 self["green"] = Pixmap()
17                 self["yellow"] = Pixmap()
18                 self["blue"] = Pixmap()
19                 self["red_text"] = Label()
20                 self["green_text"] = Label()
21                 self["yellow_text"] = Label()
22                 self["blue_text"] = Label()
23                 self.updateColors()
24                 
25                 self["pretext"] = Label(_("Shutdown Dreambox after"))
26                 self["input"] = Input(text = str(self.session.nav.SleepTimer.getCurrentSleepTime()), maxSize = False, type = Input.NUMBER)
27                 self["aftertext"] = Label(_("minutes"))
28                 
29                 self["actions"] = NumberActionMap(["SleepTimerEditorActions"], 
30                 {
31                         "exit": self.close,
32                         "select": self.select,
33                         "1": self.keyNumberGlobal,
34                         "2": self.keyNumberGlobal,
35                         "3": self.keyNumberGlobal,
36                         "4": self.keyNumberGlobal,
37                         "5": self.keyNumberGlobal,
38                         "6": self.keyNumberGlobal,
39                         "7": self.keyNumberGlobal,
40                         "8": self.keyNumberGlobal,
41                         "9": self.keyNumberGlobal,
42                         "0": self.keyNumberGlobal,
43                         "selectLeft": self.selectLeft,
44                         "selectRight": self.selectRight,
45                         "disableTimer": self.disableTimer,
46                         "toggleAction": self.toggleAction,
47                         "toggleAsk": self.toggleAsk
48                 }, -1)
49                 
50         def updateColors(self):
51                 if self.session.nav.SleepTimer.isActive():
52                         self["red_text"].setText(_("Timer status:") + " " + _("Enabled"))
53                 else:
54                         self["red_text"].setText(_("Timer status:") + " " + _("Disabled"))
55                 if config.SleepTimer.action.value == "shutdown":
56                         self["green_text"].setText(_("Sleep timer action:") + " " + _("Deep Standby"))
57                 elif config.SleepTimer.action.value == "standby":
58                         self["green_text"].setText(_("Sleep timer action:") + " " + _("Standby"))
59
60                 if config.SleepTimer.ask.value:
61                         self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("yes"))
62                 else:
63                         self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("no"))
64                 self["blue_text"].setText(_("Settings"))
65                 
66                 
67         def select(self):
68                 self.session.nav.SleepTimer.setSleepTime(int(self["input"].getText()))
69                 self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been acitvated."), MessageBox.TYPE_INFO)
70         
71         def keyNumberGlobal(self, number):
72                 self["input"].number(number)
73                 
74         def selectLeft(self):
75                 self["input"].left()
76
77         def selectRight(self):
78                 self["input"].right()
79         
80         def disableTimer(self):
81                 if self.session.nav.SleepTimer.isActive():
82                         self.session.nav.SleepTimer.clear()
83                 else:
84                         self.session.nav.SleepTimer.setSleepTime(int(self["input"].getText()))
85                 self.updateColors()
86                 
87         def toggleAction(self):
88                 if config.SleepTimer.action.value == "shutdown":
89                         config.SleepTimer.action.value = "standby"
90                 elif config.SleepTimer.action.value == "standby":
91                         config.SleepTimer.action.value = "shutdown"
92                 self.updateColors()
93                 
94         def toggleAsk(self):
95                 config.SleepTimer.ask.value = not config.SleepTimer.ask.value
96                 self.updateColors()