boilerplate & messagebox syntax

Previous topic - Next topic


I have had a few of the scripts shipped with the scribus 1.5.* versions freeze Scibus because the message box has no buttons to dismiss it.

So I looked at some of the other sample scripts and was able to modify the '' script to avoid this. I then decided I should put it into the boiler plate... see the sample script  files: if you are on Linux & using the 15.0 version from the Scribus Friends ppa they should be here...

My changed script...
#!/usr/bin/env python
# -*- coding: utf-8 -*-

(C)2006.03.04 Gregory Pittman

(C)2008.02.28 Petr Vanek - fileDialog replaces valueDialog

this version 2008.02.28

This program is free software; you can redistribute it and/or modify
it under the terms of the  GPL, v2 (GNU General Public License as published by
the Free Software Foundation, version 2 of the License), or any later version.
See the Scribus Copyright page in the Help Browser for further informaton
about GPL, v2.


This script takes the current document and extracts all the text from text frames,
and also gets the pathnames to all images. This is then saved to a file named
by the user.


You must run from Scribus and must have a file open.


Start the script. A file dialog appears for the name of the file
to save to. The above information is saved to the file.

# Craig Bradney, Scribus Team
# 10/3/08: Added to Scribus distribution "as was" from Scribus wiki for bug #6826, script is GPLd
# 20150904 - trebor Modified to fix the scribus.messageBox & incorporated into the Scribus 1.5 boiler plate script template
import sys

    # 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."


def main(argv):
def exportText(textfile):
    page = 1
    pagenum = scribus.pageCount()
    T = []
    content = []
    while (page <= pagenum):
        d = scribus.getPageItems()
        strpage = str(page)
        T.append('Page '+ strpage + '\n\n')
        for item in d:
            if (item[1] == 4):
                contents = scribus.getAllText(item[0])
                if (contents in content):
                    contents = 'Duplication, perhaps linked-to frame'
                T.append(item[0]+': '+ contents + '\n\n')
            elif (item[1] == 2):
                imgname = scribus.getImageFile(item[0])
                T.append(item[0]+': ' + imgname + '\n')
        page += 1
    output_file = open(textfile,'w')
    endmessage = textfile + ' was created'
    # See help - /usr/share/doc/scribus-ng/en/scripterapi-dialogs.html
    # Don't know why the scribus. syntax is required
    scribus.messageBox("Finished", endmessage, scribus.ICON_INFORMATION, scibus.BUTTON_OK)

if scribus.haveDoc():
    textfile = scribus.fileDialog('Enter name of file to save to', \
                                  filter='Text Files (*.txt);;All Files (*)')
        if textfile == '':
            raise Exception
    except Exception, e:
        print e

    scribus.messageBox('Export Error', 'You need a Document open, and a frame selected.', scribus.ICON_WARNING, scribus.BUTTON_OK)

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."""
        scribus.statusMessage("Running script...")
        # 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():

# 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__':

Some scripts in the samples work with 'messagebox' (not 'scribus.messagebox') format..
No idea why - I couldn't get it to work this way in the extracttext version.
This from the word count sample file
messageBox(TITLE, "Can't count words in a non-text frame", ICON_INFORMATION)

Hope you find this useful. Thanks Scribus team! :-*


I read a lot, before to understand :)

Thanks. I corrected the script and all seem OK  ;D

But I would like to understand why this was running OK in console, and not in line. May be the console has already the icon name in memory?

Thanks for all in any case.