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):
235 oldref = self.timer.service_ref
237 self.timer.service_ref = ServiceReference(args)
238 config.timerentry.service.vals = (str(self.timer.service_ref.getServiceName()),)
239 self["config"].invalidate(config.timerentry.service)
241 print "you pressed cancel"
242 self.timer.service_ref = oldref
244 def keyNumberGlobal(self, number):
245 print "You pressed number " + str(number)
246 if (self["config"].getCurrent()[1].parent.enabled == True):
247 self["config"].handleKey(config.key[str(number)])
249 def getTimestamp(self, date, mytime):
250 d = time.localtime(date)
251 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
252 return int(mktime(dt.timetuple()))
255 self.timer.name = config.timerentry.name.value
256 self.timer.description = config.timerentry.description.value
257 self.timer.justplay = (currentConfigSelectionElement(config.timerentry.justplay) == "zap")
258 self.timer.resetRepeated()
260 if (config.timerentry.type.value == 0): # once
261 self.timer.begin = self.getTimestamp(config.timerentry.startdate.value, config.timerentry.starttime.value)
262 self.timer.end = self.getTimestamp(config.timerentry.enddate.value, config.timerentry.endtime.value)
263 if (config.timerentry.type.value == 1): # repeated
264 if (config.timerentry.repeated.value == 0): # daily
266 self.timer.setRepeated(x)
268 if (config.timerentry.repeated.value == 1): # weekly
269 self.timer.setRepeated(config.timerentry.weekday.value)
271 if (config.timerentry.repeated.value == 2): # Mon-Fri
273 self.timer.setRepeated(x)
275 if (config.timerentry.repeated.value == 3): # user defined
277 if (config.timerentry.day[x].value == 0): self.timer.setRepeated(x)
279 self.timer.begin = self.getTimestamp(time.time(), config.timerentry.starttime.value)
280 self.timer.end = self.getTimestamp(time.time(), config.timerentry.endtime.value)
282 if self.timer.eit is not None:
283 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
284 if event is not None:
285 if event.getNumOfLinkageServices() > 0:
286 self.session.openWithCallback(self.subserviceSelected, SubserviceSelection, event, self.timer.service_ref.ref)
288 self.close((True, self.timer))
290 def subserviceSelected(self, service):
291 if not service is None:
292 self.timer.service_ref = ServiceReference(service)
293 self.close((True, self.timer))
298 class TimerLog(Screen):
299 def __init__(self, session, timer):
300 Screen.__init__(self, session)
302 self.log_entries = self.timer.log_entries[:]
306 self["loglist"] = MenuList(self.list)
307 self["logentry"] = Label()
309 self["key_red"] = Button(_("Delete entry"))
310 self["key_green"] = Button()
311 self["key_yellow"] = Button("")
312 self["key_blue"] = Button(_("Clear log"))
314 self.onShown.append(self.updateText)
316 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
319 "cancel": self.keyClose,
324 "red": self.deleteEntry,
325 "blue": self.clearLog
328 def deleteEntry(self):
329 self.log_entries.remove(self["loglist"].getCurrent()[1])
331 self["loglist"].l.setList(self.list)
334 def fillLogList(self):
336 for x in self.log_entries:
337 self.list.append((str(strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x))
340 self.log_entries = []
342 self["loglist"].l.setList(self.list)
346 if self.timer.log_entries != self.log_entries:
347 self.timer.log_entries = self.log_entries
348 self.close((True, self.timer))
353 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
357 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
361 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
365 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
368 def updateText(self):
369 if len(self.list) > 0:
370 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
372 self["logentry"].setText("")