1 from Screen import Screen
2 import ChannelSelection
3 from ServiceReference import ServiceReference
4 from Components.config import ConfigSelection, ConfigText, ConfigSubList, ConfigSubsection, ConfigDateTime, ConfigClock, ConfigYesNo, getConfigListEntry
5 from Components.ActionMap import ActionMap, NumberActionMap
6 from Components.ConfigList import ConfigList, ConfigListScreen
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.MessageBox import MessageBox
13 from Screens.ChoiceBox import ChoiceBox
14 from RecordTimer import AFTEREVENT
15 from enigma import eEPGCache
19 class TimerEntry(Screen, ConfigListScreen):
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"],
35 "cancel": self.keyCancel,
39 ConfigListScreen.__init__(self, self.list, session = session)
40 self.createSetup("config")
42 def createConfig(self):
43 justplay = self.timer.justplay
45 afterevent = { AFTEREVENT.NONE: "nothing", AFTEREVENT.DEEPSTANDBY: "deepstandby", AFTEREVENT.STANDBY: "standby"}[self.timer.afterEvent]
47 weekday_table = ["mon", "tue", "wed", "thu", "fri", "sat", "sun"]
49 # calculate default values
54 if self.timer.repeated: # repeated
56 if (self.timer.repeated == 31): # Mon-Fri
58 elif (self.timer.repeated == 127): # daily
61 flags = self.timer.repeated
65 if flags == 1: # weekly
66 print "Set to weekday " + str(x)
68 if flags & 1 == 1: # set user defined flags
79 weekday = (int(time.strftime("%w", time.localtime(self.timer.begin))) - 1) % 7
82 self.timerentry_justplay = ConfigSelection(choices = [("zap", _("zap")), ("record", _("record"))], default = {0: "record", 1: "record"}[justplay])
83 self.timerentry_afterevent = ConfigSelection(choices = [("nothing", _("do nothing")), ("deepstandby", _("go to deep standby"))], default = afterevent)
84 self.timerentry_type = ConfigSelection(choices = [("once",_("once")), ("repeated", _("repeated"))], default = type)
85 self.timerentry_name = ConfigText(default = self.timer.name, fixed_size = False)
86 self.timerentry_description = ConfigText(default = self.timer.description, fixed_size = False)
88 self.timerentry_repeated = ConfigSelection(default = repeated, choices = [("daily", _("daily")), ("weekly", _("weekly")), ("weekdays", _("Mon-Fri")), ("user", _("user defined"))])
90 self.timerentry_startdate = ConfigDateTime(default = self.timer.begin, formatstring = _("%d.%B %Y"), increment = 86400)
91 self.timerentry_starttime = ConfigClock(default = [int(time.strftime("%H", time.localtime(self.timer.begin))), int(time.strftime("%M", time.localtime(self.timer.begin)))])
93 self.timerentry_enddate = ConfigDateTime(default = self.timer.end, formatstring = _("%d.%B %Y"), increment = 86400)
94 self.timerentry_endtime = ConfigClock(default = [int(time.strftime("%H", time.localtime(self.timer.end))), int(time.strftime("%M", time.localtime(self.timer.end)))])
96 self.timerentry_weekday = ConfigSelection(default = weekday_table[weekday], choices = [("mon",_("Monday")), ("tue", _("Tuesday")), ("wed",_("Wednesday")), ("thu", _("Thursday")), ("fri", _("Friday")), ("sat", _("Saturday")), ("sun", _("Sunday"))])
98 self.timerentry_day = ConfigSubList()
100 self.timerentry_day.append(ConfigYesNo(default = day[x]))
102 # FIXME some service-chooser needed here
104 try: # no current service available?
105 servicename = str(self.timer.service_ref.getServiceName())
108 self.timerentry_service = ConfigSelection([servicename])
110 self.timerentry_startdate.addNotifier(self.checkDate)
111 self.timerentry_enddate.addNotifier(self.checkDate)
113 def checkDate(self, configElement):
114 if configElement is self.timerentry_startdate:
115 if self.timerentry_enddate.value < self.timerentry_startdate.value:
116 self.timerentry_enddate.value = self.timerentry_startdate.value
117 self["config"].invalidate(self.timerentry_enddate)
118 if configElement is self.timerentry_enddate:
119 if (self.timerentry_enddate.value < self.timerentry_startdate.value):
120 self.timerentry_startdate.value = self.timerentry_enddate.value
121 self["config"].invalidate(self.timerentry_startdate)
123 def createSetup(self, widget):
125 self.list.append(getConfigListEntry(_("Name"), self.timerentry_name))
126 self.list.append(getConfigListEntry(_("Description"), self.timerentry_description))
127 self.timerJustplayEntry = getConfigListEntry(_("Timer Type"), self.timerentry_justplay)
128 self.list.append(self.timerJustplayEntry)
129 self.timerTypeEntry = getConfigListEntry(_("Repeat Type"), self.timerentry_type)
130 self.list.append(self.timerTypeEntry)
132 if self.timerentry_type.value == "once":
133 self.frequencyEntry = None
135 self.frequencyEntry = getConfigListEntry(_("Frequency"), self.timerentry_repeated)
136 self.list.append(self.frequencyEntry)
137 if self.timerentry_repeated.value == "daily":
139 if self.timerentry_repeated.value == "weekdays":
141 if self.timerentry_repeated.value == "weekly":
142 self.list.append(getConfigListEntry(_("Weekday"), self.timerentry_weekday))
144 if self.timerentry_repeated.value == "user":
145 self.list.append(getConfigListEntry(_("Monday"), self.timerentry_day[0]))
146 self.list.append(getConfigListEntry(_("Tuesday"), self.timerentry_day[1]))
147 self.list.append(getConfigListEntry(_("Wednesday"), self.timerentry_day[2]))
148 self.list.append(getConfigListEntry(_("Thursday"), self.timerentry_day[3]))
149 self.list.append(getConfigListEntry(_("Friday"), self.timerentry_day[4]))
150 self.list.append(getConfigListEntry(_("Saturday"), self.timerentry_day[5]))
151 self.list.append(getConfigListEntry(_("Sunday"), self.timerentry_day[6]))
153 #self.list.append(getConfigListEntry("StartDate", self.timerentry_startdate))
154 # self.list.append(getConfigListEntry("Weekday", self.timerentry_weekday))
156 if self.timerentry_type.value == "once":
157 self.list.append(getConfigListEntry(_("Start"), self.timerentry_startdate))
158 self.list.append(getConfigListEntry(" ", self.timerentry_starttime))
160 self.list.append(getConfigListEntry(_("StartTime"), self.timerentry_starttime))
162 if self.timerentry_type.value == "once":
163 if self.timerentry_justplay.value != "zap":
164 self.list.append(getConfigListEntry(_("End"), self.timerentry_enddate))
165 self.list.append(getConfigListEntry(" ", self.timerentry_endtime))
167 if self.timerentry_justplay.value != "zap":
168 self.list.append(getConfigListEntry(_("EndTime"), self.timerentry_endtime))
170 if self.timerentry_justplay.value != "zap":
171 self.list.append(getConfigListEntry(_("After event"), self.timerentry_afterevent))
173 self.channelEntry = getConfigListEntry(_("Channel"), self.timerentry_service)
174 self.list.append(self.channelEntry)
176 self[widget].list = self.list
177 self[widget].l.setList(self.list)
180 print "newConfig", self["config"].getCurrent()
181 if self["config"].getCurrent() == self.timerTypeEntry:
182 self.createSetup("config")
183 if self["config"].getCurrent() == self.timerJustplayEntry:
184 self.createSetup("config")
185 if self["config"].getCurrent() == self.frequencyEntry:
186 self.createSetup("config")
189 if self["config"].getCurrent() is self.channelEntry:
192 ConfigListScreen.keyLeft(self)
195 def keyRightCallback(self, configPath):
196 currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
197 # check if we are still on the same config entry
198 if (currentConfigPath == configPath):
202 if self["config"].getCurrent() is self.channelEntry:
205 ConfigListScreen.keyRight(self)
209 if self["config"].getCurrent() == self.channelEntry:
210 self.session.openWithCallback(self.finishedChannelSelection, ChannelSelection.SimpleChannelSelection, _("Select channel to record from"))
214 def finishedChannelSelection(self, *args):
216 self.timer.service_ref = ServiceReference(args[0])
217 self.timerentry_service.vals = (str(self.timer.service_ref.getServiceName()),)
218 self["config"].invalidate(self.timerentry_service)
220 def getTimestamp(self, date, mytime):
221 d = time.localtime(date)
222 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
223 return int(time.mktime(dt.timetuple()))
225 def getBeginEnd(self):
226 enddate = self.timerentry_enddate.value
227 endtime = self.timerentry_endtime.value
229 startdate = self.timerentry_startdate.value
230 starttime = self.timerentry_starttime.value
232 begin = self.getTimestamp(startdate, starttime)
233 end = self.getTimestamp(enddate, endtime)
235 # because of the dateChecks, startdate can't be < enddate.
236 # however, the endtime can be less than the starttime.
237 # in this case, add 1 day.
243 self.timer.name = self.timerentry_name.value
244 self.timer.description = self.timerentry_description.value
245 self.timer.justplay = self.timerentry_justplay.value == "zap"
246 self.timer.resetRepeated()
247 self.timer.afterEvent = {"nothing": AFTEREVENT.NONE, "deepstandby": AFTEREVENT.DEEPSTANDBY, "standby": AFTEREVENT.STANDBY}[self.timerentry_afterevent.value]
249 if self.timerentry_type.value == "once":
250 self.timer.begin, self.timer.end = self.getBeginEnd()
251 if self.timerentry_type.value == "repeated":
252 if self.timerentry_repeated.value == "daily":
254 self.timer.setRepeated(x)
256 if self.timerentry_repeated.value == "weekly":
257 self.timer.setRepeated(self.timerentry_weekday.index)
259 if self.timerentry_repeated.value == "weekdays":
261 self.timer.setRepeated(x)
263 if self.timerentry_repeated.value == "user":
265 if self.timerentry_day[x].value:
266 self.timer.setRepeated(x)
268 self.timer.begin = self.getTimestamp(time.time(), self.timerentry_starttime.value)
269 self.timer.end = self.getTimestamp(time.time(), self.timerentry_endtime.value)
271 # when a timer end is set before the start, add 1 day
272 if self.timer.end < self.timer.begin:
273 self.timer.end += 86400
275 if self.timer.eit is not None:
276 event = eEPGCache.getInstance().lookupEventId(self.timer.service_ref.ref, self.timer.eit)
277 if event is not None:
278 n = event.getNumOfLinkageServices()
281 ref = self.session.nav.getCurrentlyPlayingServiceReference()
282 parent = self.timer.service_ref.ref
285 i = event.getLinkageService(parent, x)
286 if i.toString() == ref.toString():
288 tlist.append((i.getName(), i))
289 self.session.openWithCallback(self.subserviceSelected, ChoiceBox, title=_("Please select a subservice to record..."), list = tlist, selection = selection)
291 self.close((True, self.timer))
293 def subserviceSelected(self, service):
294 if not service is None:
295 self.timer.service_ref = ServiceReference(service[1])
296 self.close((True, self.timer))
301 class TimerLog(Screen):
302 def __init__(self, session, timer):
303 Screen.__init__(self, session)
305 self.log_entries = self.timer.log_entries[:]
309 self["loglist"] = MenuList(self.list)
310 self["logentry"] = Label()
312 self["key_red"] = Button(_("Delete entry"))
313 self["key_green"] = Button()
314 self["key_yellow"] = Button("")
315 self["key_blue"] = Button(_("Clear log"))
317 self.onShown.append(self.updateText)
319 self["actions"] = NumberActionMap(["OkCancelActions", "DirectionActions", "ColorActions"],
322 "cancel": self.keyClose,
327 "red": self.deleteEntry,
328 "blue": self.clearLog
331 def deleteEntry(self):
332 self.log_entries.remove(self["loglist"].getCurrent()[1])
334 self["loglist"].l.setList(self.list)
337 def fillLogList(self):
339 for x in self.log_entries:
340 self.list.append((str(time.strftime("%Y-%m-%d %H-%M", localtime(x[0])) + " - " + x[2]), x))
343 self.log_entries = []
345 self["loglist"].l.setList(self.list)
349 if self.timer.log_entries != self.log_entries:
350 self.timer.log_entries = self.log_entries
351 self.close((True, self.timer))
356 self["loglist"].instance.moveSelection(self["loglist"].instance.moveUp)
360 self["loglist"].instance.moveSelection(self["loglist"].instance.moveDown)
364 self["loglist"].instance.moveSelection(self["loglist"].instance.pageUp)
368 self["loglist"].instance.moveSelection(self["loglist"].instance.pageDown)
371 def updateText(self):
372 if len(self.list) > 0:
373 self["logentry"].setText(str(self["loglist"].getCurrent()[1][2]))
375 self["logentry"].setText("")