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
|
#!/usr/bin/env python
import sys
from PyTQt.tqt import *
def TQMIN(x, y):
if y > x: return y
return x
class AnalogClock(TQWidget):
def __init__(self, *args):
TQWidget.__init__(*(self,) + args)
self.time = TQTime.currentTime()
internalTimer = TQTimer(self)
self.connect(internalTimer, SIGNAL("timeout()"), self.timeout)
internalTimer.start(5000)
def timeout(self):
new_time = TQTime.currentTime()
if new_time.minute() != self.time.minute():
self.update()
def paintEvent(self, tqe):
if not self.isVisible():
return
self.time = TQTime.currentTime()
pts = TQPointArray()
paint = TQPainter(self)
paint.setBrush(self.foregroundColor())
cp = TQPoint(self.rect().center())
d = TQMIN(self.width(), self.height())
matrix = TQWMatrix()
matrix.translate(cp.x(), cp.y())
matrix.scale(d/1000.0, d/1000.0)
h_angle = 30*(self.time.hour()%12 - 3) + self.time.minute()/2
matrix.rotate(h_angle)
paint.setWorldMatrix(matrix)
pts.setPoints([-20,0,0,-20,300,0,0,20])
paint.drawPolygon(pts)
matrix.rotate(-h_angle)
m_angle = (self.time.minute()-15)*6
matrix.rotate(m_angle)
paint.setWorldMatrix(matrix)
pts.setPoints([-10,0,0,-10,400,0,0,10])
paint.drawPolygon(pts)
matrix.rotate(-m_angle)
for i in range(0,12):
paint.setWorldMatrix(matrix)
paint.drawLine(450,0, 500,0)
matrix.rotate(30)
a = TQApplication(sys.argv)
clock = AnalogClock()
clock.resize(100,100)
a.setMainWidget(clock)
clock.show()
a.exec_loop()
|