1 from Screen import Screen
2 import ChannelSelection
3 from ServiceReference import ServiceReference
4 from Components.config import *
5 from Components.ActionMap import NumberActionMap
6 from Components.ConfigList import ConfigList
7 from Components.NimManager import nimmanager
8 from Components.Label import Label
12 class TimerEntry(Screen):
13 def __init__(self, session, timer):
14 Screen.__init__(self, session)
17 self["ok"] = Label("OK")
18 self["cancel"] = Label("Cancel")
22 self["actions"] = NumberActionMap(["SetupActions", "TextEntryActions"],
26 "cancel": self.keyCancel,
28 "right": self.keyRight,
29 "delete": self.keyDelete,
30 "1": self.keyNumberGlobal,
31 "2": self.keyNumberGlobal,
32 "3": self.keyNumberGlobal,
33 "4": self.keyNumberGlobal,
34 "5": self.keyNumberGlobal,
35 "6": self.keyNumberGlobal,
36 "7": self.keyNumberGlobal,
37 "8": self.keyNumberGlobal,
38 "9": self.keyNumberGlobal,
39 "0": self.keyNumberGlobal
43 self["config"] = ConfigList(self.list)
46 def createConfig(self):
47 config.timerentry = ConfigSubsection()
49 # calculate default values
54 if (self.timer.repeated != 0): # repeated
56 if (self.timer.repeated == 31): # Mon-Fri
57 repeated = 2 # Mon - Fri
58 elif (self.timer.repeated == 127): # daily
61 flags = self.timer.repeated
62 repeated = 3 # user-defined
65 if (flags == 1): # weekly
66 print "Set to weekday " + str(x)
68 if (flags & 1 == 1): # set user-defined flags
80 config.timerentry.type = configElement_nonSave("config.timerentry.type", configSelection, type, (_("once"), _("repeated")))
81 config.timerentry.description = configElement_nonSave("config.timerentry.description", configText, self.timer.description, (configText.extendableSize, self.keyRightCallback))
83 config.timerentry.repeated = configElement_nonSave("config.timerentry.repeated", configSelection, repeated, (_("daily"), _("weekly"), _("Mon-Fri"), _("user-defined")))
85 config.timerentry.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, self.timer.begin, (_("%d.%B %Y"), 86400))
86 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"))
88 config.timerentry.enddate = configElement_nonSave("config.timerentry.enddate", configDateTime, self.timer.end, (_("%d.%B %Y"), 86400))
89 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"))
91 config.timerentry.weekday = configElement_nonSave("config.timerentry.weekday", configSelection, weekday, (_("Monday"), _("Tuesday"), _("Wednesday"), _("Thursday"), _("Friday"), _("Saturday"), _("Sunday")))
93 config.timerentry.day = []
95 config.timerentry.day.append(configElement_nonSave("config.timerentry.day[" + str(x) + "]", configSelection, day[x], (_("yes"), _("no"))))
98 # FIXME some service-chooser needed here
100 try: # no current service available?
101 servicename = str(self.timer.service_ref.getServiceName())
104 config.timerentry.service = configElement_nonSave("config.timerentry.service", configSelection, 0, ((servicename),))
106 config.timerentry.startdate.addNotifier(self.checkDate)
107 config.timerentry.enddate.addNotifier(self.checkDate)
109 def checkDate(self, configElement):
110 if (configElement.getConfigPath() == "config.timerentry.startdate"):
111 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
112 config.timerentry.enddate.value = config.timerentry.startdate.value
113 config.timerentry.enddate.change()
115 self["config"].invalidate(config.timerentry.enddate)
118 if (configElement.getConfigPath() == "config.timerentry.enddate"):
119 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
120 config.timerentry.startdate.value = config.timerentry.enddate.value
121 config.timerentry.startdate.change()
123 self["config"].invalidate(config.timerentry.startdate)
127 def createSetup(self):
129 self.list.append(getConfigListEntry(_("Description"), config.timerentry.description))
130 self.list.append(getConfigListEntry(_("TimerType"), config.timerentry.type))
132 if (config.timerentry.type.value == 0): # once
135 self.list.append(getConfigListEntry(_("Frequency"), config.timerentry.repeated))
136 if (config.timerentry.repeated.value == 0): # daily
138 if (config.timerentry.repeated.value == 2): # Mon-Fri
140 if (config.timerentry.repeated.value == 1): # weekly
141 self.list.append(getConfigListEntry(_("Weekday"), config.timerentry.weekday))
143 if (config.timerentry.repeated.value == 3): # user-defined
144 self.list.append(getConfigListEntry(_("Monday"), config.timerentry.day[0]))
145 self.list.append(getConfigListEntry(_("Tuesday"), config.timerentry.day[1]))
146 self.list.append(getConfigListEntry(_("Wednesday"), config.timerentry.day[2]))
147 self.list.append(getConfigListEntry(_("Thursday"), config.timerentry.day[3]))
148 self.list.append(getConfigListEntry(_("Friday"), config.timerentry.day[4]))
149 self.list.append(getConfigListEntry(_("Saturday"), config.timerentry.day[5]))
150 self.list.append(getConfigListEntry(_("Sunday"), config.timerentry.day[6]))
152 #self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
153 # self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
155 if (config.timerentry.type.value == 0): # once
156 self.list.append(getConfigListEntry(_("Start"), config.timerentry.startdate))
157 self.list.append(getConfigListEntry("", config.timerentry.starttime))
159 self.list.append(getConfigListEntry(_("StartTime"), config.timerentry.starttime))
160 if (config.timerentry.type.value == 0): # once
161 self.list.append(getConfigListEntry(_("End"), config.timerentry.enddate))
162 self.list.append(getConfigListEntry("", config.timerentry.endtime))
164 self.list.append(getConfigListEntry(_("EndTime"), config.timerentry.endtime))
166 self.list.append(getConfigListEntry(_("Channel"), config.timerentry.service))
168 self["config"].list = self.list
169 self["config"].l.setList(self.list)
172 print self["config"].getCurrent()
173 if self["config"].getCurrent()[0] == _("TimerType"):
175 if self["config"].getCurrent()[0] == _("Frequency"):
179 if self["config"].getCurrent()[0] == _("Channel"):
182 self["config"].handleKey(config.key["prevElement"])
186 self["config"].handleKey(config.key["delete"])
188 def keyRightCallback(self, configPath):
189 currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
190 # check if we are still on the same config entry
191 if (currentConfigPath == configPath):
195 if self["config"].getCurrent()[0] == _("Channel"):
198 self["config"].handleKey(config.key["nextElement"])
202 if self["config"].getCurrent()[0] == _("Channel"):
203 self.session.openWithCallback(self.finishedChannelSelection, ChannelSelection.SimpleChannelSelection, _("Select channel to record from"))
205 def finishedChannelSelection(self, args):
206 oldref = self.timer.service_ref
208 self.timer.service_ref = ServiceReference(args)
209 config.timerentry.service.vals = (str(self.timer.service_ref.getServiceName()),)
210 self["config"].invalidate(config.timerentry.service)
212 print "you pressed cancel"
213 self.timer.service_ref = oldref
215 def keyNumberGlobal(self, number):
216 print "You pressed number " + str(number)
217 if (self["config"].getCurrent()[1].parent.enabled == True):
218 self["config"].handleKey(config.key[str(number)])
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])
224 return int(mktime(dt.timetuple()))
227 self.timer.description = config.timerentry.description.value
228 self.timer.resetRepeated()
230 if (config.timerentry.type.value == 0): # once
231 self.timer.begin = self.getTimestamp(config.timerentry.startdate.value, config.timerentry.starttime.value)
232 self.timer.end = self.getTimestamp(config.timerentry.enddate.value, config.timerentry.endtime.value)
233 if (config.timerentry.type.value == 1): # repeated
234 if (config.timerentry.repeated.value == 0): # daily
236 self.timer.setRepeated(x)
238 if (config.timerentry.repeated.value == 1): # weekly
239 self.timer.setRepeated(config.timerentry.weekday.value)
241 if (config.timerentry.repeated.value == 2): # Mon-Fri
243 self.timer.setRepeated(x)
245 if (config.timerentry.repeated.value == 3): # user-defined
247 if (config.timerentry.day[x].value == 0): self.timer.setRepeated(x)
249 self.timer.begin = self.getTimestamp(time.time(), config.timerentry.starttime.value)
250 self.timer.end = self.getTimestamp(time.time(), config.timerentry.endtime.value)
252 self.close((True, self.timer))