much more flexible method to get a servicelist in python..
[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
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):
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", "TextEntryActions"],
23                 {
24                         "ok": self.keySelect,
25                         "save": self.keyGo,
26                         "cancel": self.keyCancel,
27                         "left": self.keyLeft,
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
40                 }, -1)
41
42                 self.list = []
43                 self["config"] = ConfigList(self.list)
44                 self.createSetup(self["config"])
45
46         def createConfig(self):
47                         config.timeinput = ConfigSubsection()
48                         nowtime = time.time()
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"))
51
52         def createSetup(self, configlist):
53                 self.list = []
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)
58
59         def keyLeft(self):
60                 self["config"].handleKey(config.key["prevElement"])
61
62         def keyDelete(self):
63                 self["config"].handleKey(config.key["delete"])
64
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):
69                         self.keyRight()
70
71         def keyRight(self):
72                 self["config"].handleKey(config.key["nextElement"])
73
74         def keySelect(self):
75                 self.keyGo()
76
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)])
81
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()))
86
87         def keyGo(self):
88                 time = self.getTimestamp(config.timeinput.date.value, config.timeinput.time.value)
89                 self.close((True, time))
90
91         def keyCancel(self):
92                 self.close((False,))