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.

dclock.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. # A port to PyTQt of the dclock example from TQt v2.x.
  3. import sys, string
  4. from python_tqt.qt import *
  5. class DigitalClock(TQLCDNumber):
  6. def __init__(self, parent=None, name=None):
  7. TQLCDNumber.__init__(self, parent, name)
  8. self.showingColon = 0
  9. self.setFrameStyle(TQFrame.Panel | TQFrame.Raised)
  10. self.setLineWidth(2)
  11. self.showTime()
  12. self.normalTimer = self.startTimer(500)
  13. self.showDateTimer = -1
  14. def timerEvent(self, e):
  15. if e.timerId() == self.showDateTimer:
  16. self.stopDate()
  17. else:
  18. if self.showDateTimer == -1:
  19. self.showTime()
  20. def mousePressEvent(self, e):
  21. if e.button() == TQt.LeftButton:
  22. self.showDate()
  23. def showDate(self):
  24. if self.showDateTimer != -1:
  25. return
  26. d = TQDate.currentDate()
  27. self.display('%2d %2d' % (d.month(), d.day()))
  28. self.showDateTimer = self.startTimer(2000)
  29. def stopDate(self):
  30. self.killTimer(self.showDateTimer)
  31. self.showDateTimer = -1
  32. self.showTime()
  33. def showTime(self):
  34. self.showingColon = not self.showingColon
  35. s = list(str(TQTime.currentTime().toString())[:5]) #.left(5)
  36. if not self.showingColon:
  37. s[2] = ' '
  38. if s[0] == '0':
  39. s[0] = ' '
  40. s = string.join(s,'')
  41. self.display(s)
  42. a = TQApplication(sys.argv)
  43. clock = DigitalClock()
  44. clock.resize(170,80)
  45. a.setMainWidget(clock)
  46. clock.show()
  47. a.exec_loop()