View Issue Details

IDProjectCategoryView StatusLast Update
0012757ScribusScripterpublic2014-10-14 20:07
Reporterwilliam Assigned Tocbradney  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
PlatformIntel 64 bitOSFedora LinuxOS Version20
Fixed in Version1.4.5.svn 
Summary0012757: [patch] Add applyMasterPage command to scripter in Scribus 1.4
DescriptionThis patch by Juraj creates a scribus.applyMasterPage(name, page) function where name is a master page and page is a page number.
Steps To ReproduceTest script:

import scribus

scribus.newDocument(scribus.PAPER_A4, (15,15, 20, 20), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.PAGE_2, 1, 8)

def create_mp(name):
    scribus.createMasterPage(name)
    scribus.editMasterPage(name)
    txt=scribus.createText(250, 70, 120, 30)
    scribus.setText(name, txt)
    scribus.closeMasterPage()
    return name

odd = create_mp('Odd Master Page')
even = create_mp('Even Master Page')

for p in range(8):
    page = p+1
    name = odd
    if page%2 == 0:
        name = even
    print (name, page)
    scribus.applyMasterPage(name, page)

scribus.saveDocAs('masterpage.sla')

pdf = scribus.PDFfile()
pdf.save()

#scribus.applyMasterPage('Wrong Name', 1)
#scribus.applyMasterPage(even, 42)
TagsNo tags attached.
Patch

Activities

william

2014-10-08 17:49

updater  

0001-Add-applyMasterPage-command-to-scripter.patch (4,344 bytes)   
From 19cff5c45b73f93941450e46f3bd1e934b721169 Mon Sep 17 00:00:00 2001
From: Juraj Fedel <wtxnh-scribus@yahoo.com.au>
Date: Wed, 8 Oct 2014 17:25:54 +0200
Subject: [PATCH] Add applyMasterPage command to scripter

---
 scribus/plugins/scriptplugin/cmddoc.cpp       |   31 +++++++++++++++++++++++++
 scribus/plugins/scriptplugin/cmddoc.h         |    7 +++++
 scribus/plugins/scriptplugin/scriptplugin.cpp |    1 +
 3 files changed, 39 insertions(+), 0 deletions(-)

diff --git a/scribus/plugins/scriptplugin/cmddoc.cpp b/scribus/plugins/scriptplugin/cmddoc.cpp
index b42862b..02acd2e 100644
--- a/scribus/plugins/scriptplugin/cmddoc.cpp
+++ b/scribus/plugins/scriptplugin/cmddoc.cpp
@@ -367,6 +367,36 @@ PyObject* scribus_deletemasterpage(PyObject* /* self */, PyObject* args)
 	Py_RETURN_NONE;
 }
 
+PyObject* scribus_applymasterpage(PyObject* /* self */, PyObject* args)
+{
+	char* name = 0;
+	int page = 0;
+	if (!PyArg_ParseTuple(args, "esi", const_cast<char*>("utf-8"), &name, &page))
+		return NULL;
+	if(!checkHaveDocument())
+		return NULL;
+	const QString masterPageName(name);
+	if (!ScCore->primaryMainWindow()->doc->MasterNames.contains(masterPageName))
+	{
+		PyErr_SetString(PyExc_ValueError, QObject::tr("Master page does not exist: '%1'","python error").arg(masterPageName).toLocal8Bit().constData());
+		return NULL;
+	}
+	if ((page < 1) || (page > static_cast<int>(ScCore->primaryMainWindow()->doc->Pages->count())))
+	{
+		PyErr_SetString(PyExc_IndexError, QObject::tr("Page number out of range: %1.","python error").arg(page).toLocal8Bit().constData());
+		return NULL;
+	}
+
+	if (!ScCore->primaryMainWindow()->doc->applyMasterPage(masterPageName, page-1))
+	{
+		PyErr_SetString(ScribusException, QObject::tr("Failed to apply masterpage '%1' on page: %2","python error").arg(masterPageName).arg(page).toLocal8Bit().constData());
+		return NULL;
+	}
+//	Py_INCREF(Py_None);
+//	return Py_None;
+	Py_RETURN_NONE;
+}
+
 /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
 with header files structure untouched (docstrings are kept near declarations)
 PV */
