r22064 by jghali - #14848: add optional page keyword argument to getAllObjects <dockattt>

scribus-commit scribus-commit at lists.scribus.net
Mon Jun 12 19:31:28 UTC 2017


Author: jghali
Date: Mon Jun 12 19:31:27 2017
New Revision: 22064

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22064
Log:
#14848: add optional page keyword argument to getAllObjects <dockattt>

Modified:
    trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
    trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22064&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	Mon Jun 12 19:31:27 2017
@@ -275,15 +275,26 @@
 	return i != NULL ? PyFloat_FromDouble(static_cast<double>(i->rotation() * -1)) : NULL;
 }
 
-PyObject *scribus_getallobj(PyObject* /* self */, PyObject* args)
+PyObject *scribus_getallobj(PyObject* /* self */, PyObject* args, PyObject *keywds)
 {
 	PyObject *l;
 	int typ = -1;
 	uint counter = 0;
 	uint counter2 = 0;
 	uint pageNr = ScCore->primaryMainWindow()->doc->currentPageNumber();
-	if (!PyArg_ParseTuple(args, "|i", &typ))
-		return NULL;
+	char *kwlist[] = {const_cast<char*>(""), const_cast<char*>("page"), NULL};
+
+
+	if (!PyArg_ParseTupleAndKeywords(args, keywds, "|ii", kwlist, &typ, &pageNr))
+		return NULL;
+
+	uint numpages = ScCore->primaryMainWindow()->doc->Pages->count();
+	if(pageNr < 0 || pageNr >= numpages){
+		PyErr_SetString(PyExc_RuntimeError, QObject::tr("page number is invalid.","python error").toLocal8Bit().constData());
+		return NULL;
+	}
+	//if (!PyArg_ParseTuple(args, "|i", &typ))
+	//	return NULL;
 	if(!checkHaveDocument())
 		return NULL;
 	// have doc already

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22064&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	Mon Jun 12 19:31:27 2017
@@ -212,12 +212,14 @@
 
 /*! docstring */
 PyDoc_STRVAR(scribus_getallobj__doc__,
-QT_TR_NOOP("getAllObjects() -> list\n\
+QT_TR_NOOP("getAllObjects([\"page\"]) -> list\n\
 \n\
 Returns a list containing the names of all objects on the current page.\n\
+Takes an optional keyword argument that changes the page from which the objects are returned\n\
+The page index starts at 0 and goes to the total number of pages - 1.\n\
 "));
 /*! Returns a list with all objects in page */
-PyObject *scribus_getallobj(PyObject * /*self*/, PyObject* args);
+PyObject *scribus_getallobj(PyObject * /*self*/, PyObject* args, PyObject *keywds);
 
 /*! docstring */
 PyDoc_STRVAR(scribus_getobjectattributes__doc__,

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22064&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	Mon Jun 12 19:31:27 2017
@@ -337,7 +337,7 @@
 	{const_cast<char*>("fileQuit"), scribus_filequit, METH_VARARGS, tr(scribus_filequit__doc__)},
 	{const_cast<char*>("flipObject"), scribus_flipobject, METH_VARARGS, tr(scribus_flipobject__doc__)},
 	{const_cast<char*>("getActiveLayer"), (PyCFunction)scribus_getactlayer, METH_NOARGS, tr(scribus_getactlayer__doc__)},
-	{const_cast<char*>("getAllObjects"), scribus_getallobj, METH_VARARGS, tr(scribus_getallobj__doc__)},
+	{const_cast<char*>("getAllObjects"), (PyCFunction)scribus_getallobj, METH_VARARGS|METH_KEYWORDS, tr(scribus_getallobj__doc__)},
 	{const_cast<char*>("getAllStyles"), (PyCFunction)scribus_getstylenames, METH_NOARGS, tr(scribus_getstylenames__doc__)},
 	{const_cast<char*>("getCharStyles"), (PyCFunction)scribus_getcharstylenames, METH_NOARGS, tr(scribus_getcharstylenames__doc__)},
 	{const_cast<char*>("getAllText"), scribus_gettext, METH_VARARGS, tr(scribus_gettext__doc__)},




More information about the scribus-commit mailing list