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 # calculate default values
62 if (self.timer.repeated != 0): # repeated
64 if (self.timer.repeated == 31): # Mon-Fri
65 repeated = 2 # Mon - Fri
66 elif (self.timer.repeated == 127): # daily
69 flags = self.timer.repeated
70 repeated = 3 # user defined
73 if (flags == 1): # weekly
74 print "Set to weekday " + str(x)
76 if (flags & 1 == 1): # set user defined flags
87 weekday = (int(strftime("%w", time.localtime(self.timer.begin))) - 1) % 7
90 config.timerentry.type = configElement_nonSave("config.timerentry.type", configSelection, type, (_("once"), _("repeated")))
91 config.timerentry.name = configElement_nonSave("config.timerentry.name", configText, self.timer.name, (configText.extendableSize, self.keyRightCallback))
92 config.timerentry.description = configElement_nonSave("config.timerentry.description", configText, self.timer.description, (configText.extendableSize, self.keyRightCallback))
94 config.timerentry.repeated = configElement_nonSave("config.timerentry.repeated", configSelection, repeated, (_("daily"), _("weekly"), _("Mon-Fri"), _("user defined")))
96 config.timerentry.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, self.timer.begin, (_("%d.%B %Y"), 86400))
97 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"))
99 config.timerentry.enddate = configElement_nonSave("config.timerentry.enddate", configDateTime, self.timer.end, (_("%d.%B %Y"), 86400))
100 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"))
102 config.timerentry.weekday = configElement_nonSave("config.timerentry.weekday", configSelection, weekday, (_("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"), _("Sunday")))
104 config.timerentry.day = []
106 config.timerentry.day.append(configElement_nonSave("config.timerentry.day[" + str(x) + "]", configSelection, day[x], (_("yes"), _("no"))))
109 # FIXME some service-chooser needed here
111 try: # no current service available?
112 servicename = str(self.timer.service_ref.getServiceName())
115 config.timerentry.service = configElement_nonSave("config.timerentry.service", configSelection, 0, ((servicename),))
117 config.timerentry.startdate.addNotifier(self.checkDate)
118 config.timerentry.enddate.addNotifier(self.checkDate)
120 def checkDate(self, configElement):
121 if (configElement.getConfigPath() == "config.timerentry.startdate"):
122 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
123 config.timerentry.enddate.value = config.timerentry.startdate.value
124 config.timerentry.enddate.change()
126 self["config"].invalidate(config.timerentry.enddate)
129 if (configElement.getConfigPath() == "config.timerentry.enddate"):
130 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
131 config.timerentry.startdate.value = config.timerentry.enddate.value
132 config.timerentry.startdate.change()
134 self["config"].invalidate(config.timerentry.startdate)
138 def createSetup(self, widget):
140 self.list.append(getConfigListEntry(_("Name"), config.timerentry.name))
141 self.list.append(getConfigListEntry(_("Description"), config.timerentry.description))
142 self.timerTypeEntry = getConfigListEntry(_("Timer Type"), config.timerentry.type)
143 self.list.append(self.timerTypeEntry)
145 if (config.timerentry.type.value == 0): # once
146 self.frequencyEntry = None
148 self.frequencyEntry = getConfigListEntry(_("Frequency"), config.timerentry.repeated)
149 self.list.append(self.frequencyEntry)
150 if (config.timerentry.repeated.value == 0): # daily
152 if (config.timerentry.repeated.value == 2): # Mon-Fri
154 if (config.timerentry.repeated.value == 1): # weekly
155 self.list.append(getConfigListEntry(_("Weekday"), config.timerentry.weekday))
157 if (config.timerentry.repeated.value == 3): # user defined
158 self.list.append(getConfigListEntry(_("Monday"), config.timerentry.day[0]))
159 self.list.append(getConfigListEntry(_("Tuesday"), config.timerentry.day[1]))
160 self.list.append(getConfigListEntry(_("Wednesday"), config.timerentry.day[2]))
161 self.list.append(getConfigListEntry(_("Thursday"), config.timerentry.day[3]))
162 self.list.append(getConfigListEntry(_("Friday"), config.timerentry.day[4]))
163 self.list.append(getConfigListEntry(_("Saturday"), config.timerentry.day[5]))
164 self.list.append(getConfigListEntry(_("Sunday"), config.timerentry.day[6]))
166 #self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
167 # self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
169 if (config.timerentry.type.value == 0): # once
170 self.list.append(getConfigListEntry(_("Start"), config.timerentry.startdate))
171 self.list.append(getConfigListEntry(" ", config.timerentry.starttime))
173 self.list.append(getConfigListEntry(_("StartTime"), config.timerentry.starttime))
174 if (config.timerentry.type.value == 0): # once
175 self.list.append(getConfigListEntry(_("End"), config.timerentry.enddate))
176 self.list.append(getConfigListEntry(" ", config.timerentry.endtime))
178 self.list.append(getConfigListEntry(_("EndTime"), config.timerentry.endtime))
180 self.channelEntry = getConfigListEntry(_("Channel"), config.timerentry.service)
181 self.list.append(self.channelEntry)
183 self[widget].list = self.list
184 self[widget].l.setList(self.list)
187 print "newConfig", self["config"].getCurrent()
188 if self["config"].getCurrent() == self.timerTypeEntry:
189 self.createSetup("config")
190 if self["config"].getCurrent() == self.frequencyEntry:
191 self.createSetup("config")
194 if self["config"].getCurrent() == self.channelEntry:
197 self["config"].handleKey(config.key["prevElement"])
201 self["config"].handleKey(config.key["delete"])
203 def keyRightCallback(self, configPath):
204 currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
205 # check if we are still on the same config entry
206 if (currentConfigPath == configPath):
210 if self["config"].getCurrent() == self.channelEntry:
213 self["config"].handleKey(config.key["nextElement"])
217 if self["config"].getCurrent() == self.channelEntry:
218 self.session.openWithCallback(self.finishedChannelSelection, ChannelSelection.SimpleChannelSelection, _("Select channel to record from"))
222 def finishedChannelSelection(self, args):
223 oldref = self.timer.service_ref
225 self.timer.service_ref = ServiceReference(args)
226 config.timerentry.service.vals = (str(self.timer.service_ref.getServiceName()),)
227 self["config"].invalidate(config.timerentry.service)
229 print "you pressed cancel"
230 self.timer.service_ref = oldref
232 def keyNumberGlobal(self, number):
233 print "You pressed number " + str(number)
234 if (self["config"].getCurrent()[1].parent.enabled == True):
235 self["config"].handleKey(config.key[str(number)])
237 def getTimestamp(self, date, mytime):
238 d = time.localtime(date)
239 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
240 return int(mktime(dt.timetuple()))
243 self.timer.name = config.timerentry.name.value
244 self.timer.description = config.timerentry.description.value
245 self.timer.resetRepeated()
247 if (config.timerentry.type.value == 0): # once
248 self.timer.begin = self.getTimestamp(config.timerentry.startdate.value, config.timerentry.starttime.value)
249 self.timer.end = self.getTimestamp(config.timerentry.enddate.value, config.timerentry.endtime.value)
250 if (config.timerentry.type.value == 1): # repeated
251 if (config.timerentry.repeated.value == 0): # daily
253 self.timer.setRepeated(x)
255 if (config.timerentry.repeated.value == 1): # weekly
256 self.timer.setRepeated(config.timerentry.weekday.value)
258 if (config.timerentry.repeated.value == 2): # Mon-Fri
260 self.timer.setRepeated(x)
262 if (config.timerentry.repeated.value == 3): # user defined
264 if (config.timerentry.day[x].value == 0): self.timer.setRepeated(x)
266 self.timer.begin = self.getTimestamp(time.time(), config.timerentry.starttime.value)
267 self.timer.end = self.getTimestamp(time.time(), config.timerentry.endtime.value)
269 if self.timer.eit is not None:
270 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
271 if event is not None:
272 if event.getNumOfLinkageServices() > 0:
273 self.session.openWithCallback(self.subserviceSelected, SubserviceSelection, event, self.timer.service_ref.ref)
275 self.close((True, self.timer))
277 def subserviceSelected(self, service):
278 if not service is None:
279 self.timer.service_ref = ServiceReference(service)
280 self.close((True, self.timer))
285 class TimerLog(Screen):
286 def __init__(self, session, timer):
287 Screen.__init__(self, session)
289 self.log_entries = self.timer.log_entries[:]
293 self["loglist"] = MenuList(self.list)
294 self["logentry"] = Label()
296 self["key_red"] = Button(_("Delete entry"))
297 self["key_green"] = Button()
298 self["key_yellow"] = Button("")
299 self["key_blue"] = Button(_("Clear log"))
301 self.onShown.append(self.updateText)
303 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
306 "cancel": self.keyClose,
311 "red": self.deleteEntry,
312 "blue": self.clearLog
315 def deleteEntry(self):
316 self.log_entries.remove(self["loglist"].getCurrent()[1])
318 self["loglist"].l.setList(self.list)
321 def fillLogList(self):
323 for x in self.log_entries:
324 self.list.append((str(strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x))
327 self.log_entries = []
329 self["loglist"].l.setList(self.list)
333 if self.timer.log_entries != self.log_entries:
334 self.timer.log_entries = self.log_entries
335 self.close((True, self.timer))
340 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
344 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
348 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
352 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
355 def updateText(self):
356 if len(self.list) > 0:
357 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
359 self["logentry"].setText("")