View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0015959 | Scribus | Scripter | public | 2019-11-22 18:10 | 2019-12-08 21:24 |
Reporter | ale | Assigned To | ale | ||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Product Version | 1.5.6.svn | ||||
Fixed in Version | 1.5.6.svn | ||||
Summary | 0015959: Scripter: add setItemName() | ||||
Description | since we all love the items names... | ||||
Tags | No tags attached. | ||||
Patch | Yes | ||||
|
scripter-set-name.diff (4,030 bytes)
diff --git a/scribus/plugins/scriptplugin/cmdobj.cpp b/scribus/plugins/scriptplugin/cmdobj.cpp index 61c14baa9..59cf77768 100644 --- a/scribus/plugins/scriptplugin/cmdobj.cpp +++ b/scribus/plugins/scriptplugin/cmdobj.cpp @@ -827,6 +827,24 @@ PyObject *scribus_getcharstylenames(PyObject* /* self */) return charStyleList; } +PyObject *scribus_setobjectname(PyObject * /* self */, PyObject *args) +{ + char* name = const_cast<char*>(""); + char* newName = const_cast<char*>(""); + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &newName, "utf-8", &name)) + return nullptr; + if (!checkHaveDocument()) + return nullptr; + + ScribusMainWindow* currentWin = ScCore->primaryMainWindow(); + ScribusDoc* currentDoc = currentWin->doc; + + PageItem* item = GetItem(QString::fromUtf8(name)); + item->setItemName(newName); + + return PyUnicode_FromString(item->itemName().toUtf8()); +} + PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args) { char* name = const_cast<char*>(""); @@ -896,5 +914,5 @@ PV */ void cmdobjdocwarnings() { QStringList s; - s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newtable__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_getstyle__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_getcharstylenames__doc__ <<scribus_duplicateobject__doc__ <<scribus_copyobject__doc__ <<scribus_pasteobject__doc__; + s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newtable__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_getstyle__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_getcharstylenames__doc__ <<scribus_setobjectname__doc__ <<scribus_duplicateobject__doc__ <<scribus_copyobject__doc__ <<scribus_pasteobject__doc__; } diff --git a/scribus/plugins/scriptplugin/cmdobj.h b/scribus/plugins/scriptplugin/cmdobj.h index 68fad185c..2458f5323 100644 --- a/scribus/plugins/scriptplugin/cmdobj.h +++ b/scribus/plugins/scriptplugin/cmdobj.h @@ -301,6 +301,17 @@ Return a list of the names of all character styles in the current document.\n\ ")); PyObject *scribus_getcharstylenames(PyObject * /*self*/); +/*! docstring */ +PyDoc_STRVAR(scribus_setobjectname__doc__, +QT_TR_NOOP("setItemName(\"newName\"[, \"name\"]) -> string\n\ +\n\ +Sets a new name to the item and returns the name applied.\n\ +")); +/** + Ale Rimoldi, 2019-11-22 + Set the name of an item +*/ +PyObject *scribus_setobjectname(PyObject * /* self */, PyObject *args); /*! docstring */ PyDoc_STRVAR(scribus_duplicateobject__doc__, diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp index d76ccba7b..8b0715da7 100644 --- a/scribus/plugins/scriptplugin/scriptplugin.cpp +++ b/scribus/plugins/scriptplugin/scriptplugin.cpp @@ -574,6 +575,7 @@ PyMethodDef scribus_methods[] = { // {const_cast<char*>("getChildren"), (PyCFunction)scribus_getchildren, METH_VARARGS|METH_KEYWORDS, tr(scribus_getchildren__doc__)}, // {const_cast<char*>("getChild"), (PyCFunction)scribus_getchild, METH_VARARGS|METH_KEYWORDS, tr(scribus_getchild__doc__)}, // by Christian Hausknecht + {const_cast<char*>("setItemName"), scribus_setobjectname, METH_VARARGS, tr(scribus_setobjectname__doc__)}, {const_cast<char*>("duplicateObject"), scribus_duplicateobject, METH_VARARGS, tr(scribus_duplicateobject__doc__)}, {const_cast<char*>("copyObject"), scribus_copyobject, METH_VARARGS, tr(scribus_copyobject__doc__)}, {const_cast<char*>("pasteObject"), scribus_pasteobject, METH_VARARGS, tr(scribus_pasteobject__doc__)}, |
|
There is in fact already a similar setNewName() function which does not return a value (it should), which is currently not documented and which is currently defined in the cmdsetprop.cpp file (see scribus_setnewname...). Afterwards comes a small philosophical question about the name we should give to this function: setItemName or setObjectName (as we already have setObjectAttributes)? |
|
i looked for it and did not found. i would remove setNewName() since it's not documented, it's in the "wrong" file (well, the logic of the names and implementation in files is hard to follow anyway and there is lot often a lot of guessing needed to find things...), has a "useless" new in the name (every set is a new value...) and does not return the name. i've looked at the existing implementation and slightly modified the one of mine. it's atttached as you see from the patch, i also was in doubt between setObject and setItem and decided for item. i've left "object" in the internal functions for compatibility with the other functions. if you want to use oject, i'm fine with it. but, personally, i think that setObjectAttributes should be first aliased and then replaced by setAttributes()... scripter-set-name-02.diff (2,949 bytes)
diff --git a/scribus/plugins/scriptplugin/cmdobj.cpp b/scribus/plugins/scriptplugin/cmdobj.cpp index 61c14baa9..465992a59 100644 --- a/scribus/plugins/scriptplugin/cmdobj.cpp +++ b/scribus/plugins/scriptplugin/cmdobj.cpp @@ -827,6 +827,24 @@ PyObject *scribus_getcharstylenames(PyObject* /* self */) return charStyleList; } +PyObject *scribus_setobjectname(PyObject * /* self */, PyObject *args) +{ + char* name = const_cast<char*>(""); + char* newName = const_cast<char*>(""); + if (!PyArg_ParseTuple(args, "es|es", "utf-8", &newName, "utf-8", &name)) + return nullptr; + if (!checkHaveDocument()) + return nullptr; + + PageItem* item = GetUniqueItem(QString::fromUtf8(name)); + if (item == nullptr) + return nullptr; + + item->setItemName(newName); + + return PyUnicode_FromString(item->itemName().toUtf8()); +} + PyObject *scribus_duplicateobject(PyObject * /* self */, PyObject *args) { char* name = const_cast<char*>(""); @@ -896,5 +914,5 @@ PV */ void cmdobjdocwarnings() { QStringList s; - s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newtable__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_getstyle__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_getcharstylenames__doc__ <<scribus_duplicateobject__doc__ <<scribus_copyobject__doc__ <<scribus_pasteobject__doc__; + s << scribus_newrect__doc__ <<scribus_newellipse__doc__ << scribus_newimage__doc__ << scribus_newtext__doc__ << scribus_newtable__doc__ << scribus_newline__doc__ <<scribus_polyline__doc__ << scribus_polygon__doc__ << scribus_bezierline__doc__ <<scribus_pathtext__doc__ <<scribus_deleteobj__doc__ <<scribus_textflow__doc__ <<scribus_objectexists__doc__ <<scribus_getstyle__doc__ <<scribus_setstyle__doc__ <<scribus_getstylenames__doc__ <<scribus_getcharstylenames__doc__ <<scribus_setobjectname__doc__ <<scribus_duplicateobject__doc__ <<scribus_copyobject__doc__ <<scribus_pasteobject__doc__; } diff --git a/scribus/plugins/scriptplugin/cmdobj.h b/scribus/plugins/scriptplugin/cmdobj.h index 68fad185c..2458f5323 100644 --- a/scribus/plugins/scriptplugin/cmdobj.h +++ b/scribus/plugins/scriptplugin/cmdobj.h @@ -301,6 +301,17 @@ Return a list of the names of all character styles in the current document.\n\ ")); PyObject *scribus_getcharstylenames(PyObject * /*self*/); +/*! docstring */ +PyDoc_STRVAR(scribus_setobjectname__doc__, +QT_TR_NOOP("setItemName(\"newName\"[, \"name\"]) -> string\n\ +\n\ +Sets a new name to the item and returns the name applied.\n\ +")); +/** + Ale Rimoldi, 2019-11-22 + Set the name of an item +*/ +PyObject *scribus_setobjectname(PyObject * /* self */, PyObject *args); /*! docstring */ PyDoc_STRVAR(scribus_duplicateobject__doc__, |
|
>> it's in the "wrong" file No, I'd say it's in the right file. |
|
as said, as a scripter user those file are a mystery. the distinction between manipulating objects and setting object properties looks arbitrary. if possible please, change the name of the function (setItemName or setObjectName; it's not used in the scribus scripts and is not documented), add the name as the return value, and add documentation for it). i don't think there is much need for a long discussion... |
Date Modified | Username | Field | Change |
---|---|---|---|
2019-11-22 18:10 | ale | New Issue | |
2019-11-22 18:10 | ale | File Added: scripter-set-name.diff | |
2019-11-23 02:02 | jghali | Note Added: 0047117 | |
2019-11-23 09:42 | ale | File Added: scripter-set-name-02.diff | |
2019-11-23 09:42 | ale | Note Added: 0047118 | |
2019-11-23 10:58 | jghali | Note Added: 0047119 | |
2019-11-23 11:51 | jghali | Assigned To | => ale |
2019-11-23 11:51 | jghali | Status | new => resolved |
2019-11-23 11:51 | jghali | Resolution | open => fixed |
2019-11-23 11:51 | jghali | Fixed in Version | => 1.5.6.svn |
2019-11-23 11:51 | jghali | Summary | [PATCH] Scripter: setItemName() => Scripter: add setItemName() |
2019-11-23 13:34 | ale | Note Added: 0047121 | |
2019-12-08 21:24 | cbradney | Status | resolved => closed |