6cdc6217f3303e0dba47ca17700aa4b6c81e4ef7
[enigma2.git] / lib / python / Screens / TimeDateInput.py
1 from Screen import Screen
2 from Components.config import *
3 from Components.ActionMap import ActionMap, NumberActionMap
4 from Components.ConfigList import ConfigList, ConfigListScreen
5 from Components.Button import Button
6 from Components.Label import Label
7 from Components.Pixmap import Pixmap
8 import time
9 import datetime
10
11 class TimeDateInput(Screen, ConfigListScreen):
12         def __init__(self, session):
13                 Screen.__init__(self, session)
14
15                 self["oktext"] = Label(_("OK"))
16                 self["canceltext"] = Label(_("Cancel"))
17                 self["ok"] = Pixmap()
18                 self["cancel"] = Pixmap()
19
20                 self.createConfig()
21
22                 self["actions"] = NumberActionMap(["SetupActions"],
23                 {
24                         "ok": self.keySelect,
25                         "save": self.keyGo,
26                         "cancel": self.keyCancel,
27                 }, -2)
28
29                 self.list = []
30                 ConfigListScreen.__init__(self, self.list)
31                 self.createSetup(self["config"])
32
33         def createConfig(self):
34                 nowtime = time.time()
35                 self.timeinput_date = ConfigDateTime(default = nowtime, formatstring = _("%d.%B %Y"), increment = 86400)
36                 self.timeinput_time = ConfigClock(default = nowtime)
37
38         def createSetup(self, configlist):
39                 self.list = []
40                 self.list.append(getConfigListEntry(_("Date"), self.timeinput_date))
41                 self.list.append(getConfigListEntry(_("Time"), self.timeinput_time))
42                 configlist.list = self.list
43                 configlist.l.setList(self.list)
44
45         def keySelect(self):
46                 self.keyGo()
47
48         def getTimestamp(self, date, mytime):
49                 d = time.localtime(date)
50                 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
51                 return int(time.mktime(dt.timetuple()))
52
53         def keyGo(self):
54                 time = self.getTimestamp(self.timeinput_date.value, self.timeinput_time.value)
55                 self.close((True, time))
56
57         def keyCancel(self):
58                 self.close((False,))