volume-control:
[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.startdate = configElement_nonSave("config.timerentry.startdate", configDateTime, timer.begin, ("%d.%B %Y", 86400))
44             config.timerentry.starttime = configElement_nonSave("config.timerentry.starttime", configSequence, [int(strftime("%H", localtime(timer.begin))), int(strftime("%M", localtime(timer.begin)))], configsequencearg.get("CLOCK"))
45             #config.timerentry.starttime = configElement_nonSave("config.timerentry.starttime", configDateTime, timer.begin, ("%H:%M", 60))
46             config.timerentry.enddate = configElement_nonSave("config.timerentry.enddate", configDateTime, timer.end, ("%d.%B %Y", 86400))
47             config.timerentry.endtime = configElement_nonSave("config.timerentry.endtime", configSequence, [int(strftime("%H", localtime(timer.end))), int(strftime("%M", localtime(timer.end)))], configsequencearg.get("CLOCK"))
48 #            config.timerentry.endtime = configElement_nonSave("config.timerentry.endtime", configDateTime, timer.end, ("%H:%M", 60))            
49             #config.timerentry.weekday = configElement_nonSave("config.timerentry.weekday", configDateTime, time(), ("%A", 86400))
50
51     def createSetup(self):
52         self.list = []
53         self.list.append(getConfigListEntry("TimerType", config.timerentry.type))
54         
55         if (config.timerentry.type.value == 0):
56             self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
57             self.list.append(getConfigListEntry("StartTime", config.timerentry.starttime))
58             self.list.append(getConfigListEntry("EndDate", config.timerentry.enddate))
59             self.list.append(getConfigListEntry("EndTime", config.timerentry.endtime))
60         else:
61             pass
62             #self.list.append(getConfigListEntry("StartDate", config.timerentry.startdate))
63 #        self.list.append(getConfigListEntry("Weekday", config.timerentry.weekday))
64         
65         self["config"].list = self.list
66         self["config"].l.setList(self.list)
67         
68     def newConfig(self):
69         print self["config"].getCurrent()
70         if self["config"].getCurrent()[0] == "TimerType":
71             self.createSetup()
72         if self["config"].getCurrent()[0] == "Tuner":
73             self.createSetup()
74                     
75     def keyLeft(self):
76         self["config"].handleKey(config.key["prevElement"])
77         self.newConfig()
78
79     def keyRight(self):
80         self["config"].handleKey(config.key["nextElement"])
81         self.newConfig()
82
83     def keyNumberGlobal(self, number):
84         print "You pressed number " + str(number)
85         if (self["config"].getCurrent()[1].parent.enabled == True):
86             self["config"].handleKey(config.key[str(number)])
87
88     def keyGo(self):
89         for x in self["config"].list:
90             x[1].save()
91         self.session.openWithCallback(self.keyCancel, ServiceScan)        
92
93         #self.close()
94
95     def keyCancel(self):
96         for x in self["config"].list:
97             x[1].cancel()
98         self.close()