[scribus] another (revised) senseless script from Greg

Gregory Pittman gpittman at iglou.com
Mon Aug 20 01:51:03 UTC 2012


On 08/19/2012 09:29 PM, Gregory Pittman wrote:
> Here is an intellectual exercise. Let's imagine you want to play with 
> a layout by swapping images from one frame and another, maybe even 
> frames on different pages.
>
> Here is a script that does just that. If you don't like what you get, 
> just run it again -- Undo seems to work, but AFAICT you have to undo 
> twice to reverse the effects of the script. Note that the frames are 
> not swapped, just the image content.
>
I found it wise/necessary to revise the script by moving the 
setRedraw(False) farther down. This prevents messing up the display of 
your frames if you hit one of the errors -- the images visually disappear.

Alternatively, the script works fine without either the setRedraw(False) 
or the setRedraw(True) commands there at all.

***revised script follows****

#!/usr/bin/env python
# -*- coding: utf-8  -*-

"""

© 2012 Gregory Pittman

swapimage.py

USAGE

Select 2 image frames, no more, no less, both must be image frames. Can 
be on different
pages.

Run the script, the images are swapped.

"""

try:
     import scribus
except ImportError:
     print "Unable to import the 'scribus' module. This script will only 
run within"
     print "the Python interpreter embedded in Scribus. Try 
Script->Execute Script."
     sys.exit(1)


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

frame1 = scribus.getSelectedObject(0)
frame2 = scribus.getSelectedObject(1)

ftype1 = scribus.getObjectType(frame1)
ftype2 = scribus.getObjectType(frame2)
if ((ftype1 != "ImageFrame") or (ftype2 != "ImageFrame")):
     scribus.messageBox('Object Type', "Both selected objects must be 
image frames",
                        scribus.ICON_WARNING, scribus.BUTTON_OK)
     sys.exit(2)

scribus.setRedraw(False)

filename1 = scribus.getImageFile(frame1)
filename2 = scribus.getImageFile(frame2)

scribus.loadImage(filename2, frame1)
scribus.loadImage(filename1, frame2)

scribus.setRedraw(True)





More information about the scribus mailing list