SIP4 python bindings for TQt
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.5KB

  1. #!/usr/bin/env python
  2. import sys
  3. from python_tqt.qt import *
  4. def TQMIN(x, y):
  5. if y > x: return y
  6. return x
  7. class AnalogClock(TQWidget):
  8. def __init__(self, *args):
  9. apply(TQWidget.__init__,(self,) + args)
  10. self.time = TQTime.currentTime()
  11. internalTimer = TQTimer(self)
  12. self.connect(internalTimer, SIGNAL("timeout()"), self.timeout)
  13. internalTimer.start(5000)
  14. def timeout(self):
  15. new_time = TQTime.currentTime()
  16. if new_time.minute() != self.time.minute():
  17. self.update()
  18. def paintEvent(self, qe):
  19. if not self.isVisible():
  20. return
  21. self.time = TQTime.currentTime()
  22. pts = TQPointArray()
  23. paint = TQPainter(self)
  24. paint.setBrush(self.foregroundColor())
  25. cp = TQPoint(self.rect().center())
  26. d = TQMIN(self.width(), self.height())
  27. matrix = TQWMatrix()
  28. matrix.translate(cp.x(), cp.y())
  29. matrix.scale(d/1000.0, d/1000.0)
  30. h_angle = 30*(self.time.hour()%12 - 3) + self.time.minute()/2
  31. matrix.rotate(h_angle)
  32. paint.setWorldMatrix(matrix)
  33. pts.setPoints([-20,0,0,-20,300,0,0,20])
  34. paint.drawPolygon(pts)
  35. matrix.rotate(-h_angle)
  36. m_angle = (self.time.minute()-15)*6
  37. matrix.rotate(m_angle)
  38. paint.setWorldMatrix(matrix)
  39. pts.setPoints([-10,0,0,-10,400,0,0,10])
  40. paint.drawPolygon(pts)
  41. matrix.rotate(-m_angle)
  42. for i in range(0,12):
  43. paint.setWorldMatrix(matrix)
  44. paint.drawLine(450,0, 500,0)
  45. matrix.rotate(30)
  46. a = TQApplication(sys.argv)
  47. clock = AnalogClock()
  48. clock.resize(100,100)
  49. a.setMainWidget(clock)
  50. clock.show()
  51. a.exec_loop()