r21858 by jghali - #8118: Allow get/set of item attributes in scripter <jurajF>
scribus-commit
scribus-commit at lists.scribus.net
Sat Apr 1 19:58:06 UTC 2017
Author: jghali
Date: Sat Apr 1 19:58:06 2017
New Revision: 21858
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=21858
Log:
#8118: Allow get/set of item attributes in scripter <jurajF>
Modified:
trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.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=21858&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp Sat Apr 1 19:58:06 2017
@@ -327,6 +327,47 @@
return l;
}
+PyObject *scribus_getobjectattributes(PyObject* /* self */, PyObject* args)
+{
+ if(!checkHaveDocument())
+ return NULL;
+ char *Name = const_cast<char*>("");
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+ return NULL;
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+
+ ObjAttrVector *attributes=item->getObjectAttributes();
+ PyObject *lst;
+ lst = PyList_New(attributes->count());
+ if (!lst)
+ return NULL;
+ int n = 0;
+ for (ObjAttrVector::Iterator objAttrIt = attributes->begin() ; objAttrIt != attributes->end(); ++objAttrIt)
+ {
+ PyObject *tmp;
+ tmp = Py_BuildValue("{ssssssssssssss}",
+ "Name", objAttrIt->name.toUtf8().data(),
+ "Type", objAttrIt->type.toUtf8().data(),
+ "Value", objAttrIt->value.toUtf8().data(),
+ "Parameter", objAttrIt->parameter.toUtf8().data(),
+ "Relationship", objAttrIt->relationship.toUtf8().data(),
+ "RelationshipTo", objAttrIt->relationshipto.toUtf8().data(),
+ "AutoAddTo", objAttrIt->autoaddto.toUtf8().data());
+ if (tmp)
+ PyList_SetItem(lst, n, tmp);
+ else {
+ // Error string is already set by Py_BuildValue()
+ Py_DECREF(lst);
+ return NULL;
+ }
+ n++;
+ }
+ return lst;
+}
+
+
/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
with header files structure untouched (docstrings are kept near declarations)
PV */
@@ -342,5 +383,6 @@
<< scribus_getfillshade__doc__ << scribus_getcornerrad__doc__
<< scribus_getimgscale__doc__ << scribus_getimagefile__doc__
<< scribus_getposi__doc__ << scribus_getsize__doc__
- << scribus_getrotation__doc__ << scribus_getallobj__doc__;
-}
+ << scribus_getrotation__doc__ << scribus_getallobj__doc__
+ << scribus_getobjectattributes__doc__;
+}
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21858&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.h Sat Apr 1 19:58:06 2017
@@ -219,5 +219,12 @@
/*! Returns a list with all objects in page */
PyObject *scribus_getallobj(PyObject * /*self*/, PyObject* args);
+/*! docstring */
+PyDoc_STRVAR(scribus_getobjectattributes__doc__,
+QT_TR_NOOP("getObjectAttributes([\"name\"]) -> list\n\
+Returns a list containing all attributes of object \"name\".\n\
+"));
+PyObject *scribus_getobjectattributes(PyObject * /*self*/, PyObject* args);
+
#endif
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21858&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.cpp Sat Apr 1 19:58:06 2017
@@ -397,6 +397,111 @@
Py_RETURN_NONE;
}
+PyObject *scribus_setobjectattributes(PyObject* /* self */, PyObject* args)
+{
+ if(!checkHaveDocument())
+ return NULL;
+ char *Name = const_cast<char*>("");
+ PyObject *attr;
+ if (!PyArg_ParseTuple(args, "O|es", &attr, "utf-8", &Name))
+ return NULL;
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == NULL)
+ return NULL;
+
+ if (!PyList_Check(attr)) {
+ PyErr_SetString(PyExc_TypeError, "argument must be list.");
+ return NULL;
+ }
+
+ ObjAttrVector attributes;
+ int n = PyList_Size(attr);
+ for (int i=0; i<n; ++i) {
+ PyObject *tmp = PyList_GetItem(attr, i);
+ if (!PyDict_Check(tmp)) {
+ PyErr_SetString(PyExc_TypeError, "elemets of 'attr' must be dictionary.");
+ return NULL;
+ }
+ ObjectAttribute blank;
+ PyObject *val;
+ char* data;
+
+ val = PyDict_GetItemString(tmp, "Name");
+ if (!val) {
+ PyErr_SetString(PyExc_TypeError, "attribute does not have 'Name' key.");
+ return NULL;
+ }
+ data = PyString_AsString(val);
+ if (!data)
+ return NULL;
+ blank.name = QString(data);
+
+ val = PyDict_GetItemString(tmp, "Type");
+ if (!val) {
+ PyErr_SetString(PyExc_TypeError, "attribute does not have 'Type' key.");
+ return NULL;
+ }
+ data = PyString_AsString(val);
+ if (!data)
+ return NULL;
+ blank.type = QString(data);
+
+ val = PyDict_GetItemString(tmp, "Value");
+ if (!val) {
+ PyErr_SetString(PyExc_TypeError, "attribute does not have 'Value' key.");
+ return NULL;
+ }
+ data = PyString_AsString(val);
+ if (!data)
+ return NULL;
+ blank.value = QString(data);
+
+ val = PyDict_GetItemString(tmp, "Parameter");
+ if (!val) {
+ PyErr_SetString(PyExc_TypeError, "attribute does not have 'Parameter' key.");
+ return NULL;
+ }
+ data = PyString_AsString(val);
+ if (!data)
+ return NULL;
+ blank.parameter = QString(data);
+
+ val = PyDict_GetItemString(tmp, "Relationship");
+ if (!val) {
+ PyErr_SetString(PyExc_TypeError, "attribute does not have 'Relationship' key.");
+ return NULL;
+ }
+ data = PyString_AsString(val);
+ if (!data)
+ return NULL;
+ blank.relationship = QString(data);
+
+ val = PyDict_GetItemString(tmp, "RelationshipTo");
+ if (!val) {
+ PyErr_SetString(PyExc_TypeError, "attribute does not have 'RelationshipTo' key.");
+ return NULL;
+ }
+ data = PyString_AsString(val);
+ if (!data)
+ return NULL;
+ blank.relationshipto = QString(data);
+
+ val = PyDict_GetItemString(tmp, "AutoAddTo");
+ if (!val) {
+ PyErr_SetString(PyExc_TypeError, "attribute does not have 'AutoAddTo' key.");
+ return NULL;
+ }
+ data = PyString_AsString(val);
+ if (!data)
+ return NULL;
+ blank.autoaddto = QString(data);
+
+ attributes.append(blank);
+ }
+
+ item->setObjectAttributes(&attributes);
+ Py_RETURN_NONE;
+}
/*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings
with header files structure untouched (docstrings are kept near declarations)
@@ -412,5 +517,5 @@
<< scribus_setlinejoin__doc__ << scribus_setlinecap__doc__
<< scribus_setlinestyle__doc__ << scribus_setfillshade__doc__
<< scribus_setcornerrad__doc__ << scribus_setmultiline__doc__
- << scribus_setnewname__doc__;
-}
+ << scribus_setnewname__doc__ << scribus_setobjectattributes__doc__;
+}
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21858&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdsetprop.h Sat Apr 1 19:58:06 2017
@@ -204,5 +204,21 @@
"));
/*! Set newname */
PyObject *scribus_setnewname(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
+PyDoc_STRVAR(scribus_setobjectattributes__doc__,
+QT_TR_NOOP("seObjectAttributes(attritbutes, [\"name\"])\n\
+\n\
+Sets attributes of the object \"name\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+\n\
+attributes is list of dictionary. Each dictionary must have those keys:\n\
+Name, Type, Value, Parameter, Relationship, RelationshipTo, AutoAddTo\n\
+All values must be strings.\n\
+\n\
+May raise NotFoundError if the object doesn't exist.\n\
+"));
+PyObject *scribus_setobjectattributes(PyObject * /*self*/, PyObject* args);
+
#endif
Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=21858&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp Sat Apr 1 19:58:06 2017
@@ -389,6 +389,7 @@
{const_cast<char*>("getPosition"), scribus_getposi, METH_VARARGS, tr(scribus_getposi__doc__)},
{const_cast<char*>("getRotation"), scribus_getrotation, METH_VARARGS, tr(scribus_getrotation__doc__)},
{const_cast<char*>("getObjectType"), scribus_getobjecttype, METH_VARARGS, tr(scribus_getobjecttype__doc__)},
+ {const_cast<char*>("getObjectAttributes"), scribus_getobjectattributes, METH_VARARGS, tr(scribus_getobjectattributes__doc__)},
{const_cast<char*>("getSelectedObject"), scribus_getselobjnam, METH_VARARGS, tr(scribus_getselobjnam__doc__)},
{const_cast<char*>("getSize"), scribus_getsize, METH_VARARGS, tr(scribus_getsize__doc__)},
{const_cast<char*>("getTableRows"), scribus_gettablerows, METH_VARARGS, tr(scribus_gettablerows__doc__)},
@@ -523,6 +524,7 @@
{const_cast<char*>("setMultiLine"), scribus_setmultiline, METH_VARARGS, tr(scribus_setmultiline__doc__)},
{const_cast<char*>("setNewName"), scribus_setnewname, METH_VARARGS, tr(scribus_setnewname__doc__)},
// duplicity? {"setMultiLine", scribus_setmultiline, METH_VARARGS, "TODO: docstring"},
+ {const_cast<char*>("setObjectAttributes"), scribus_setobjectattributes, METH_VARARGS, tr(scribus_setobjectattributes__doc__)},
{const_cast<char*>("setRedraw"), scribus_setredraw, METH_VARARGS, tr(scribus_setredraw__doc__)},
// missing? {"setSelectedObject", scribus_setselobjnam, METH_VARARGS, "Returns the Name of the selecteted Object. \"nr\" if given indicates the Number of the selected Object, e.g. 0 means the first selected Object, 1 means the second selected Object and so on."},
{const_cast<char*>("hyphenateText"), scribus_hyphenatetext, METH_VARARGS, tr(scribus_hyphenatetext__doc__)},
More information about the scribus-commit
mailing list