Screens/TimerEdit.py: fix timerlist sort function (no more move disabled timers to...
[enigma2.git] / lib / python / Screens / TimeDateInput.py
1 from Screen import Screen
2 from Components.config import ConfigClock, ConfigDateTime, getConfigListEntry
3 from Components.ActionMap import NumberActionMap
4 from Components.ConfigList import ConfigListScreen
5 from Components.Label import Label
6 from Components.Pixmap import Pixmap
7 import time
8 import datetime
9
10 class TimeDateInput(Screen, ConfigListScreen):
11         def __init__(self, session, config_time=None, config_date=None):
12                 Screen.__init__(self, session)
13                 self["oktext"] = Label(_("OK"))
14                 self["canceltext"] = Label(_("Cancel"))
15                 self["ok"] = Pixmap()
16                 self["cancel"] = Pixmap()
17
18                 self.createConfig(config_date, config_time)
19
20                 self["actions"] = NumberActionMap(["SetupActions"],
21                 {
22                         "ok": self.keySelect,
23                         "save": self.keyGo,
24                         "cancel": self.keyCancel,
25                 }, -2)
26
27                 self.list = []
28                 ConfigListScreen.__init__(self, self.list)
29                 self.createSetup(self["config"])
30
31         def createConfig(self, conf_date, conf_time):
32                 self.save_mask = 0
33                 if conf_time:
34                         self.save_mask |= 1
35                 else:
36                         conf_time = ConfigClock(default = time.time()),
37                 if conf_date:
38                         self.save_mask |= 2
39                 else:
40                         conf_date = ConfigDateTime(default = time.time(), formatstring = _("%d.%B %Y"), increment = 86400)
41                 self.timeinput_date = conf_date
42                 self.timeinput_time = conf_time
43
44         def createSetup(self, configlist):
45                 self.list = [
46                         getConfigListEntry(_("Date"), self.timeinput_date),
47                         getConfigListEntry(_("Time"), self.timeinput_time)
48                 ]
49                 configlist.list = self.list
50                 configlist.l.setList(self.list)
51
52         def keySelect(self):
53                 self.keyGo()
54
55         def getTimestamp(self, date, mytime):
56                 d = time.localtime(date)
57                 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
58                 return int(time.mktime(dt.timetuple()))
59
60         def keyGo(self):
61                 time = self.getTimestamp(self.timeinput_date.value, self.timeinput_time.value)
62                 if self.save_mask & 1:
63                         self.timeinput_time.save()
64                 if self.save_mask & 2:
65                         self.timeinput_date.save()
66                 self.close((True, time))
67
68         def keyCancel(self):
69                 if self.save_mask & 1:
70                         self.timeinput_time.cancel()
71                 if self.save_mask & 2:
72                         self.timeinput_date.cancel()
73                 self.close((False,))