typos
[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
9 class SleepTimerEdit(Screen):
10         def __init__(self, session):
11                 Screen.__init__(self, session)
12                 
13                 self["red"] = Pixmap()
14                 self["green"] = Pixmap()
15                 self["yellow"] = Pixmap()
16                 self["blue"] = Pixmap()
17                 self["red_text"] = Label()
18                 self["green_text"] = Label()
19                 self["yellow_text"] = Label()
20                 self["blue_text"] = Label()
21                 self.is_active = self.session.nav.SleepTimer.isActive()
22                 self.updateColors()
23                 
24                 self["pretext"] = Label(_("Shutdown Dreambox after"))
25                 self["input"] = Input(text = str(self.session.nav.SleepTimer.getCurrentSleepTime()), maxSize = False, type = Input.NUMBER)
26                 self["aftertext"] = Label(_("minutes"))
27                 
28                 self["actions"] = NumberActionMap(["SleepTimerEditorActions", "TextEntryActions", "KeyboardInputActions"], 
29                 {
30                         "exit": self.cancel,
31                         "select": self.select,
32                         "1": self.keyNumberGlobal,
33                         "2": self.keyNumberGlobal,
34                         "3": self.keyNumberGlobal,
35                         "4": self.keyNumberGlobal,
36                         "5": self.keyNumberGlobal,
37                         "6": self.keyNumberGlobal,
38                         "7": self.keyNumberGlobal,
39                         "8": self.keyNumberGlobal,
40                         "9": self.keyNumberGlobal,
41                         "0": self.keyNumberGlobal,
42                         "selectLeft": self.selectLeft,
43                         "selectRight": self.selectRight,
44                         "left": self.selectLeft,
45                         "right": self.selectRight,
46                         "home": self.selectHome,
47                         "end": self.selectEnd,
48                         "deleteForward": self.deleteForward,
49                         "deleteBackward": self.deleteBackward,
50                         "disableTimer": self.disableTimer,
51                         "toggleAction": self.toggleAction,
52                         "toggleAsk": self.toggleAsk
53                 }, -1)
54
55         def updateColors(self):
56                 if self.is_active:
57                         self["red_text"].setText(_("Timer status:") + " " + _("Enabled"))
58                 else:
59                         self["red_text"].setText(_("Timer status:") + " " + _("Disabled"))
60                 
61                 if config.SleepTimer.action.value == "shutdown":
62                         self["green_text"].setText(_("Sleep timer action:") + " " + _("Deep Standby"))
63                 elif config.SleepTimer.action.value == "standby":
64                         self["green_text"].setText(_("Sleep timer action:") + " " + _("Standby"))
65                 
66                 if config.SleepTimer.ask.value:
67                         self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("yes"))
68                 else:
69                         self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("no"))
70                 self["blue_text"].setText(_("Settings"))
71
72         def cancel(self):
73                 config.SleepTimer.ask.cancel()
74                 config.SleepTimer.action.cancel()
75                 self.close()
76
77         def select(self):
78                 if self.is_active:
79                         self.session.nav.SleepTimer.setSleepTime(int(self["input"].getText()))
80                         self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been activated."), MessageBox.TYPE_INFO)
81                 else:
82                         self.session.nav.SleepTimer.clear()
83                         self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been disabled."), MessageBox.TYPE_INFO)
84
85         def keyNumberGlobal(self, number):
86                 self["input"].number(number)
87
88         def selectLeft(self):
89                 self["input"].left()
90
91         def selectRight(self):
92                 self["input"].right()
93
94         def selectHome(self):
95                 self["input"].home()
96         
97         def selectEnd(self):
98                 self["input"].end()
99         
100         def deleteForward(self):
101                 self["input"].delete()
102         
103         def deleteBackward(self):
104                 self["input"].deleteBackward()
105         
106         def disableTimer(self):
107                 self.is_active = not self.is_active
108                 self.updateColors()
109
110         def toggleAction(self):
111                 if config.SleepTimer.action.value == "shutdown":
112                         config.SleepTimer.action.value = "standby"
113                 elif config.SleepTimer.action.value == "standby":
114                         config.SleepTimer.action.value = "shutdown"
115                 self.updateColors()
116
117         def toggleAsk(self):
118                 config.SleepTimer.ask.value = not config.SleepTimer.ask.value
119                 self.updateColors()