extended timerentry
[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             config.timerentry.repeated = configElement_nonSave("config.timerentry.repeated", configSelection, 0, ("daily", "weekly", "Mon-Fri", "user-defined"))
45             config.timerentry.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, timer.begin, ("%d.%B %Y", 86400))
46             config.timerentry.starttime = configElement_nonSave("config.timerentry.starttime", configSequence, [int(strftime("%H", localtime(timer.begin))), int(strftime("%M", localtime(timer.begin)))], configsequencearg.get("CLOCK"))
47             #config.timerentry.starttime = configElement_nonSave("config.timerentry.starttime", configDateTime, timer.begin, ("%H:%M", 60))
48             config.timerentry.enddate = configElement_nonSave("config.timerentry.enddate", configDateTime, timer.end, ("%d.%B %Y", 86400))
49             config.timerentry.endtime = configElement_nonSave("config.timerentry.endtime", configSequence, [int(strftime("%H", localtime(timer.end))), int(strftime("%M", localtime(timer.end)))], configsequencearg.get("CLOCK"))
50 #            config.timerentry.endtime = configElement_nonSave("config.timerentry.endtime", configDateTime, timer.end, ("%H:%M", 60))            
51             config.timerentry.weekday = configElement_nonSave("config.timerentry.weekday", configDateTime, time(), ("%A", 86400))
52             config.timerentry.monday = configElement_nonSave("config.timerentry.monday", configSelection, 0, ("yes", "no"))
53             config.timerentry.tuesday = configElement_nonSave("config.timerentry.tuesday", configSelection, 0, ("yes", "no"))
54             config.timerentry.wednesday = configElement_nonSave("config.timerentry.wednesday", configSelection, 0, ("yes", "no"))
55             config.timerentry.thursday = configElement_nonSave("config.timerentry.thursday", configSelection, 0, ("yes", "no"))
56             config.timerentry.friday = configElement_nonSave("config.timerentry.friday", configSelection, 0, ("yes", "no"))
57             config.timerentry.saturday = configElement_nonSave("config.timerentry.saturday", configSelection, 0, ("yes", "no"))
58             config.timerentry.sunday = configElement_nonSave("config.timerentry.sunday", configSelection, 0, ("yes", "no"))
59             
60     def createSetup(self):
61         self.list = []
62         self.list.append(getConfigListEntry("Description", config.timerentry.description))
63         self.list.append(getConfigListEntry("TimerType", config.timerentry.type))
64         
65         if (config.timerentry.type.value == 0): # once
66             pass
67         else: # repeated
68             self.list.append(getConfigListEntry("Frequency", config.timerentry.repeated))
69             if (config.timerentry.repeated.value == 0): # daily
70                 pass
71             if (config.timerentry.repeated.value == 2): # Mon-Fri
72                 pass
73             if (config.timerentry.repeated.value == 1): # weekly
74                 self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
75
76             if (config.timerentry.repeated.value == 3): # user-defined
77                 self.list.append(getConfigListEntry("Monday", config.timerentry.monday))
78                 self.list.append(getConfigListEntry("Tuesday", config.timerentry.tuesday))
79                 self.list.append(getConfigListEntry("Wednesday", config.timerentry.wednesday))
80                 self.list.append(getConfigListEntry("Thursday", config.timerentry.thursday))
81                 self.list.append(getConfigListEntry("Friday", config.timerentry.friday))
82                 self.list.append(getConfigListEntry("Saturday", config.timerentry.saturday))
83                 self.list.append(getConfigListEntry("Sunday", config.timerentry.sunday))
84                 
85             #self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
86 #        self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
87         
88         if (config.timerentry.type.value == 0): # once
89             self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
90         self.list.append(getConfigListEntry("StartTime", config.timerentry.starttime))
91         if (config.timerentry.type.value == 0): # once
92             self.list.append(getConfigListEntry("EndDate", config.timerentry.enddate))
93         self.list.append(getConfigListEntry("EndTime", config.timerentry.endtime))
94         
95         self["config"].list = self.list
96         self["config"].l.setList(self.list)
97         
98     def newConfig(self):
99         print self["config"].getCurrent()
100         if self["config"].getCurrent()[0] == "TimerType":
101             self.createSetup()
102         if self["config"].getCurrent()[0] == "Frequency":
103             self.createSetup()
104                     
105     def keyLeft(self):
106         self["config"].handleKey(config.key["prevElement"])
107         self.newConfig()
108
109     def keyRight(self):
110         self["config"].handleKey(config.key["nextElement"])
111         self.newConfig()
112
113     def keyNumberGlobal(self, number):
114         print "You pressed number " + str(number)
115         if (self["config"].getCurrent()[1].parent.enabled == True):
116             self["config"].handleKey(config.key[str(number)])
117
118     def keyGo(self):
119         for x in self["config"].list:
120             x[1].save()
121         self.session.openWithCallback(self.keyCancel, ServiceScan)        
122
123         #self.close()
124
125     def keyCancel(self):
126         for x in self["config"].list:
127             x[1].cancel()
128         self.close()