revert local change
[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.is_active = self.session.nav.SleepTimer.isActive()
24                 self.updateColors()
25                 
26                 self["pretext"] = Label(_("Shutdown Dreambox after"))
27                 self["input"] = Input(text = str(self.session.nav.SleepTimer.getCurrentSleepTime()), maxSize = False, type = Input.NUMBER)
28                 self["aftertext"] = Label(_("minutes"))
29                 
30                 self["actions"] = NumberActionMap(["SleepTimerEditorActions"], 
31                 {
32                         "exit": self.cancel,
33                         "select": self.select,
34                         "1": self.keyNumberGlobal,
35                         "2": self.keyNumberGlobal,
36                         "3": self.keyNumberGlobal,
37                         "4": self.keyNumberGlobal,
38                         "5": self.keyNumberGlobal,
39                         "6": self.keyNumberGlobal,
40                         "7": self.keyNumberGlobal,
41                         "8": self.keyNumberGlobal,
42                         "9": self.keyNumberGlobal,
43                         "0": self.keyNumberGlobal,
44                         "selectLeft": self.selectLeft,
45                         "selectRight": self.selectRight,
46                         "disableTimer": self.disableTimer,
47                         "toggleAction": self.toggleAction,
48                         "toggleAsk": self.toggleAsk
49                 }, -1)
50
51         def updateColors(self):
52                 if self.is_active:
53                         self["red_text"].setText(_("Timer status:") + " " + _("Enabled"))
54                 else:
55                         self["red_text"].setText(_("Timer status:") + " " + _("Disabled"))
56                 
57                 if config.SleepTimer.action.value == "shutdown":
58                         self["green_text"].setText(_("Sleep timer action:") + " " + _("Deep Standby"))
59                 elif config.SleepTimer.action.value == "standby":
60                         self["green_text"].setText(_("Sleep timer action:") + " " + _("Standby"))
61                 
62                 if config.SleepTimer.ask.value:
63                         self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("yes"))
64                 else:
65                         self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("no"))
66                 self["blue_text"].setText(_("Settings"))
67
68         def cancel(self):
69                 config.SleepTimer.ask.cancel()
70                 config.SleepTimer.action.cancel()
71                 self.close()
72
73         def select(self):
74                 if self.is_active:
75                         self.session.nav.SleepTimer.setSleepTime(int(self["input"].getText()))
76                         self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been activated."), MessageBox.TYPE_INFO)
77                 else:
78                         self.session.nav.SleepTimer.clear()
79                         self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been disabled."), MessageBox.TYPE_INFO)
80
81         def keyNumberGlobal(self, number):
82                 self["input"].number(number)
83
84         def selectLeft(self):
85                 self["input"].left()
86
87         def selectRight(self):
88                 self["input"].right()
89
90         def disableTimer(self):
91                 self.is_active = not self.is_active
92                 self.updateColors()
93
94         def toggleAction(self):
95                 if config.SleepTimer.action.value == "shutdown":
96                         config.SleepTimer.action.value = "standby"
97                 elif config.SleepTimer.action.value == "standby":
98                         config.SleepTimer.action.value = "shutdown"
99                 self.updateColors()
100
101         def toggleAsk(self):
102                 config.SleepTimer.ask.value = not config.SleepTimer.ask.value
103                 self.updateColors()