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
10 config.SleepTimer.defaulttime = ConfigInteger(default = 30)
12 class SleepTimerEdit(Screen):
13 def __init__(self, session):
14 Screen.__init__(self, session)
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()
27 self["current_status"].setText(_("Timer status:") + " " + _("Enabled"))
29 self["current_status"].setText(_("Timer status:") + " " + _("Disabled"))
32 self.time = self.session.nav.SleepTimer.getCurrentSleepTime()
34 self.time = config.SleepTimer.defaulttime.value
35 self["input"] = Input(text = str(self.time), maxSize = False, type = Input.NUMBER)
41 self["pretext"] = Label(_("Shutdown Dreambox after"))
42 self["aftertext"] = Label(_("minutes"))
44 self["actions"] = NumberActionMap(["SleepTimerEditorActions", "TextEntryActions", "KeyboardInputActions"],
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
71 def updateColors(self):
73 self["red_text"].setText(_("Action:") + " " + _("Enable timer"))
75 self["red_text"].setText(_("Action:") + " " + _("Disable timer"))
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"))
82 if config.SleepTimer.ask.value:
83 self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("yes"))
85 self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("no"))
86 self["blue_text"].setText(_("Settings"))
89 config.SleepTimer.ask.cancel()
90 config.SleepTimer.action.cancel()
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)
100 self.session.nav.SleepTimer.clear()
101 self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been disabled."), MessageBox.TYPE_INFO)
103 def keyNumberGlobal(self, number):
104 self["input"].number(number)
106 def selectLeft(self):
109 def selectRight(self):
110 self["input"].right()
112 def selectHome(self):
118 def deleteForward(self):
119 self["input"].delete()
121 def deleteBackward(self):
122 self["input"].deleteBackward()
124 def disableTimer(self):
125 self.status = not self.status
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"
136 config.SleepTimer.ask.value = not config.SleepTimer.ask.value