c7ea0cf66778fea40f374dff4b8eeb53382d86ca
[enigma2.git] / lib / python / Screens / TimerEntry.py
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
7 from time import *
8
9 class TimerEntry(Screen):
10     def __init__(self, session, timer):
11         Screen.__init__(self, session)
12         
13         self.createConfig(timer)
14         
15         self["actions"] = NumberActionMap(["SetupActions"],
16         {
17             "ok": self.keyGo,
18             "cancel": self.keyCancel,
19             "left": self.keyLeft,
20             "right": self.keyRight,
21             "1": self.keyNumberGlobal,
22             "2": self.keyNumberGlobal,
23             "3": self.keyNumberGlobal,
24             "4": self.keyNumberGlobal,
25             "5": self.keyNumberGlobal,
26             "6": self.keyNumberGlobal,
27             "7": self.keyNumberGlobal,
28             "8": self.keyNumberGlobal,
29             "9": self.keyNumberGlobal,
30             "0": self.keyNumberGlobal
31         }, -1)
32                 
33         self.list = []
34         self["config"] = ConfigList(self.list)
35         self.createSetup()
36
37         self["introduction"] = Label("Press OK to start the scan")
38
39     def createConfig(self, timer):
40             config.timerentry = ConfigSubsection()
41
42             config.timerentry.type = configElement_nonSave("config.timerentry.type", configSelection, 0, ("once", "repeated"))
43             config.timerentry.description = configElement_nonSave("config.timerentry.description", configText, timer.description, (configText.extendableSize,))
44
45             config.timerentry.repeated = configElement_nonSave("config.timerentry.repeated", configSelection, 0, ("daily", "weekly", "Mon-Fri", "user-defined"))
46
47             config.timerentry.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, timer.begin, ("%d.%B %Y", 86400))
48             config.timerentry.starttime = configElement_nonSave("config.timerentry.starttime", configSequence, [int(strftime("%H", localtime(timer.begin))), int(strftime("%M", localtime(timer.begin)))], configsequencearg.get("CLOCK"))
49
50             config.timerentry.enddate = configElement_nonSave("config.timerentry.enddate", configDateTime, timer.end, ("%d.%B %Y", 86400))
51             config.timerentry.endtime = configElement_nonSave("config.timerentry.endtime", configSequence, [int(strftime("%H", localtime(timer.end))), int(strftime("%M", localtime(timer.end)))], configsequencearg.get("CLOCK"))
52             
53             config.timerentry.weekday = configElement_nonSave("config.timerentry.weekday", configDateTime, time(), ("%A", 86400))
54             
55             config.timerentry.monday = configElement_nonSave("config.timerentry.monday", configSelection, 0, ("yes", "no"))
56             config.timerentry.tuesday = configElement_nonSave("config.timerentry.tuesday", configSelection, 0, ("yes", "no"))
57             config.timerentry.wednesday = configElement_nonSave("config.timerentry.wednesday", configSelection, 0, ("yes", "no"))
58             config.timerentry.thursday = configElement_nonSave("config.timerentry.thursday", configSelection, 0, ("yes", "no"))
59             config.timerentry.friday = configElement_nonSave("config.timerentry.friday", configSelection, 0, ("yes", "no"))
60             config.timerentry.saturday = configElement_nonSave("config.timerentry.saturday", configSelection, 0, ("yes", "no"))
61             config.timerentry.sunday = configElement_nonSave("config.timerentry.sunday", configSelection, 0, ("yes", "no"))
62             
63             # FIXME some service-chooser needed here
64             config.timerentry.service = configElement_nonSave("config.timerentry.service", configSelection, 0, ((str(timer.service_ref.getServiceName())),))
65             
66     def createSetup(self):
67         self.list = []
68         self.list.append(getConfigListEntry("Description", config.timerentry.description))
69         self.list.append(getConfigListEntry("TimerType", config.timerentry.type))
70         
71         if (config.timerentry.type.value == 0): # once
72             pass
73         else: # repeated
74             self.list.append(getConfigListEntry("Frequency", config.timerentry.repeated))
75             if (config.timerentry.repeated.value == 0): # daily
76                 pass
77             if (config.timerentry.repeated.value == 2): # Mon-Fri
78                 pass
79             if (config.timerentry.repeated.value == 1): # weekly
80                 self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
81
82             if (config.timerentry.repeated.value == 3): # user-defined
83                 self.list.append(getConfigListEntry("Monday", config.timerentry.monday))
84                 self.list.append(getConfigListEntry("Tuesday", config.timerentry.tuesday))
85                 self.list.append(getConfigListEntry("Wednesday", config.timerentry.wednesday))
86                 self.list.append(getConfigListEntry("Thursday", config.timerentry.thursday))
87                 self.list.append(getConfigListEntry("Friday", config.timerentry.friday))
88                 self.list.append(getConfigListEntry("Saturday", config.timerentry.saturday))
89                 self.list.append(getConfigListEntry("Sunday", config.timerentry.sunday))
90                 
91             #self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
92 #        self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
93         
94         if (config.timerentry.type.value == 0): # once
95             self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
96         self.list.append(getConfigListEntry("StartTime", config.timerentry.starttime))
97         if (config.timerentry.type.value == 0): # once
98             self.list.append(getConfigListEntry("EndDate", config.timerentry.enddate))
99         self.list.append(getConfigListEntry("EndTime", config.timerentry.endtime))
100         
101         self.list.append(getConfigListEntry("Channel", config.timerentry.service))        
102         
103         self["config"].list = self.list
104         self["config"].l.setList(self.list)
105         
106     def newConfig(self):
107         print self["config"].getCurrent()
108         if self["config"].getCurrent()[0] == "TimerType":
109             self.createSetup()
110         if self["config"].getCurrent()[0] == "Frequency":
111             self.createSetup()
112                     
113     def keyLeft(self):
114         self["config"].handleKey(config.key["prevElement"])
115         self.newConfig()
116
117     def keyRight(self):
118         self["config"].handleKey(config.key["nextElement"])
119         self.newConfig()
120
121     def keyNumberGlobal(self, number):
122         print "You pressed number " + str(number)
123         if (self["config"].getCurrent()[1].parent.enabled == True):
124             self["config"].handleKey(config.key[str(number)])
125
126     def keyGo(self):
127         for x in self["config"].list:
128             x[1].save()
129         self.session.openWithCallback(self.keyCancel, ServiceScan)        
130
131         #self.close()
132
133     def keyCancel(self):
134         for x in self["config"].list:
135             x[1].cancel()
136         self.close()