follow Console() changes
[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                 self.list.append(getConfigListEntry(_("Date"), self.timeinput_date))
47                 self.list.append(getConfigListEntry(_("Time"), self.timeinput_time))
48                 configlist.list = self.list
49                 configlist.l.setList(self.list)
50
51         def keySelect(self):
52                 self.keyGo()
53
54         def getTimestamp(self, date, mytime):
55                 d = time.localtime(date)
56                 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
57                 return int(time.mktime(dt.timetuple()))
58
59         def keyGo(self):
60                 time = self.getTimestamp(self.timeinput_date.value, self.timeinput_time.value)
61                 if self.save_mask & 1:
62                         self.timeinput_time.save()
63                 if self.save_mask & 2:
64                         self.timeinput_date.save()
65                 self.close((True, time))
66
67         def keyCancel(self):
68                 if self.save_mask & 1:
69                         self.timeinput_time.cancel()
70                 if self.save_mask & 2:
71                         self.timeinput_date.cancel()
72                 self.close((False,))