config rewrite. some extensions still need to be updated.
[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                 }, -1)
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"), 86400))
36 #               self.timeinput_time = ConfigSequence(default = [int(time.strftime("%H", time.localtime(nowtime))), int(time.strftime("%M", time.localtime(nowtime)))]
37                 assert False, "fixme"
38
39         def createSetup(self, configlist):
40                 self.list = []
41                 self.list.append(getConfigListEntry(_("Date"), config.timeinput.date))
42                 self.list.append(getConfigListEntry(_("Time"), config.timeinput.time))
43                 configlist.list = self.list
44                 configlist.l.setList(self.list)
45
46         def keyRightCallback(self, configPath):
47                 currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
48                 # check if we are still on the same config entry
49                 if (currentConfigPath == configPath):
50                         self.keyRight()
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(mktime(dt.timetuple()))
59
60         def keyGo(self):
61                 time = self.getTimestamp(config.timeinput.date.value, config.timeinput.time.value)
62                 self.close((True, time))
63
64         def keyCancel(self):
65                 self.close((False,))