1 from Screen import Screen
2 import ChannelSelection
3 from ServiceReference import ServiceReference
4 from Components.config import *
5 from Components.ActionMap import ActionMap, NumberActionMap
6 from Components.ConfigList import ConfigList
7 from Components.MenuList import MenuList
8 from Components.Button import Button
9 from Components.NimManager import nimmanager
10 from Components.Label import Label
11 from Components.Pixmap import Pixmap
12 from Screens.SubserviceSelection import SubserviceSelection
13 from Screens.MessageBox import MessageBox
14 from RecordTimer import AFTEREVENT
15 from enigma import eEPGCache
19 class TimerEntry(Screen):
20 def __init__(self, session, timer):
21 Screen.__init__(self, session)
24 self["oktext"] = Label(_("OK"))
25 self["canceltext"] = Label(_("Cancel"))
27 self["cancel"] = Pixmap()
31 self["actions"] = NumberActionMap(["SetupActions", "TextEntryActions"],
35 "cancel": self.keyCancel,
37 "right": self.keyRight,
38 "delete": self.keyDelete,
39 "1": self.keyNumberGlobal,
40 "2": self.keyNumberGlobal,
41 "3": self.keyNumberGlobal,
42 "4": self.keyNumberGlobal,
43 "5": self.keyNumberGlobal,
44 "6": self.keyNumberGlobal,
45 "7": self.keyNumberGlobal,
46 "8": self.keyNumberGlobal,
47 "9": self.keyNumberGlobal,
48 "0": self.keyNumberGlobal
52 self["config"] = ConfigList(self.list)
53 self.createSetup("config")
55 def createConfig(self):
56 config.timerentry = ConfigSubsection()
58 if (self.timer.justplay):
63 afterevent = { AFTEREVENT.NONE: 0, AFTEREVENT.DEEPSTANDBY: 1, AFTEREVENT.STANDBY: 2}[self.timer.afterEvent]
65 # calculate default values
70 if (self.timer.repeated != 0): # repeated
72 if (self.timer.repeated == 31): # Mon-Fri
73 repeated = 2 # Mon - Fri
74 elif (self.timer.repeated == 127): # daily
77 flags = self.timer.repeated
78 repeated = 3 # user defined
81 if (flags == 1): # weekly
82 print "Set to weekday " + str(x)
84 if (flags & 1 == 1): # set user defined flags
95 weekday = (int(strftime("%w", time.localtime(self.timer.begin))) - 1) % 7
98 config.timerentry.justplay = configElement_nonSave("config.timerentry.justplay", configSelection, justplay, (("zap", _("zap")), ("record", _("record"))))
99 config.timerentry.afterevent = configElement_nonSave("config.timerentry.afterevent", configSelection, afterevent, (("nothing", _("do nothing")), ("deepstandby", _("go to deep standby"))))
100 config.timerentry.type = configElement_nonSave("config.timerentry.type", configSelection, type, (_("once"), _("repeated")))
101 config.timerentry.name = configElement_nonSave("config.timerentry.name", configText, self.timer.name, (configText.extendableSize, self.keyRightCallback))
102 config.timerentry.description = configElement_nonSave("config.timerentry.description", configText, self.timer.description, (configText.extendableSize, self.keyRightCallback))
104 config.timerentry.repeated = configElement_nonSave("config.timerentry.repeated", configSelection, repeated, (_("daily"), _("weekly"), _("Mon-Fri"), _("user defined")))
106 config.timerentry.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, self.timer.begin, (_("%d.%B %Y"), 86400))
107 config.timerentry.starttime = configElement_nonSave("config.timerentry.starttime", configSequence, [int(time.strftime("%H", time.localtime(self.timer.begin))), int(time.strftime("%M", time.localtime(self.timer.begin)))], configsequencearg.get("CLOCK"))
109 config.timerentry.enddate = configElement_nonSave("config.timerentry.enddate", configDateTime, self.timer.end, (_("%d.%B %Y"), 86400))
110 config.timerentry.endtime = configElement_nonSave("config.timerentry.endtime", configSequence, [int(time.strftime("%H", time.localtime(self.timer.end))), int(time.strftime("%M", time.localtime(self.timer.end)))], configsequencearg.get("CLOCK"))
112 config.timerentry.weekday = configElement_nonSave("config.timerentry.weekday", configSelection, weekday, (_("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"), _("Sunday")))
114 config.timerentry.day = []
116 config.timerentry.day.append(configElement_nonSave("config.timerentry.day[" + str(x) + "]", configSelection, day[x], (_("yes"), _("no"))))
119 # FIXME some service-chooser needed here
121 try: # no current service available?
122 servicename = str(self.timer.service_ref.getServiceName())
125 config.timerentry.service = configElement_nonSave("config.timerentry.service", configSelection, 0, ((servicename),))
127 config.timerentry.startdate.addNotifier(self.checkDate)
128 config.timerentry.enddate.addNotifier(self.checkDate)
130 def checkDate(self, configElement):
131 if (configElement.getConfigPath() == "config.timerentry.startdate"):
132 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
133 config.timerentry.enddate.value = config.timerentry.startdate.value
134 config.timerentry.enddate.change()
136 self["config"].invalidate(config.timerentry.enddate)
139 if (configElement.getConfigPath() == "config.timerentry.enddate"):
140 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
141 config.timerentry.startdate.value = config.timerentry.enddate.value
142 config.timerentry.startdate.change()
144 self["config"].invalidate(config.timerentry.startdate)
148 def createSetup(self, widget):
150 self.list.append(getConfigListEntry(_("Name"), config.timerentry.name))
151 self.list.append(getConfigListEntry(_("Description"), config.timerentry.description))
152 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), config.timerentry.justplay)
153 self.list.append(self.timerJustplayEntry)
154 self.timerTypeEntry = getConfigListEntry(_("Repeat Type"), config.timerentry.type)
155 self.list.append(self.timerTypeEntry)
157 if (config.timerentry.type.value == 0): # once
158 self.frequencyEntry = None
160 self.frequencyEntry = getConfigListEntry(_("Frequency"), config.timerentry.repeated)
161 self.list.append(self.frequencyEntry)
162 if (config.timerentry.repeated.value == 0): # daily
164 if (config.timerentry.repeated.value == 2): # Mon-Fri
166 if (config.timerentry.repeated.value == 1): # weekly
167 self.list.append(getConfigListEntry(_("Weekday"), config.timerentry.weekday))
169 if (config.timerentry.repeated.value == 3): # user defined
170 self.list.append(getConfigListEntry(_("Monday"), config.timerentry.day[0]))
171 self.list.append(getConfigListEntry(_("Tuesday"), config.timerentry.day[1]))
172 self.list.append(getConfigListEntry(_("Wednesday"), config.timerentry.day[2]))
173 self.list.append(getConfigListEntry(_("Thursday"), config.timerentry.day[3]))
174 self.list.append(getConfigListEntry(_("Friday"), config.timerentry.day[4]))
175 self.list.append(getConfigListEntry(_("Saturday"), config.timerentry.day[5]))
176 self.list.append(getConfigListEntry(_("Sunday"), config.timerentry.day[6]))
178 #self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
179 # self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
181 if (config.timerentry.type.value == 0): # once
182 self.list.append(getConfigListEntry(_("Start"), config.timerentry.startdate))
183 self.list.append(getConfigListEntry(" ", config.timerentry.starttime))
185 self.list.append(getConfigListEntry(_("StartTime"), config.timerentry.starttime))
186 if (config.timerentry.type.value == 0): # once
187 if currentConfigSelectionElement(config.timerentry.justplay) != "zap":
188 self.list.append(getConfigListEntry(_("End"), config.timerentry.enddate))
189 self.list.append(getConfigListEntry(" ", config.timerentry.endtime))
191 if currentConfigSelectionElement(config.timerentry.justplay) != "zap":
192 self.list.append(getConfigListEntry(_("EndTime"), config.timerentry.endtime))
194 if currentConfigSelectionElement(config.timerentry.justplay) != "zap":
195 self.list.append(getConfigListEntry(_("After event"), config.timerentry.afterevent))
197 self.channelEntry = getConfigListEntry(_("Channel"), config.timerentry.service)
198 self.list.append(self.channelEntry)
200 self[widget].list = self.list
201 self[widget].l.setList(self.list)
204 print "newConfig", self["config"].getCurrent()
205 if self["config"].getCurrent() == self.timerTypeEntry:
206 self.createSetup("config")
207 if self["config"].getCurrent() == self.timerJustplayEntry:
208 self.createSetup("config")
209 if self["config"].getCurrent() == self.frequencyEntry:
210 self.createSetup("config")
213 if self["config"].getCurrent() == self.channelEntry:
216 self["config"].handleKey(config.key["prevElement"])
220 self["config"].handleKey(config.key["delete"])
222 def keyRightCallback(self, configPath):
223 currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
224 # check if we are still on the same config entry
225 if (currentConfigPath == configPath):
229 if self["config"].getCurrent() == self.channelEntry:
232 self["config"].handleKey(config.key["nextElement"])
236 if self["config"].getCurrent() == self.channelEntry:
237 self.session.openWithCallback(self.finishedChannelSelection, ChannelSelection.SimpleChannelSelection, _("Select channel to record from"))
241 def finishedChannelSelection(self, *args):
243 self.timer.service_ref = ServiceReference(args[0])
244 config.timerentry.service.vals = (str(self.timer.service_ref.getServiceName()),)
245 self["config"].invalidate(config.timerentry.service)
247 def keyNumberGlobal(self, number):
248 print "You pressed number " + str(number)
249 if (self["config"].getCurrent()[1].parent.enabled == True):
250 self["config"].handleKey(config.key[str(number)])
252 def getTimestamp(self, date, mytime):
253 d = time.localtime(date)
254 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
255 return int(mktime(dt.timetuple()))
258 self.timer.name = config.timerentry.name.value
259 self.timer.description = config.timerentry.description.value
260 self.timer.justplay = (currentConfigSelectionElement(config.timerentry.justplay) == "zap")
261 self.timer.resetRepeated()
262 self.timer.afterEvent = { 0: AFTEREVENT.NONE, 1: AFTEREVENT.DEEPSTANDBY, 2: AFTEREVENT.STANDBY}[config.timerentry.afterevent.value]
264 if (config.timerentry.type.value == 0): # once
265 self.timer.begin = self.getTimestamp(config.timerentry.startdate.value, config.timerentry.starttime.value)
266 self.timer.end = self.getTimestamp(config.timerentry.enddate.value, config.timerentry.endtime.value)
267 if (config.timerentry.type.value == 1): # repeated
268 if (config.timerentry.repeated.value == 0): # daily
270 self.timer.setRepeated(x)
272 if (config.timerentry.repeated.value == 1): # weekly
273 self.timer.setRepeated(config.timerentry.weekday.value)
275 if (config.timerentry.repeated.value == 2): # Mon-Fri
277 self.timer.setRepeated(x)
279 if (config.timerentry.repeated.value == 3): # user defined
281 if (config.timerentry.day[x].value == 0): self.timer.setRepeated(x)
283 self.timer.begin = self.getTimestamp(time.time(), config.timerentry.starttime.value)
284 self.timer.end = self.getTimestamp(time.time(), config.timerentry.endtime.value)
286 if self.timer.eit is not None:
287 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
288 if event is not None:
289 if event.getNumOfLinkageServices() > 0:
290 self.session.openWithCallback(self.subserviceSelected, SubserviceSelection, event, self.timer.service_ref.ref)
292 self.close((True, self.timer))
294 def subserviceSelected(self, service):
295 if not service is None:
296 self.timer.service_ref = ServiceReference(service)
297 self.close((True, self.timer))
302 class TimerLog(Screen):
303 def __init__(self, session, timer):
304 Screen.__init__(self, session)
306 self.log_entries = self.timer.log_entries[:]
310 self["loglist"] = MenuList(self.list)
311 self["logentry"] = Label()
313 self["key_red"] = Button(_("Delete entry"))
314 self["key_green"] = Button()
315 self["key_yellow"] = Button("")
316 self["key_blue"] = Button(_("Clear log"))
318 self.onShown.append(self.updateText)
320 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
323 "cancel": self.keyClose,
328 "red": self.deleteEntry,
329 "blue": self.clearLog
332 def deleteEntry(self):
333 self.log_entries.remove(self["loglist"].getCurrent()[1])
335 self["loglist"].l.setList(self.list)
338 def fillLogList(self):
340 for x in self.log_entries:
341 self.list.append((str(strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x))
344 self.log_entries = []
346 self["loglist"].l.setList(self.list)
350 if self.timer.log_entries != self.log_entries:
351 self.timer.log_entries = self.log_entries
352 self.close((True, self.timer))
357 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
361 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
365 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
369 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
372 def updateText(self):
373 if len(self.list) > 0:
374 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
376 self["logentry"].setText("")