SIP4 python bindings for TQt
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

aclock.py 1.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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()