@@ -374,4 +404,5 @@ void cmddocdocwarnings()
 {
     QStringList s;
     s << scribus_newdocument__doc__ << scribus_newdoc__doc__ <<  scribus_closedoc__doc__ << scribus_havedoc__doc__ << scribus_opendoc__doc__ << scribus_savedoc__doc__ << scribus_getdocname__doc__ << scribus_savedocas__doc__ << scribus_setinfo__doc__ <<scribus_setmargins__doc__ <<scribus_setunit__doc__ <<scribus_getunit__doc__ <<scribus_loadstylesfromfile__doc__ <<scribus_setdoctype__doc__ <<scribus_closemasterpage__doc__ <<scribus_masterpagenames__doc__ <<scribus_editmasterpage__doc__ <<scribus_createmasterpage__doc__ <<scribus_deletemasterpage__doc__;
+    s << scribus_applymasterpage__doc__;
 }
diff --git a/scribus/plugins/scriptplugin/cmddoc.h b/scribus/plugins/scriptplugin/cmddoc.h
index 9c45acf..9e057f3 100644
--- a/scribus/plugins/scriptplugin/cmddoc.h
+++ b/scribus/plugins/scriptplugin/cmddoc.h
@@ -266,5 +266,12 @@ Delete the named master page.\n\
 "));
 PyObject* scribus_deletemasterpage(PyObject* self, PyObject* args);
 
+PyDoc_STRVAR(scribus_applymasterpage__doc__,
+QT_TR_NOOP("applyMasterPage(mastePageName, pageNumber)\n\
+\n\
+Apply master page masterPageName on page pageNumber.\n\
+"));
+PyObject* scribus_applymasterpage(PyObject* self, PyObject* args);
+
 #endif
 
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 539a8fb..3ad778d 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -280,6 +280,7 @@ char* tr(const char* docstringConstant)
 PyMethodDef scribus_methods[] = {
 	// 2004/10/03 pv - aliases with common Python syntax - ClassName methodName
 	// 2004-11-06 cr - move aliasing to dynamically generated wrapper functions, sort methoddef
+	{const_cast<char*>("applyMasterPage"), scribus_applymasterpage, METH_VARARGS, tr(scribus_applymasterpage__doc__)},
 	{const_cast<char*>("changeColor"), scribus_setcolor, METH_VARARGS, tr(scribus_setcolor__doc__)},
 	{const_cast<char*>("closeDoc"), (PyCFunction)scribus_closedoc, METH_NOARGS, tr(scribus_closedoc__doc__)},
 	{const_cast<char*>("closeMasterPage"), (PyCFunction)scribus_closemasterpage, METH_NOARGS, tr(scribus_closemasterpage__doc__)},
-- 
1.7.2.3

Kunda

2014-10-08 19:42

updater   ~0033938

When you 'Report Issue' there should be a place for you to specify which Scribus Project to post under. It seems the 'Contributor Builds' keeps getting used instead of 'Scribus'. Perhaps 'Contributor Builds' was set to default and you don't get prompted anymore. Can you confirm ?

Issue History

Date Modified Username Field Change
2014-10-08 17:49 william New Issue
2014-10-08 17:49 william File Added: 0001-Add-applyMasterPage-command-to-scripter.patch
2014-10-08 19:41 Kunda Project Contributor Builds => Scribus
2014-10-08 19:42 Kunda Note Added: 0033938
2014-10-08 19:51 cbradney Status new => resolved
2014-10-08 19:51 cbradney Fixed in Version => 1.4.5.svn
2014-10-08 19:51 cbradney Resolution open => fixed
2014-10-08 19:51 cbradney Assigned To => cbradney
2014-10-09 00:05 Kunda Category General => Scripter
2014-10-14 20:07 cbradney Status resolved => closed