fix coverart png stuff
[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"], 
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                         "disableTimer": self.disableTimer,
45                         "toggleAction": self.toggleAction,
46                         "toggleAsk": self.toggleAsk
47                 }, -1)
48
49         def updateColors(self):
50                 if self.is_active:
51                         self["red_text"].setText(_("Timer status:") + " " + _("Enabled"))
52                 else:
53                         self["red_text"].setText(_("Timer status:") + " " + _("Disabled"))
54                 
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         def cancel(self):
67                 config.SleepTimer.ask.cancel()
68                 config.SleepTimer.action.cancel()
69                 self.close()
70
71         def select(self):
72                 if self.is_active:
73                         self.session.nav.SleepTimer.setSleepTime(int(self["input"].getText()))
74                         self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been activated."), MessageBox.TYPE_INFO)
75                 else:
76                         self.session.nav.SleepTimer.clear()
77                         self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been disabled."), MessageBox.TYPE_INFO)
78
79         def keyNumberGlobal(self, number):
80                 self["input"].number(number)
81
82         def selectLeft(self):
83                 self["input"].left()
84
85         def selectRight(self):
86                 self["input"].right()
87
88         def disableTimer(self):
89                 self.is_active = not self.is_active
90                 self.updateColors()
91
92         def toggleAction(self):
93                 if config.SleepTimer.action.value == "shutdown":
94                         config.SleepTimer.action.value = "standby"
95                 elif config.SleepTimer.action.value == "standby":
96                         config.SleepTimer.action.value = "shutdown"
97                 self.updateColors()
98
99         def toggleAsk(self):
100                 config.SleepTimer.ask.value = not config.SleepTimer.ask.value
101                 self.updateColors()