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 Components.SystemInfo import SystemInfo
9 from enigma import eEPGCache
10 from SleepTimer import SleepTimer
13 config.SleepTimer.defaulttime = ConfigInteger(default = 30)
15 class SleepTimerEdit(Screen):
16 def __init__(self, session):
17 Screen.__init__(self, session)
19 self["red"] = Pixmap()
20 self["green"] = Pixmap()
21 self["yellow"] = Pixmap()
22 self["blue"] = Pixmap()
23 self["red_text"] = Label()
24 self["green_text"] = Label()
25 self["yellow_text"] = Label()
26 self["blue_text"] = Label()
27 self["current_status"] = Label()
28 self.is_active = self.session.nav.SleepTimer.isActive()
30 self["current_status"].setText(_("Timer status:") + " " + _("Enabled"))
32 self["current_status"].setText(_("Timer status:") + " " + _("Disabled"))
35 self.time = self.session.nav.SleepTimer.getCurrentSleepTime()
37 self.time = config.SleepTimer.defaulttime.value
38 self["input"] = Input(text = str(self.time), maxSize = False, type = Input.NUMBER)
43 self["pretext"] = Label(_("Shutdown Dreambox after"))
44 self["aftertext"] = Label(_("minutes"))
46 self["actions"] = NumberActionMap(["SleepTimerEditorActions", "TextEntryActions", "KeyboardInputActions"],
49 "select": self.select,
50 "1": self.keyNumberGlobal,
51 "2": self.keyNumberGlobal,
52 "3": self.keyNumberGlobal,
53 "4": self.keyNumberGlobal,
54 "5": self.keyNumberGlobal,
55 "6": self.keyNumberGlobal,
56 "7": self.keyNumberGlobal,
57 "8": self.keyNumberGlobal,
58 "9": self.keyNumberGlobal,
59 "0": self.keyNumberGlobal,
60 "selectLeft": self.selectLeft,
61 "selectRight": self.selectRight,
62 "left": self.selectLeft,
63 "right": self.selectRight,
64 "home": self.selectHome,
65 "end": self.selectEnd,
66 "deleteForward": self.deleteForward,
67 "deleteBackward": self.deleteBackward,
68 "disableTimer": self.disableTimer,
69 "toggleAction": self.toggleAction,
70 "toggleAsk": self.toggleAsk,
71 "useServiceTime": self.useServiceTime
74 def updateColors(self):
76 self["red_text"].setText(_("Action:") + " " + _("Enable timer"))
78 self["red_text"].setText(_("Action:") + " " + _("Disable timer"))
80 if config.SleepTimer.action.value == "shutdown":
81 if SystemInfo["DeepstandbySupport"]:
82 shutdownString = _("Deep Standby")
84 shutdownString = _("Shutdown")
85 self["green_text"].setText(_("Sleep timer action:") + " " + shutdownString)
86 elif config.SleepTimer.action.value == "standby":
87 self["green_text"].setText(_("Sleep timer action:") + " " + _("Standby"))
89 if config.SleepTimer.ask.value:
90 self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("yes"))
92 self["yellow_text"].setText(_("Ask before shutdown:") + " " + _("no"))
93 self["blue_text"].setText(_("Use time of currently running service"))
96 config.SleepTimer.ask.cancel()
97 config.SleepTimer.action.cancel()
102 time = int(self["input"].getText())
103 config.SleepTimer.defaulttime.setValue(time)
104 config.SleepTimer.defaulttime.save()
105 config.SleepTimer.action.save()
106 self.session.nav.SleepTimer.setSleepTime(time)
107 self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been activated."), MessageBox.TYPE_INFO)
109 self.session.nav.SleepTimer.clear()
110 self.session.openWithCallback(self.close, MessageBox, _("The sleep timer has been disabled."), MessageBox.TYPE_INFO)
112 def keyNumberGlobal(self, number):
113 self["input"].number(number)
115 def selectLeft(self):
118 def selectRight(self):
119 self["input"].right()
121 def selectHome(self):
127 def deleteForward(self):
128 self["input"].delete()
130 def deleteBackward(self):
131 self["input"].deleteBackward()
133 def disableTimer(self):
134 self.status = not self.status
137 def toggleAction(self):
138 if config.SleepTimer.action.value == "shutdown":
139 config.SleepTimer.action.value = "standby"
140 elif config.SleepTimer.action.value == "standby":
141 config.SleepTimer.action.value = "shutdown"
145 config.SleepTimer.ask.value = not config.SleepTimer.ask.value
148 def useServiceTime(self):
150 ref = self.session.nav.getCurrentlyPlayingServiceReference()
154 service = self.session.nav.getCurrentService()
155 seek = service and service.seek()
157 length = seek.getLength()
158 position = seek.getPlayPosition()
159 if length and position:
160 remaining = length[1] - position[1]
162 remaining = remaining / 90000
164 epg = eEPGCache.getInstance()
165 event = epg.lookupEventTime(ref, -1, 0)
168 start = event.getBeginTime()
169 duration = event.getDuration()
170 end = start + duration
171 remaining = end - now
173 config.SleepTimer.defaulttime.value = (remaining / 60) + 2
174 self["input"].setText(str((remaining / 60) + 2))