/
EtAnalogClock.py
47 lines (37 loc) · 985 Bytes
/
EtAnalogClock.py
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
# original code is from openmips gb Team: [OMaclock] Converter #
# Thx to arn354 #
from __future__ import absolute_import
from time import localtime
from Components.Converter.Converter import Converter
from Components.Element import cached
class EtAnalogClock(Converter):
DEFAULT = 0
OMA_SEC = 1
OMA_MIN = 2
OMA_HOUR = 3
def __init__(self, type):
Converter.__init__(self, type)
if type == "Seconds":
self.type = self.OMA_SEC
elif type == "Minutes":
self.type = self.OMA_MIN
elif type == "Hours":
self.type = self.OMA_HOUR
else:
self.type = self.DEFAULT
@cached
def getText(self):
time = self.source.time
if time is None:
return ""
t = localtime(time)
if self.type == self.OMA_SEC:
return "%02d,sec" % t.tm_sec
elif self.type == self.OMA_MIN:
return "%02d,min" % t.tm_min
elif self.type == self.OMA_HOUR:
ret = (t.tm_hour * 5) + (t.tm_min / 12)
return "%02d,hour" % ret
else:
return "???"
text = property(getText)