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 enigma import eEPGCache
18 class TimerEntry(Screen):
19 def __init__(self, session, timer):
20 Screen.__init__(self, session)
23 self["oktext"] = Label(_("OK"))
24 self["canceltext"] = Label(_("Cancel"))
26 self["cancel"] = Pixmap()
30 self["actions"] = NumberActionMap(["SetupActions", "TextEntryActions"],
34 "cancel": self.keyCancel,
36 "right": self.keyRight,
37 "delete": self.keyDelete,
38 "1": self.keyNumberGlobal,
39 "2": self.keyNumberGlobal,
40 "3": self.keyNumberGlobal,
41 "4": self.keyNumberGlobal,
42 "5": self.keyNumberGlobal,
43 "6": self.keyNumberGlobal,
44 "7": self.keyNumberGlobal,
45 "8": self.keyNumberGlobal,
46 "9": self.keyNumberGlobal,
47 "0": self.keyNumberGlobal
51 self["config"] = ConfigList(self.list)
52 self.createSetup("config")
54 def createConfig(self):
55 config.timerentry = ConfigSubsection()
57 if (self.timer.justplay):
62 # calculate default values
67 if (self.timer.repeated != 0): # repeated
69 if (self.timer.repeated == 31): # Mon-Fri
70 repeated = 2 # Mon - Fri
71 elif (self.timer.repeated == 127): # daily
74 flags = self.timer.repeated
75 repeated = 3 # user defined
78 if (flags == 1): # weekly
79 print "Set to weekday " + str(x)
81 if (flags & 1 == 1): # set user defined flags
92 weekday = (int(strftime("%w", time.localtime(self.timer.begin))) - 1) % 7
95 config.timerentry.justplay = configElement_nonSave("config.timerentry.justplay", configSelection, justplay, (("zap", _("zap")), ("record", _("record"))))
96 config.timerentry.type = configElement_nonSave("config.timerentry.type", configSelection, type, (_("once"), _("repeated")))
97 config.timerentry.name = configElement_nonSave("config.timerentry.name", configText, self.timer.name, (configText.extendableSize, self.keyRightCallback))
98 config.timerentry.description = configElement_nonSave("config.timerentry.description", configText, self.timer.description, (configText.extendableSize, self.keyRightCallback))
100 config.timerentry.repeated = configElement_nonSave("config.timerentry.repeated", configSelection, repeated, (_("daily"), _("weekly"), _("Mon-Fri"), _("user defined")))
102 config.timerentry.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, self.timer.begin, (_("%d.%B %Y"), 86400))
103 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"))
105 config.timerentry.enddate = configElement_nonSave("config.timerentry.enddate", configDateTime, self.timer.end, (_("%d.%B %Y"), 86400))
106 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"))
108 config.timerentry.weekday = configElement_nonSave("config.timerentry.weekday", configSelection, weekday, (_("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"), _("Sunday")))
110 config.timerentry.day = []
112 config.timerentry.day.append(configElement_nonSave("config.timerentry.day[" + str(x) + "]", configSelection, day[x], (_("yes"), _("no"))))
115 # FIXME some service-chooser needed here
117 try: # no current service available?
118 servicename = str(self.timer.service_ref.getServiceName())
121 config.timerentry.service = configElement_nonSave("config.timerentry.service", configSelection, 0, ((servicename),))
123 config.timerentry.startdate.addNotifier(self.checkDate)
124 config.timerentry.enddate.addNotifier(self.checkDate)
126 def checkDate(self, configElement):
127 if (configElement.getConfigPath() == "config.timerentry.startdate"):
128 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
129 config.timerentry.enddate.value = config.timerentry.startdate.value
130 config.timerentry.enddate.change()
132 self["config"].invalidate(config.timerentry.enddate)
135 if (configElement.getConfigPath() == "config.timerentry.enddate"):
136 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
137 config.timerentry.startdate.value = config.timerentry.enddate.value
138 config.timerentry.startdate.change()
140 self["config"].invalidate(config.timerentry.startdate)
144 def createSetup(self, widget):
146 self.list.append(getConfigListEntry(_("Name"), config.timerentry.name))
147 self.list.append(getConfigListEntry(_("Description"), config.timerentry.description))
148 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), config.timerentry.justplay)
149 self.list.append(self.timerJustplayEntry)
150 self.timerTypeEntry = getConfigListEntry(_("Repeat Type"), config.timerentry.type)
151 self.list.append(self.timerTypeEntry)
153 if (config.timerentry.type.value == 0): # once
154 self.frequencyEntry = None
156 self.frequencyEntry = getConfigListEntry(_("Frequency"), config.timerentry.repeated)
157 self.list.append(self.frequencyEntry)
158 if (config.timerentry.repeated.value == 0): # daily
160 if (config.timerentry.repeated.value == 2): # Mon-Fri
162 if (config.timerentry.repeated.value == 1): # weekly
163 self.list.append(getConfigListEntry(_("Weekday"), config.timerentry.weekday))
165 if (config.timerentry.repeated.value == 3): # user defined
166 self.list.append(getConfigListEntry(_("Monday"), config.timerentry.day[0]))
167 self.list.append(getConfigListEntry(_("Tuesday"), config.timerentry.day[1]))
168 self.list.append(getConfigListEntry(_("Wednesday"), config.timerentry.day[2]))
169 self.list.append(getConfigListEntry(_("Thursday"), config.timerentry.day[3]))
170 self.list.append(getConfigListEntry(_("Friday"), config.timerentry.day[4]))
171 self.list.append(getConfigListEntry(_("Saturday"), config.timerentry.day[5]))
172 self.list.append(getConfigListEntry(_("Sunday"), config.timerentry.day[6]))
174 #self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
175 # self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
177 if (config.timerentry.type.value == 0): # once
178 self.list.append(getConfigListEntry(_("Start"), config.timerentry.startdate))
179 self.list.append(getConfigListEntry(" ", config.timerentry.starttime))
181 self.list.append(getConfigListEntry(_("StartTime"), config.timerentry.starttime))
182 if (config.timerentry.type.value == 0): # once
183 if currentConfigSelectionElement(config.timerentry.justplay) != "zap":
184 self.list.append(getConfigListEntry(_("End"), config.timerentry.enddate))
185 self.list.append(getConfigListEntry(" ", config.timerentry.endtime))
187 if currentConfigSelectionElement(config.timerentry.justplay) != "zap":
188 self.list.append(getConfigListEntry(_("EndTime"), config.timerentry.endtime))
190 self.channelEntry = getConfigListEntry(_("Channel"), config.timerentry.service)
191 self.list.append(self.channelEntry)
193 self[widget].list = self.list
194 self[widget].l.setList(self.list)
197 print "newConfig", self["config"].getCurrent()
198 if self["config"].getCurrent() == self.timerTypeEntry:
199 self.createSetup("config")
200 if self["config"].getCurrent() == self.timerJustplayEntry:
201 self.createSetup("config")
202 if self["config"].getCurrent() == self.frequencyEntry:
203 self.createSetup("config")
206 if self["config"].getCurrent() == self.channelEntry:
209 self["config"].handleKey(config.key["prevElement"])
213 self["config"].handleKey(config.key["delete"])
215 def keyRightCallback(self, configPath):
216 currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
217 # check if we are still on the same config entry
218 if (currentConfigPath == configPath):
222 if self["config"].getCurrent() == self.channelEntry:
225 self["config"].handleKey(config.key["nextElement"])
229 if self["config"].getCurrent() == self.channelEntry:
230 self.session.openWithCallback(self.finishedChannelSelection, ChannelSelection.SimpleChannelSelection, _("Select channel to record from"))
234 def finishedChannelSelection(self, *args):
236 self.timer.service_ref = ServiceReference(args[0])
237 config.timerentry.service.vals = (str(self.timer.service_ref.getServiceName()),)
238 self["config"].invalidate(config.timerentry.service)
240 def keyNumberGlobal(self, number):
241 print "You pressed number " + str(number)
242 if (self["config"].getCurrent()[1].parent.enabled == True):
243 self["config"].handleKey(config.key[str(number)])
245 def getTimestamp(self, date, mytime):
246 d = time.localtime(date)
247 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
248 return int(mktime(dt.timetuple()))
251 self.timer.name = config.timerentry.name.value
252 self.timer.description = config.timerentry.description.value
253 self.timer.justplay = (currentConfigSelectionElement(config.timerentry.justplay) == "zap")
254 self.timer.resetRepeated()
256 if (config.timerentry.type.value == 0): # once
257 self.timer.begin = self.getTimestamp(config.timerentry.startdate.value, config.timerentry.starttime.value)
258 self.timer.end = self.getTimestamp(config.timerentry.enddate.value, config.timerentry.endtime.value)
259 if (config.timerentry.type.value == 1): # repeated
260 if (config.timerentry.repeated.value == 0): # daily
262 self.timer.setRepeated(x)
264 if (config.timerentry.repeated.value == 1): # weekly
265 self.timer.setRepeated(config.timerentry.weekday.value)
267 if (config.timerentry.repeated.value == 2): # Mon-Fri
269 self.timer.setRepeated(x)
271 if (config.timerentry.repeated.value == 3): # user defined
273 if (config.timerentry.day[x].value == 0): self.timer.setRepeated(x)
275 self.timer.begin = self.getTimestamp(time.time(), config.timerentry.starttime.value)
276 self.timer.end = self.getTimestamp(time.time(), config.timerentry.endtime.value)
278 if self.timer.eit is not None:
279 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
280 if event is not None:
281 if event.getNumOfLinkageServices() > 0:
282 self.session.openWithCallback(self.subserviceSelected, SubserviceSelection, event, self.timer.service_ref.ref)
284 self.close((True, self.timer))
286 def subserviceSelected(self, service):
287 if not service is None:
288 self.timer.service_ref = ServiceReference(service)
289 self.close((True, self.timer))
294 class TimerLog(Screen):
295 def __init__(self, session, timer):
296 Screen.__init__(self, session)
298 self.log_entries = self.timer.log_entries[:]
302 self["loglist"] = MenuList(self.list)
303 self["logentry"] = Label()
305 self["key_red"] = Button(_("Delete entry"))
306 self["key_green"] = Button()
307 self["key_yellow"] = Button("")
308 self["key_blue"] = Button(_("Clear log"))
310 self.onShown.append(self.updateText)
312 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
315 "cancel": self.keyClose,
320 "red": self.deleteEntry,
321 "blue": self.clearLog
324 def deleteEntry(self):
325 self.log_entries.remove(self["loglist"].getCurrent()[1])
327 self["loglist"].l.setList(self.list)
330 def fillLogList(self):
332 for x in self.log_entries:
333 self.list.append((str(strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x))
336 self.log_entries = []
338 self["loglist"].l.setList(self.list)
342 if self.timer.log_entries != self.log_entries:
343 self.timer.log_entries = self.log_entries
344 self.close((True, self.timer))
349 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
353 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
357 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
361 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
364 def updateText(self):
365 if len(self.list) > 0:
366 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
368 self["logentry"].setText("")