/
EtAnalogClockLCD.py
128 lines (113 loc) · 3.19 KB
/
EtAnalogClockLCD.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
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# original code is from openmips gb Team: [OMaClockLcd] Renderer #
# Thx to arn354 #
from __future__ import absolute_import
from math import cos, pi, sin
from enigma import eCanvas, eRect, eSize, gRGB
from Components.Renderer.Renderer import Renderer
from skin import parseColor
class EtAnalogClockLCD(Renderer):
def __init__(self):
Renderer.__init__(self)
self.fColor = gRGB(255, 255, 255, 0)
self.fColors = gRGB(255, 0, 0, 0)
self.fColorm = gRGB(255, 0, 0, 0)
self.fColorh = gRGB(255, 255, 255, 0)
self.bColor = gRGB(0, 0, 0, 255)
self.forend = -1
self.linewidth = 1
self.positionheight = 1
self.positionwidth = 1
self.linesize = 1
GUI_WIDGET = eCanvas
def applySkin(self, desktop, parent):
attribs = []
for (attrib, what,) in self.skinAttributes:
if (attrib == 'hColor'):
self.fColorh = parseColor(what)
elif (attrib == 'mColor'):
self.fColorm = parseColor(what)
elif (attrib == 'sColor'):
self.fColors = parseColor(what)
elif (attrib == 'linewidth'):
self.linewidth = int(what)
elif (attrib == 'positionheight'):
self.positionheight = int(what)
elif (attrib == 'positionwidth'):
self.positionwidth = int(what)
elif (attrib == 'linesize'):
self.linesize = int(what)
else:
attribs.append((attrib, what))
self.skinAttributes = attribs
return Renderer.applySkin(self, desktop, parent)
def calc(self, w, r, m, m1):
a = (w * 6)
z = (pi / 180)
x = int(round((r * sin((a * z)))))
y = int(round((r * cos((a * z)))))
return ((m + x), (m1 - y))
def hand(self, opt):
width = self.positionwidth
height = self.positionheight
r = (width / 2)
r1 = (height / 2)
l = self.linesize
if opt == 'sec':
l = self.linesize
self.fColor = self.fColors
elif opt == 'min':
l = self.linesize
self.fColor = self.fColorm
else:
self.fColor = self.fColorh
(endX, endY,) = self.calc(self.forend, l, r, r1)
self.line_draw(r, r1, endX, endY)
def line_draw(self, x0, y0, x1, y1):
steep = (abs((y1 - y0)) > abs((x1 - x0)))
if steep:
x0, y0 = y0, x0
x1, y1 = y1, x1
if (x0 > x1):
x0, x1 = x1, x0
y0, y1 = y1, y0
if (y0 < y1):
ystep = 1
else:
ystep = -1
deltax = (x1 - x0)
deltay = abs((y1 - y0))
error = (-deltax / 2)
y = y0
for x in list(range(x0, (x1 + 1))):
if steep:
self.instance.fillRect(eRect(y, x, self.linewidth, self.linewidth), self.fColor)
else:
self.instance.fillRect(eRect(x, y, self.linewidth, self.linewidth), self.fColor)
error = (error + deltay)
if (error > 0):
y = (y + ystep)
error = (error - deltax)
def changed(self, what):
opt = (self.source.text).split(',')
try:
sopt = int(opt[0])
if len(opt) < 2:
opt.append('')
except Exception as e:
return
if (what[0] == self.CHANGED_CLEAR):
pass
elif self.instance:
self.instance.show()
if (self.forend != sopt):
self.forend = sopt
self.instance.clear(self.bColor)
self.hand(opt[1])
def parseSize(self, str):
(x, y,) = str.split(',')
return eSize(int(x), int(y))
def postWidgetCreate(self, instance):
for (attrib, value,) in self.skinAttributes:
if ((attrib == 'size') and self.instance.setSize(self.parseSize(value))):
pass
self.instance.clear(self.bColor)