Swap Images
Jump to navigation
Jump to search
Here is a simple script that has one task, to switch the images in 2 selected frames.
This is undo-able, but you will need to click Undo twice, since there are two separate operations in the script.
swapimages.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# ****************************************************************************
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# ****************************************************************************
"""
© 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)