Back to index

scribus-ng  1.3.4.dfsg+svn20071115
pyqt_timer.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 """
00005 A simple demo script showing the use of PyQt timers.
00006 
00007 Note that if you run this script again before the timer
00008 fires, the first timer is cancelled (because the timer object
00009 is deleted when you replace the only reference to it, the
00010 `timer' name in the global scope. Watch out for this sort
00011 of thing when writing your scripts.
00012 """
00013 
00014 import sys
00015 
00016 try:
00017     import scribus
00018 except ImportError,err:
00019     print "This script only runs from within Scribus"
00020     sys.exit(1)
00021 
00022 try:
00023     import qt
00024 except ImportError,err:
00025     scribus.messageBox("Scribus - Python Timer",
00026                        "It seems you don't have PyQt installed. "
00027                        "This script can't do anything without it. "
00028                        "You can probably install PyQt from your "
00029                        "distro's packages. Failing that, you can get "
00030                        "PyQt from http://www.riverbankcomputing.co.uk .",
00031                        scribus.BUTTON_OK)
00032     sys.exit(1)
00033 
00034 def msg():
00035     scribus.messageBox("Scribus - Python Timer",
00036                        "The timer has run out",
00037                        scribus.BUTTON_OK)
00038 
00039 def main():
00040     global timer
00041     timer = qt.QTimer()
00042     timer.connect(timer, qt.SIGNAL("timeout()"), msg)
00043     scribus.messageBox("Scribus - Python Timer",
00044                        "About to start a 5 second timer",
00045                        scribus.BUTTON_OK)
00046     timer.start(5*1000, True)
00047 
00048 if __name__ == '__main__':
00049     main()