[scribus] Catalogue Scripts

Don Strayer dstrayer at sadt.com
Mon Oct 11 23:54:25 CEST 2010


On Monday, October 11, 2010 07:06:24 am Ian "Witty" Whitfield wrote:
> I have looked at your Catalogue with interest. In particular I'm
> very  interested to know more about the Python Scripts you are
> using!!
> 
> Please keep in mind that I don't know Python or even how to use it
> in  Scribus but I'm very happy to learn it if it would do what I
> want.
> 
> I have a Database of members details and I publish a monthly Journal 
> that goes round the World. Each article or letter from a member that 
> goes into the Journal has the Members details and a photo attached.
> This  sounds very much like what you are doing, (except your
> "members" have 4 legs!!!).
> 
> Anything you, or anyone else, can tell me about this would be
> appreciated.
> 
> Thanks a lot.

Ian,

The scripts for my catalog are so specialized to their specific purpose
that I doubt that they'd be of much help. I'll start here with some
generalities, and maybe post some cleaned-up examples later.

Online documentation for the Scribus scripter interface is at
http://docs.scribus.net/ under "For Developers". In particular, the
pages under "Scripter API" list the commands that can be called from a
script to manipulate a document.

There are lots of example scripts in the wiki:
http://wiki.scribus.net/index.php/Category:Scripts_%26_Plugins

For learning Python itself, some of these might help:

How to Think Like a Computer Scientist: Learning with Python
http://openbookproject.net/thinkCSpy/

The Python Tutorial at the Python website
http://docs.python.org/tutorial/index.html
...and other documentation to be found there.

Dive Into Python, by Mark Pilgrim, an excellent book:
http://www.diveintopython.org/

Text Processing in Python, by David Mertz
http://gnosis.cx/TPiP/
looks promising but I haven't read it.

Python is a pretty straightforward and powerful language (to me, at
least; others might disagree). You don't really have to get very deep
into it to write the sort of scripts we're talking about here.

The basic steps I went through were:

Manually design the layout for one item. Create paragraph styles for the
various fonts to be used. You probably have much of this done already.

Write a simple script to create one instance of the item you just
designed on a blank page in Scribus. To set a text box, you'd use
Scribus scripter commands like createText, setText, selectText, and
setStyle.

Modify the script to create the instance at a specific location.

Write code to pull the necessary text out of your database.

Create a way to tell the code, "I want to set member X at location Y"
for some list of members.

Write code to loop through the list, pulling data and setting the
layout for each member.

Open your document in Scribus and invoke your script. Debug and tweak as
necessary.

When it finally does what you want, open a beer and promptly forget
about all the places where you were going to clean up the code.

(As I said, those were the steps *I* went through.)

I've been setting my photos manually, so I don't have experience with
automating images. The code would be simplest if the pictures were
cropped and scaled to a uniform size in the database beforehand.

I hope that's enough to help you decide whether scripting can do what
you need.

Don Strayer



More information about the scribus mailing list