Boilerplate.py: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
m ("Geishi will find you. No matter how long it takes, no matter how far, Geishi will find you" --last of the mohicans (movie)) |
||
Line 1: | Line 1: | ||
(retrieved from 1.4.0 rc6 script directory) | (retrieved from 1.4.0 rc6 script directory) | ||
< | <syntaxhighlight lang='python'> | ||
#!/usr/bin/env python | #!/usr/bin/env python | ||
# -*- coding: utf-8 -*- | # -*- coding: utf-8 -*- | ||
Line 53: | Line 53: | ||
if __name__ == '__main__': | if __name__ == '__main__': | ||
main_wrapper(sys.argv) | main_wrapper(sys.argv) | ||
</syntaxhighlight> | |||
</ |
Latest revision as of 02:23, 20 January 2014
(retrieved from 1.4.0 rc6 script directory)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
try:
# Please do not use 'from scribus import *' . If you must use a 'from import',
# Do so _after_ the 'import scribus' and only import the names you need, such
# as commonly used constants.
import scribus
except ImportError,err:
print "This Python script is written for the Scribus scripting interface."
print "It can only be run from within Scribus."
sys.exit(1)
#########################
# YOUR IMPORTS GO HERE #
#########################
def main(argv):
"""This is a documentation string. Write a description of what your code
does here. You should generally put documentation strings ("docstrings")
on all your Python functions."""
#########################
# YOUR CODE GOES HERE #
#########################
pass # <--- Delete this line
def main_wrapper(argv):
"""The main_wrapper() function disables redrawing, sets a sensible generic
status bar message, and optionally sets up the progress bar. It then runs
the main() function. Once everything finishes it cleans up after the main()
function, making sure everything is sane before the script terminates."""
try:
scribus.statusMessage("Running script...")
scribus.progressReset()
main(argv)
finally:
# Exit neatly even if the script terminated with an exception,
# so we leave the progress bar and status bar blank and make sure
# drawing is enabled.
if scribus.haveDoc():
scribus.setRedraw(True)
scribus.statusMessage("")
scribus.progressReset()
# This code detects if the script is being run as a script, or imported as a module.
# It only runs main() if being run as a script. This permits you to import your script
# and control it manually for debugging.
if __name__ == '__main__':
main_wrapper(sys.argv)