Back to index

scribus-ng  1.3.4.dfsg+svn20071115
boilerplate.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 # -*- coding: utf-8 -*-
00003 
00004 import sys
00005 
00006 try:
00007     # Please do not use 'from scribus import *' . If you must use a 'from import',
00008     # Do so _after_ the 'import scribus' and only import the names you need, such
00009     # as commonly used constants.
00010     import scribus
00011 except ImportError,err:
00012     print "This Python script is written for the Scribus scripting interface."
00013     print "It can only be run from within Scribus."
00014     sys.exit(1)
00015 
00016 #########################
00017 # YOUR IMPORTS GO HERE  #
00018 #########################
00019 
00020 def main(argv):
00021     """This is a documentation string. Write a description of what your code
00022     does here. You should generally put documentation strings ("docstrings")
00023     on all your Python functions."""
00024     #########################
00025     #  YOUR CODE GOES HERE  #
00026     #########################
00027     pass    # <--- Delete this line
00028 
00029 def main_wrapper(argv):
00030     """The main_wrapper() function disables redrawing, sets a sensible generic
00031     status bar message, and optionally sets up the progress bar. It then runs
00032     the main() function. Once everything finishes it cleans up after the main()
00033     function, making sure everything is sane before the script terminates."""
00034     try:
00035         scribus.statusMessage("Running script...")
00036         scribus.progressReset()
00037         main(argv)
00038     finally:
00039         # Exit neatly even if the script terminated with an exception,
00040         # so we leave the progress bar and status bar blank and make sure
00041         # drawing is enabled.
00042         if scribus.haveDoc():
00043             scribus.setRedraw(True)
00044         scribus.statusMessage("")
00045         scribus.progressReset()
00046 
00047 # This code detects if the script is being run as a script, or imported as a module.
00048 # It only runs main() if being run as a script. This permits you to import your script
00049 # and control it manually for debugging.
00050 if __name__ == '__main__':
00051     main_wrapper(sys.argv)