Difference between revisions of "Troubleshooting Scripts"

From Scribus Wiki
Jump to: navigation, search
(Invoking Scribus Commands)
(Changes in Constants)
Line 38: Line 38:
  
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
Trying this now will result in your script hanging and locking up Scribus, since there will be no '''OK''' button to close the '''messageBox()'''.

Revision as of 14:16, 6 November 2016

This article is part of the Scripts series.

You are likely to find that a number of the example scripts on the wiki don't work, either generating errors, or perhaps nothing happens at all. This is because the acceptable syntax has changed over the years. On this page are some of the common problems I have encountered, often with my own scripts, which at one time worked, and now do not.

Invoking Scribus Commands

There are two ways to include the Scribus Scripter commands:

from scribus import *

and

import scribus

The first of these pulls in all of the Scripter commands into the interpreter, and is not the advocated method, since most scripts use a handful of Scribus Python commands. The second one only looks for a Scribus method when it is called, but it's important to tell Python that this is a Scribus command, so for example,

import scribus

if selectionCount() != 2:
    messageBox('Selection Count', "You must have 2 image frames selected",
                       ICON_WARNING, BUTTON_OK)

This is going to fail, and may even "hang" Scribus. This is because selectionCount(), messageBox() are Scribus commands, and ICON_WARNING and BUTTON_OK are Scribus-specific constants. So you need to prepend scribus. before each of these commands, like so:

import scribus

if scribus.selectionCount() != 2:
    scribus.messageBox('Selection Count', "You must have 2 image frames selected",
                       scribus.ICON_WARNING, scribus.BUTTON_OK)

Changes in Constants

This brings up another problem with some older scripts. In a messageBox() command like above, you used to be able to use a number for these constants, like

    scribus.messageBox('Selection Count', "You must have 2 image frames selected",
                       icon1=0, button1=1)

Trying this now will result in your script hanging and locking up Scribus, since there will be no OK button to close the messageBox().