1 from Screen import Screen
2 from Components.config import *
3 from Components.ActionMap import NumberActionMap
4 from Components.ConfigList import ConfigList
5 from Components.NimManager import nimmanager
6 from Components.Label import Label
11 class TimerEntry(Screen):
12 def __init__(self, session, timer):
13 Screen.__init__(self, session)
18 self["actions"] = NumberActionMap(["SetupActions"],
21 "cancel": self.keyCancel,
23 "right": self.keyRight,
24 "1": self.keyNumberGlobal,
25 "2": self.keyNumberGlobal,
26 "3": self.keyNumberGlobal,
27 "4": self.keyNumberGlobal,
28 "5": self.keyNumberGlobal,
29 "6": self.keyNumberGlobal,
30 "7": self.keyNumberGlobal,
31 "8": self.keyNumberGlobal,
32 "9": self.keyNumberGlobal,
33 "0": self.keyNumberGlobal
37 self["config"] = ConfigList(self.list)
40 def createConfig(self):
41 config.timerentry = ConfigSubsection()
43 # calculate default values
48 if (self.timer.repeated != 0): # repeated
50 if (self.timer.repeated == 31): # Mon-Fri
51 repeated = 2 # Mon - Fri
52 elif (self.timer.repeated == 127): # daily
55 flags = self.timer.repeated
56 repeated = 3 # user-defined
59 if (flags == 1): # weekly
60 print "Set to weekday " + str(x)
62 if (flags & 1 == 1): # set user-defined flags
74 config.timerentry.type = configElement_nonSave("config.timerentry.type", configSelection, type, ("once", "repeated"))
75 config.timerentry.description = configElement_nonSave("config.timerentry.description", configText, self.timer.description, (configText.extendableSize, self.keyRightCallback))
77 config.timerentry.repeated = configElement_nonSave("config.timerentry.repeated", configSelection, repeated, ("daily", "weekly", "Mon-Fri", "user-defined"))
79 config.timerentry.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, self.timer.begin, ("%d.%B %Y", 86400))
80 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"))
82 config.timerentry.enddate = configElement_nonSave("config.timerentry.enddate", configDateTime, self.timer.end, ("%d.%B %Y", 86400))
83 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"))
85 config.timerentry.weekday = configElement_nonSave("config.timerentry.weekday", configSelection, weekday, ("Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"))
87 config.timerentry.day = []
89 config.timerentry.day.append(configElement_nonSave("config.timerentry.day[" + str(x) + "]", configSelection, day[x], ("yes", "no")))
92 # FIXME some service-chooser needed here
93 config.timerentry.service = configElement_nonSave("config.timerentry.service", configSelection, 0, ((str(self.timer.service_ref.getServiceName())),))
95 config.timerentry.startdate.addNotifier(self.checkDate)
96 config.timerentry.enddate.addNotifier(self.checkDate)
98 def checkDate(self, configElement):
99 if (configElement.getConfigPath() == "config.timerentry.startdate"):
100 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
101 config.timerentry.enddate.value = config.timerentry.startdate.value
102 config.timerentry.enddate.change()
103 self["config"].invalidate(config.timerentry.enddate)
104 if (configElement.getConfigPath() == "config.timerentry.enddate"):
105 if (config.timerentry.enddate.value < config.timerentry.startdate.value):
106 config.timerentry.startdate.value = config.timerentry.enddate.value
107 config.timerentry.startdate.change()
108 self["config"].invalidate(config.timerentry.startdate)
110 def createSetup(self):
112 self.list.append(getConfigListEntry("Description", config.timerentry.description))
113 self.list.append(getConfigListEntry("TimerType", config.timerentry.type))
115 if (config.timerentry.type.value == 0): # once
118 self.list.append(getConfigListEntry("Frequency", config.timerentry.repeated))
119 if (config.timerentry.repeated.value == 0): # daily
121 if (config.timerentry.repeated.value == 2): # Mon-Fri
123 if (config.timerentry.repeated.value == 1): # weekly
124 self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
126 if (config.timerentry.repeated.value == 3): # user-defined
127 self.list.append(getConfigListEntry("Monday", config.timerentry.day[0]))
128 self.list.append(getConfigListEntry("Tuesday", config.timerentry.day[1]))
129 self.list.append(getConfigListEntry("Wednesday", config.timerentry.day[2]))
130 self.list.append(getConfigListEntry("Thursday", config.timerentry.day[3]))
131 self.list.append(getConfigListEntry("Friday", config.timerentry.day[4]))
132 self.list.append(getConfigListEntry("Saturday", config.timerentry.day[5]))
133 self.list.append(getConfigListEntry("Sunday", config.timerentry.day[6]))
135 #self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
136 # self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
138 if (config.timerentry.type.value == 0): # once
139 self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
140 self.list.append(getConfigListEntry("StartTime", config.timerentry.starttime))
141 if (config.timerentry.type.value == 0): # once
142 self.list.append(getConfigListEntry("EndDate", config.timerentry.enddate))
143 self.list.append(getConfigListEntry("EndTime", config.timerentry.endtime))
145 self.list.append(getConfigListEntry("Channel", config.timerentry.service))
147 self["config"].list = self.list
148 self["config"].l.setList(self.list)
151 print self["config"].getCurrent()
152 if self["config"].getCurrent()[0] == "TimerType":
154 if self["config"].getCurrent()[0] == "Frequency":
158 self["config"].handleKey(config.key["prevElement"])
161 def keyRightCallback(self, configPath):
162 currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
163 # check if we are still on the same config entry
164 if (currentConfigPath == configPath):
168 self["config"].handleKey(config.key["nextElement"])
171 def keyNumberGlobal(self, number):
172 print "You pressed number " + str(number)
173 if (self["config"].getCurrent()[1].parent.enabled == True):
174 self["config"].handleKey(config.key[str(number)])
176 def getTimestamp(self, date, mytime):
177 d = time.localtime(date)
178 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
180 return int(mktime(dt.timetuple()))
183 self.timer.resetRepeated()
185 if (config.timerentry.type.value == 0): # once
186 self.timer.begin = self.getTimestamp(config.timerentry.startdate.value, config.timerentry.starttime.value)
187 self.timer.end = self.getTimestamp(config.timerentry.enddate.value, config.timerentry.endtime.value)
188 if (config.timerentry.type.value == 1): # repeated
189 if (config.timerentry.repeated.value == 0): # daily
191 self.timer.setRepeated(x)
193 if (config.timerentry.repeated.value == 1): # weekly
194 self.timer.setRepeated(config.timerentry.weekday.value)
196 if (config.timerentry.repeated.value == 2): # Mon-Fri
198 self.timer.setRepeated(x)
200 if (config.timerentry.repeated.value == 3): # user-defined
202 if (config.timerentry.day[x].value == 0): self.timer.setRepeated(x)
204 self.timer.begin = self.getTimestamp(time.time(), config.timerentry.starttime.value)
205 self.timer.end = self.getTimestamp(time.time(), config.timerentry.endtime.value)
207 self.close((True, self.timer))