Using the new applyMasterPage() command

From Scribus Wiki
Revision as of 02:01, 10 October 2014 by Gpittman (talk | contribs) (Created page with "{{Scripting Index}} Here is an initial script which makes use of the new '''applyMasterPage()''' command now in 1.4.5svn and 1.5.0svn versions of Scribus. This particular sc...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
This article is part of the Scripts series.

Here is an initial script which makes use of the new applyMasterPage() command now in 1.4.5svn and 1.5.0svn versions of Scribus. This particular script takes some of its structure from paste2pagelist.py, which was written for the recently added copyObject() and pasteObject() commands.

assignMP.py

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# assignMP.py
# © Gregory Pittman 2014-10-09
# 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.
"""
USAGE
You must have a document open. You will presumably have more than one 
Master Page, since otherwise the script makes little sense.

The first dialog shows a numbered list of your Master Pages, and asks
you to choose which one to apply by number.

Next you are asked for a list of pages to assign this MP to.
At the end you are left in the Edit Master Page mode. This is a kludge 
to make sure that the document refreshes to show your new MP assignments.

"""
import scribus

if scribus.haveDoc():
    scribus.setRedraw(0)
    mpnames = scribus.masterPageNames()
    mps = ""
    item = 0
    for mp in mpnames:
      mps = mps + str(item) + " " + mp + "\n"
      item += 1
    masterPage = scribus.valueDialog('Master Pages', "Here are your Master Pages: \n" + mps +"\n Choose the number of the MP to assign", "0")
    pagelist = scribus.valueDialog('Assign Master Page to...',"Paste to which pages?\n(page numbers, separated by white space)","1")
    pageslist = pagelist.split()
    pages = scribus.pageCount()
    for p in pageslist:
        p_no = int(p)
        if ((p_no > pages) or (p_no < 1)):
            scribus.messageBox('OOPS!', "You have a page number outside the range of pages in your document", scribus.ICON_WARNING, scribus.BUTTON_OK)
            sys.exit(2)

    for p in pageslist:
	p_no = int(p)
	scribus.gotoPage(p_no)
	scribus.applyMasterPage(mpnames[int(masterPage)], p_no)
    scribus.editMasterPage(mpnames[int(masterPage)])
    scribus.setRedraw(1)
    scribus.redrawAll()
    scribus.docChanged(1)
    scribus.messageBox("Finished", "Done",icon=0,button1=1)

else:
    scribus.messageBox('Usage Error', 'You need a Document open', icon=0, button1=1)
    sys.exit(2)