You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
13 years ago
|
#!/usr/bin/env python
|
||
|
|
||
|
import sys
|
||
8 years ago
|
from python_tqt.qt import *
|
||
13 years ago
|
|
||
13 years ago
|
def TQMIN(x, y):
|
||
13 years ago
|
if y > x: return y
|
||
|
return x
|
||
13 years ago
|
class AnalogClock(TQWidget):
|
||
13 years ago
|
def __init__(self, *args):
|
||
3 years ago
|
TQWidget.__init__(*(self,) + args)
|
||
13 years ago
|
self.time = TQTime.currentTime()
|
||
|
internalTimer = TQTimer(self)
|
||
13 years ago
|
self.connect(internalTimer, SIGNAL("timeout()"), self.timeout)
|
||
|
internalTimer.start(5000)
|
||
|
|
||
|
def timeout(self):
|
||
13 years ago
|
new_time = TQTime.currentTime()
|
||
13 years ago
|
if new_time.minute() != self.time.minute():
|
||
|
self.update()
|
||
|
|
||
|
def paintEvent(self, qe):
|
||
|
if not self.isVisible():
|
||
|
return
|
||
13 years ago
|
self.time = TQTime.currentTime()
|
||
13 years ago
|
|
||
13 years ago
|
pts = TQPointArray()
|
||
|
paint = TQPainter(self)
|
||
13 years ago
|
paint.setBrush(self.foregroundColor())
|
||
|
|
||
13 years ago
|
cp = TQPoint(self.rect().center())
|
||
|
d = TQMIN(self.width(), self.height())
|
||
|
matrix = TQWMatrix()
|
||
13 years ago
|
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)
|
||
|
|
||
13 years ago
|
a = TQApplication(sys.argv)
|
||
13 years ago
|
clock = AnalogClock()
|
||
|
clock.resize(100,100)
|
||
|
a.setMainWidget(clock)
|
||
|
clock.show()
|
||
|
a.exec_loop()
|