[scribus] Python script for scribus

Gregory Pittman gpittman at iglou.com
Tue Dec 30 03:45:33 CET 2008


Roger wrote:
> <snip>
>>> I have been trying to get python script to past images and text into 
>>> a page in order to automate some of the set up and page layout
>>> I am just learning python and wrote the following .py script from my 
>>> gleaning of the documentation but get an error message:
> </snip  No point in keeping all the previous text.>
>
> Thanks Greg
> I changed to createImage and it works, now inserts text and image as 
> required, however
> The error message remains until I click OK then the inserting goes ahead.
>
> Error message reads:
> Traceback (most recent call last):
>   File "<string>", line 8, in <module>
>   File "/home/roger250/Scribus135/scripts/RM-Sample-header.py", line 
> 51, in <module>
>     main()
>   File "/home/roger250/Scribus135/scripts/RM-Sample-header.py", line 
> 43, in main
>     scaleImage(1,1)
> NoValidObjectError: Cannot use empty string for object name when there 
> is no selection
>
>     selectfile = fileDialog("Navigate to images directory and select 
> to place on page", "*.*")
> Hard coding /path/to/image.jpg returns the same error message and 
> script fails.
> Hard coding/path/to/folder into the above returns an empty dialog 
> selector from which I can choose one directory only, it then fails 
> with same error message.
> My images are permanently in /Pictures/folder1/. not in a Scribus 
> directory.
>
>
> Image is inserted with:
>
>         d = createImage(33, 20, 32, 32)
> #       loadImage("filename" [, "name"])
> #          loadImage(selectfile,header)
>
>         loadImage(selectfile,d)
>         scaleImage(1,1)
> ScaleImage does not work regardless of scale setting.
> It inputs at 50 percent even though the image and image box are same 
> dimensions.
Perhaps adding the name of the frame would help:
scaleImage(1,1,d)

but at the same time the default is to load an image at 100%, so if 
you're carefully sizing the frame, then this should be unnecessary.

Look at this piece of InfoBox.py that comes with 135svn:

        imageload = scribus.fileDialog('Load image','Images(*.jpg *.png 
*.tif *.JPG *.PNG *.jpeg *.JPEG *.TIF)',haspreview=1)
        im = Image.open(imageload)
        xsize, ysize = im.size
        new_height = float(ysize)/float(xsize)*new_width
        new_image = scribus.createImage(new_left, float(new_top), 
new_width, float(new_height),framename)
        scribus.loadImage(imageload, new_image)

First, there is the fileDialog to pick the image file.
Next, the script uses some commands from PIL, the python imaging library 
(requires 'from PIL import Image' at the beginning of your script). This 
loads the file so that the dimensions can be measured, then we use these 
to size the frame appropriately -- this script fits an image into a 
column to fill the width of the column.
Maybe this can be of some use now or in the future.

Greg




More information about the scribus mailing list