aboutsummaryrefslogtreecommitdiff
path: root/lib/python/Screens/TimeDateInput.py
blob: 4ea67b74619e60adc143ba55d7c4e1bdf7470a2f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
from Screen import Screen
from Components.config import *
from Components.ActionMap import ActionMap, NumberActionMap
from Components.ConfigList import ConfigList
from Components.Button import Button
from Components.Label import Label
from Components.Pixmap import Pixmap
import time
import datetime

class TimeDateInput(Screen):
	def __init__(self, session):
		Screen.__init__(self, session)

		self["oktext"] = Label(_("OK"))
		self["canceltext"] = Label(_("Cancel"))
		self["ok"] = Pixmap()
		self["cancel"] = Pixmap()

		self.createConfig()

		self["actions"] = NumberActionMap(["SetupActions", "TextEntryActions"],
		{
			"ok": self.keySelect,
			"save": self.keyGo,
			"cancel": self.keyCancel,
			"left": self.keyLeft,
			"right": self.keyRight,
			"delete": self.keyDelete,
			"1": self.keyNumberGlobal,
			"2": self.keyNumberGlobal,
			"3": self.keyNumberGlobal,
			"4": self.keyNumberGlobal,
			"5": self.keyNumberGlobal,
			"6": self.keyNumberGlobal,
			"7": self.keyNumberGlobal,
			"8": self.keyNumberGlobal,
			"9": self.keyNumberGlobal,
			"0": self.keyNumberGlobal
		}, -1)

		self.list = []
		self["config"] = ConfigList(self.list)
		self.createSetup(self["config"])

	def createConfig(self):
			config.timeinput = ConfigSubsection()
			nowtime = time.time()
			config.timeinput.date = configElement_nonSave("config.timeinput.date", configDateTime, nowtime, (_("%d.%B %Y"), 86400))
			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"))

	def createSetup(self, configlist):
		self.list = []
		self.list.append(getConfigListEntry(_("Date"), config.timeinput.date))
		self.list.append(getConfigListEntry(_("Time"), config.timeinput.time))
		configlist.list = self.list
		configlist.l.setList(self.list)

	def keyLeft(self):
		self["config"].handleKey(config.key["prevElement"])

	def keyDelete(self):
		self["config"].handleKey(config.key["delete"])

	def keyRightCallback(self, configPath):
		currentConfigPath = self["config"].getCurrent()[1].parent.getConfigPath()
		# check if we are still on the same config entry
		if (currentConfigPath == configPath):
			self.keyRight()

	def keyRight(self):
		self["config"].handleKey(config.key["nextElement"])

	def keySelect(self):
		self.keyGo()

	def keyNumberGlobal(self, number):
		print "You pressed number " + str(number)
		if (self["config"].getCurrent()[1].parent.enabled == True):
			self["config"].handleKey(config.key[str(number)])

	def getTimestamp(self, date, mytime):
		d = time.localtime(date)
		dt = datetime.datetime(d.tm_year, d.tm_mon, d.tm_mday, mytime[0], mytime[1])
		return int(mktime(dt.timetuple()))

	def keyGo(self):
		time = self.getTimestamp(config.timeinput.date.value, config.timeinput.time.value)
		self.close((True, time))

	def keyCancel(self):
		self.close((False,))