View Issue Details

IDProjectCategoryView StatusLast Update
0014848ScribusScripterpublic2017-12-20 20:59
Reporterdockattt Assigned Tojghali  
PrioritynormalSeveritytweakReproducibilityalways
Status closedResolutionfixed 
Product Version1.5.4.svn 
Fixed in Version1.5.4.svn 
Summary0014848: add optional page keyword argument to getAllObjects
Descriptionthe python function getAllObjects returns all the objects on the current page. It can be made more useful if it can query other pages with a new keyword argument. The attached patch adds the code and some documentation that makes this work.

There also is an undocumented filter/argument in the function(this wasn't added with the patch). Should what it does be put in the pydoc?
Steps To ReproducegetAllObjects()
getAllObjects(page=apagenumber)
TagsNo tags attached.
PatchYes

Activities

dockattt

2017-06-04 16:53

reporter  

getallobjects.patch (3,465 bytes)   
Index: Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	(revision 22051)
+++ Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp	(working copy)
@@ -275,7 +275,7 @@
 	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;
@@ -282,8 +282,19 @@
 	uint counter = 0;
 	uint counter2 = 0;
 	uint pageNr = ScCore->primaryMainWindow()->doc->currentPageNumber();
-	if (!PyArg_ParseTuple(args, "|i", &typ))
+	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
Index: Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
===================================================================
--- Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	(revision 22051)
+++ Scribus/scribus/plugins/scriptplugin/cmdgetprop.h	(working copy)
@@ -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__,
Index: Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
===================================================================
--- Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(revision 22051)
+++ Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp	(working copy)
@@ -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__)},
getallobjects.patch (3,465 bytes)   

jghali

2017-06-12 19:31

administrator   ~0044046

Patch applied, thanks!

Issue History

Date Modified Username Field Change
2017-06-04 16:53 dockattt New Issue
2017-06-04 16:53 dockattt File Added: getallobjects.patch
2017-06-12 19:31 jghali Assigned To => jghali
2017-06-12 19:31 jghali Status new => resolved
2017-06-12 19:31 jghali Resolution open => fixed
2017-06-12 19:31 jghali Fixed in Version => 1.5.4.svn
2017-06-12 19:31 jghali Note Added: 0044046
2017-12-20 20:59 cbradney Status resolved => closed