1 from Screen import Screen
2 from Components.config import *
3 from Components.ActionMap import ActionMap, NumberActionMap
4 from Components.ConfigList import ConfigList
5 from Components.Button import Button
6 from Components.Label import Label
7 from Components.Pixmap import Pixmap
11 class TimeDateInput(Screen):
12 def __init__(self, session):
13 Screen.__init__(self, session)
15 self["oktext"] = Label(_("OK"))
16 self["canceltext"] = Label(_("Cancel"))
18 self["cancel"] = Pixmap()
22 self["actions"] = NumberActionMap(["SetupActions", "TextEntryActions"],
26 "cancel": self.keyCancel,
28 "right": self.keyRight,
29 "delete": self.keyDelete,
30 "1": self.keyNumberGlobal,
31 "2": self.keyNumberGlobal,
32 "3": self.keyNumberGlobal,
33 "4": self.keyNumberGlobal,
34 "5": self.keyNumberGlobal,
35 "6": self.keyNumberGlobal,
36 "7": self.keyNumberGlobal,
37 "8": self.keyNumberGlobal,
38 "9": self.keyNumberGlobal,
39 "0": self.keyNumberGlobal
43 self["config"] = ConfigList(self.list)
44 self.createSetup(self["config"])
46 def createConfig(self):
47 config.timeinput = ConfigSubsection()
49 config.timeinput.date = configElement_nonSave("config.timeinput.date", configDateTime, nowtime, (_("%d.%B %Y"), 86400))
50 config.timeinput.time = configElement_nonSave("config.timeinput.time", configSequence, [int(time.strftime("%H", time.localtime(nowtime))), int(time.strftime("%M", time.localtime(nowtime)))], configsequencearg.get("CLOCK"))
52 def createSetup(self, configlist):
54 self.list.append(getConfigListEntry(_("Date"), config.timeinput.date))
55 self.list.append(getConfigListEntry(_("Time"), config.timeinput.time))
56 configlist.list = self.list
57 configlist.l.setList(self.list)
60 self["config"].handleKey(config.key["prevElement"])
63 self["config"].handleKey(config.key["delete"])
65 def keyRightCallback(self, configPath):
66 currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
67 # check if we are still on the same config entry
68 if (currentConfigPath == configPath):
72 self["config"].handleKey(config.key["nextElement"])
77 def keyNumberGlobal(self, number):
78 print "You pressed number " + str(number)
79 if (self["config"].getCurrent()[1].parent.enabled == True):
80 self["config"].handleKey(config.key[str(number)])
82 def getTimestamp(self, date, mytime):
83 d = time.localtime(date)
84 dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
85 return int(mktime(dt.timetuple()))
88 time = self.getTimestamp(config.timeinput.date.value, config.timeinput.time.value)
89 self.close((True, time))