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 enigma import eEPGCache
9 from SleepTimer import SleepTimer
12 config.SleepTimer.defaulttime = ConfigInteger(default = 30)
14 class SleepTimerEdit(Screen):
15 def __init__(self, session):
16 Screen.__init__(self, session)
18 self["red"] = Pixmap()
19 self["green"] = Pixmap()
20 self["yellow"] = Pixmap()
21 self["blue"] = Pixmap()
22 self["red_text"] = Label()
23 self["green_text"] = Label()
24 self["yellow_text"] = Label()
25 self["blue_text"] = Label()
26 self["current_status"] = Label()
27 self.is_active = self.session.nav.SleepTimer.isActive()
29 self["current_status"].setText(_("Timer status:") + " " + _("Enabled"))
31 self["current_status"].setText(_("Timer status:") + " " + _("Disabled"))
34 self.time = self.session.nav.SleepTimer.getCurrentSleepTime()
36 self.time = config.SleepTimer.defaulttime.value
37 self["input"] = Input(text = str(self.time), maxSize = False, type = Input.NUMBER)
42 self["pretext"] = Label(_("Shutdown Dreambox after"))
43 self["aftertext"] = Label(_("minutes"))
45 self["actions"] = NumberActionMap(["SleepTimerEditorActions", "TextEntryActions", "KeyboardInputActions"],
48 "select": self.select,
49 "1": self.keyNumberGlobal,
50 "2": self.keyNumberGlobal,
51 "3": self.keyNumberGlobal,
52 "4": self.keyNumberGlobal,
53 "5": self.keyNumberGlobal,
54 "6": self.keyNumberGlobal,
55 "7": self.keyNumberGlobal,
56 "8": self.keyNumberGlobal,
57 "9": self.keyNumberGlobal,
58 "0": self.keyNumberGlobal,
59 "selectLeft": self.selectLeft,
60 "selectRight": self.selectRight,
61 "left": self.selectLeft,
62 "right": self.selectRight,
63 "home": self.selectHome,
64 "end": self.selectEnd,
65 "deleteForward": self.deleteForward,
66 "deleteBackward": self.deleteBackward,
67 "disableTimer": self.disableTimer,
68 "toggleAction": self.toggleAction,
69 "toggleAsk": self.toggleAsk,
70 "useServiceTime": self.useServiceTime
73 def updateColors(self):
75 self["red_text"].setText(_("Action:") + " " + _("Enable timer"))
77 self["red_text"].setText(_("Action:") + " " + _("Disable timer"))
79 if config.SleepTimer.action.value == "shutdown":
80 self["green_text"].setText(_("Sleep timer action:") + " " + _("Deep Standby"))
81 elif config.SleepTimer.action.value == "standby":
82 self["green_text"].setText(_("Sleep timer action:") + " " + _("Standby"))
84 if config.SleepTimer.ask.value:
85 self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("yes"))
87 self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("no"))
88 self["blue_text"].setText(_("Use time of currently running service"))
91 config.SleepTimer.ask.cancel()
92 config.SleepTimer.action.cancel()
97 time = int(self["input"].getText())
98 config.SleepTimer.defaulttime.setValue(time)
99 config.SleepTimer.defaulttime.save()
100 config.SleepTimer.action.save()
101 self.session.nav.SleepTimer.setSleepTime(time)
102 self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been activated."), MessageBox.TYPE_INFO)
104 self.session.nav.SleepTimer.clear()
105 self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been disabled."), MessageBox.TYPE_INFO)
107 def keyNumberGlobal(self, number):
108 self["input"].number(number)
110 def selectLeft(self):
113 def selectRight(self):
114 self["input"].right()
116 def selectHome(self):
122 def deleteForward(self):
123 self["input"].delete()
125 def deleteBackward(self):
126 self["input"].deleteBackward()
128 def disableTimer(self):
129 self.status = not self.status
132 def toggleAction(self):
133 if config.SleepTimer.action.value == "shutdown":
134 config.SleepTimer.action.value = "standby"
135 elif config.SleepTimer.action.value == "standby":
136 config.SleepTimer.action.value = "shutdown"
140 config.SleepTimer.ask.value = not config.SleepTimer.ask.value
143 def useServiceTime(self):
145 ref = self.session.nav.getCurrentlyPlayingServiceReference()
149 service = self.session.nav.getCurrentService()
150 seek = service and service.seek()
152 length = seek.getLength()
153 position = seek.getPlayPosition()
154 if length and position:
155 remaining = length[1] - position[1]
157 remaining = remaining / 90000
159 epg = eEPGCache.getInstance()
160 event = epg.lookupEventTime(ref, -1, 0)
163 start = event.getBeginTime()
164 duration = event.getDuration()
165 end = start + duration
166 remaining = end - now
168 config.SleepTimer.defaulttime.value = (remaining / 60) + 2
169 self["input"].setText(str((remaining / 60) + 2))