FLOSS Manuals

 English |  Español |  Français |  Italiano |  Português |  Русский |  Shqip

Python Scripting with Scribus


Here is a script which again was a request from someone. What he was looking for was a quick way to hide the images in a document. You can do this manually on the main canvas, but only one by one.

My approach here was to create a new layer in the document, then transfer all the images to that layer, and finally make the layer invisible.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# File: invisibleImages.py


You must have a document open.

This script moves all images to a new layer called "Ghostlayer",
the idea being that you can show/hide, print-export/not as desired.

import scribus

if scribus.haveDoc():

  fantome = "Ghostlayer"
  working = scribus.getActiveLayer()
  page = 1
  pagenum = scribus.pageCount()
  while (page <= pagenum):
    scribus.setActiveLayer(working)  # maybe not necessary?  
    pageitems = scribus.getPageItems()

    for item in pageitems:
      if (item[1] == 2):
    imagebox = item[0]
    page += 1
  scribus.setLayerPrintable(fantome, 0)  # comment this out to do manually later
  scribus.setLayerVisible(fantome, 0)    # comment this out to do manually later
  scribus.messageBox("Finished", "That should do it!",scribus.ICON_NONE,scribus.BUTTON_OK)

    scribus.messageBox('Usage Error', 'You need a Document open', scribus.ICON_NONE,scribus.BUTTON_OK)

The first thing we do is to create our new layer, named fantome. Now, just as we've seen in several other scripts, we go through the document page by page, and on each page getPageItems(), and this time sift out all the image frames. For each frame we select it, copy it, then switch our active layer to fantome and paste there. Once this is done, we can safely delete the original. As I look through this script, I would have thought that I might have needed to switch the active layer back to working, but apparently not, since this does work as desired.

Once all the image frames have been copied and the originals deleted, then we not only make the fantome layer non-printable (which also means that those images would not be exported to PDF), but then make the content invisible.

In case any of your images has Text Flows Around Frame set, this still is in operation. If you want to make your images visible once again, just bring up the Layers dialog and check the appropriate boxes for the layer. This script also would open the possibility for easily making a document with more than one set of images. You would need to modify it by commenting out the line which deletes the original image frames, then load new images into one set or the other. Since the new layer is on top of the old one, making fantome visible only shows the its images.

There has been error in communication with Booktype server. Not sure right now where is the problem.

You should refresh this page.