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