Back to index

scribus-ng  1.3.4.dfsg+svn20071115
startup_hook.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf8 -*-
00003 
00004 """
00005 This script is a simple example to show how you can trigger things based on
00006 event hooks provided by Scribus. This sample runs the `gotSignal' method
00007 when the app has finished setting up and it emits the appStarted() signal.
00008 This is useful if, for example, you need access to the main window to
00009 do your setup when running as a startup script.
00010 
00011 This script isn't very interesting unless you run it as a startup script,
00012 with Scribus running in an xterm, and watch the output on stdout/stderr.
00013 
00014 You will need PyQt for this script to work.
00015 """
00016 
00017 try:
00018     import qt
00019 except:
00020     print "Seems you don't have PyQt. Doing nothing."
00021     return
00022 
00023 from qt import SIGNAL, PYSIGNAL, SLOT
00024 
00025 # Note that to connect to signals etc you MUST inherit from QObject or a subclass
00026 # of QObject.
00027 class Recipient(qt.QObject):
00028 
00029     def __init__(self):
00030         # Connect ourselves to the "appStarted()" signal emitted by Scribus.
00031         # Ask PyQt to run the self.gotSignal method when the signal is emitted.
00032         self.connect(qt.qApp, SIGNAL("appStarted()"), self.gotSignal)
00033 
00034     def gotSignal(self):
00035         print "PONG!"
00036 
00037 if __name__ == '__main__':
00038     recip = Recipient();