home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 November / CPNL0711.ISO / beeld / teken / scribus-1.3.3.9-win32-install.exe / share / samples / pyqt_timer.py < prev    next >
Text File  |  2005-07-05  |  1KB  |  50 lines

  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. """
  5. A simple demo script showing the use of PyQt timers.
  6.  
  7. Note that if you run this script again before the timer
  8. fires, the first timer is cancelled (because the timer object
  9. is deleted when you replace the only reference to it, the
  10. `timer' name in the global scope. Watch out for this sort
  11. of thing when writing your scripts.
  12. """
  13.  
  14. import sys
  15.  
  16. try:
  17.     import scribus
  18. except ImportError,err:
  19.     print "This script only runs from within Scribus"
  20.     sys.exit(1)
  21.  
  22. try:
  23.     import qt
  24. except ImportError,err:
  25.     scribus.messageBox("Scribus - Python Timer",
  26.                        "It seems you don't have PyQt installed. "
  27.                        "This script can't do anything without it. "
  28.                        "You can probably install PyQt from your "
  29.                        "distro's packages. Failing that, you can get "
  30.                        "PyQt from http://www.riverbankcomputing.co.uk .",
  31.                        scribus.BUTTON_OK)
  32.     sys.exit(1)
  33.  
  34. def msg():
  35.     scribus.messageBox("Scribus - Python Timer",
  36.                        "The timer has run out",
  37.                        scribus.BUTTON_OK)
  38.  
  39. def main():
  40.     global timer
  41.     timer = qt.QTimer()
  42.     timer.connect(timer, qt.SIGNAL("timeout()"), msg)
  43.     scribus.messageBox("Scribus - Python Timer",
  44.                        "About to start a 5 second timer",
  45.                        scribus.BUTTON_OK)
  46.     timer.start(5*1000, True)
  47.  
  48. if __name__ == '__main__':
  49.     main()
  50.