View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0017079 | Scribus | Scripter | public | 2023-12-17 20:59 | 2023-12-24 10:00 |
Reporter | ale | Assigned To | cbradney | ||
Priority | normal | Severity | minor | Reproducibility | have not tried |
Status | closed | Resolution | fixed | ||
Fixed in Version | 1.6.0.svn | ||||
Summary | 0017079: PATCH: scripter: create setRotation(), deprecate rotateObjectAbs() and add a way to use a specific basepoint | ||||
Description | i propose to - create a new setRotation() (as a companion to getRotation()) - deprecate rotateObjectAbs() - add a basepoint=None named argument to setRotation() | ||||
Tags | No tags attached. | ||||
Patch | Yes | ||||
|
here is a patch set-rotation.diff (6,927 bytes)
diff --git a/scribus/plugins/scriptplugin/cmdmani.cpp b/scribus/plugins/scriptplugin/cmdmani.cpp index ce0ea2ba3..18ec52595 100644 --- a/scribus/plugins/scriptplugin/cmdmani.cpp +++ b/scribus/plugins/scriptplugin/cmdmani.cpp @@ -316,18 +316,41 @@ PyObject *scribus_rotateobjectrel(PyObject* /* self */, PyObject* args) Py_RETURN_NONE; } -PyObject *scribus_rotateobjectabs(PyObject* /* self */, PyObject* args) +PyObject *scribus_setrotation(PyObject* /* self */, PyObject* args, PyObject* kw) { - char *Name = const_cast<char*>(""); - double x; - if (!PyArg_ParseTuple(args, "d|es", &x, "utf-8", &Name)) + + double rotation; + char* name = const_cast<char*>(""); + int basepoint = (int) AnchorPoint::None; + char* kwargs[] = { + const_cast<char*>("rotation"), + const_cast<char*>("name"), + const_cast<char*>("basepoint"), + nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "d|esi", kwargs, &rotation, "utf-8", &name, &basepoint)) return nullptr; + if (!checkHaveDocument()) return nullptr; - PageItem *item = GetUniqueItem(QString::fromUtf8(Name)); + + PageItem *item = GetUniqueItem(QString::fromUtf8(name)); if (item == nullptr) return nullptr; - ScCore->primaryMainWindow()->doc->rotateItem(x * -1.0, item); + + AnchorPoint oldBasePoint = AnchorPoint::None; + if (basepoint != (int) AnchorPoint::None) + { + oldBasePoint = ScCore->primaryMainWindow()->doc->rotationMode(); + ScCore->primaryMainWindow()->doc->setRotationMode(static_cast<AnchorPoint>(basepoint)); + } + + ScCore->primaryMainWindow()->doc->rotateItem(rotation * -1.0, item); + + if (basepoint != (int) AnchorPoint::None) + { + ScCore->primaryMainWindow()->doc->setRotationMode(oldBasePoint); + } + Py_RETURN_NONE; } @@ -726,6 +749,7 @@ void cmdmanidocwarnings() << scribus_setimageoffset__doc__ << scribus_setimagescale__doc__ << scribus_setnormalmode__doc__ + << scribus_setrotation__doc__ << scribus_setscaleframetoimage__doc__ << scribus_setscaleimagetoframe__doc__ << scribus_sizeobject__doc__ diff --git a/scribus/plugins/scriptplugin/cmdmani.h b/scribus/plugins/scriptplugin/cmdmani.h index e4d4253a7..f7fd346d0 100644 --- a/scribus/plugins/scriptplugin/cmdmani.h +++ b/scribus/plugins/scriptplugin/cmdmani.h @@ -53,12 +53,24 @@ PyObject *scribus_rotateobjectrel(PyObject * /*self*/, PyObject* args); PyDoc_STRVAR(scribus_rotateobjectabs__doc__, QT_TR_NOOP("rotateObjectAbs(rot [, \"name\"])\n\ \n\ -Sets the rotation of the object \"name\" to \"rot\". Positive values\n\ +Deprecated. Please use setRotation().\n\ +")); + +PyDoc_STRVAR(scribus_setrotation__doc__, +QT_TR_NOOP("setRotation(rotation [, name=\"\", basepoint=None])\n\ +\n\ +Sets the rotation of the object \"name\" to \"rotation\". Positive values\n\ mean counter clockwise rotation. If \"name\" is not given the currently\n\ selected item is used.\n\ +\n\ +If basepoint is not set, the current basepoint is used.\n\ +Valid values for basepoint are:\n\ +BASEPOINT_TOPLEFT, BASEPOINT_TOP, BASEPOINT_TOPRIGHT,\n\ +BASEPOINT_LEFT, BASEPOINT_CENTER, BASEPOINT_RIGHT,\n\ +BASEPOINT_BOTTOMLEFT, BASEPOINT_BOTTOM, BASEPOINT_BOTTOMRIGHT\n\ ")); -/*! Rotate ABS the object */ -PyObject *scribus_rotateobjectabs(PyObject * /*self*/, PyObject* args); +/*! Set the rotation of the object */ +PyObject *scribus_setrotation(PyObject * /*self*/, PyObject* args, PyObject* kw); /*! docstring */ PyDoc_STRVAR(scribus_sizeobject__doc__, diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp index 2836dfb96..59407e81d 100644 --- a/scribus/plugins/scriptplugin/scriptplugin.cpp +++ b/scribus/plugins/scriptplugin/scriptplugin.cpp @@ -485,7 +485,7 @@ PyMethodDef scribus_methods[] = { {const_cast<char*>("resizeTableRow"), scribus_resizetablerow, METH_VARARGS, tr(scribus_resizetablerow__doc__)}, {const_cast<char*>("revertDoc"), (PyCFunction)scribus_revertdoc, METH_NOARGS, tr(scribus_revertdoc__doc__)}, {const_cast<char*>("rotateObject"), scribus_rotateobjectrel, METH_VARARGS, tr(scribus_rotateobjectrel__doc__)}, - {const_cast<char*>("rotateObjectAbs"), scribus_rotateobjectabs, METH_VARARGS, tr(scribus_rotateobjectabs__doc__)}, + {const_cast<char*>("rotateObjectAbs"), (PyCFunction)scribus_setrotation, METH_VARARGS|METH_KEYWORDS, tr(scribus_rotateobjectabs__doc__)}, // Deprecated, alias to setRotation {const_cast<char*>("saveDoc"), (PyCFunction)scribus_savedoc, METH_NOARGS, tr(scribus_savedoc__doc__)}, {const_cast<char*>("saveDocAs"), scribus_savedocas, METH_VARARGS, tr(scribus_savedocas__doc__)}, {const_cast<char*>("savePDFOptions"), (PyCFunction)scribus_savepdfoptions, METH_VARARGS, tr(scribus_savepdfoptions__doc__)}, @@ -564,6 +564,7 @@ PyMethodDef scribus_methods[] = { {const_cast<char*>("setPDFBookmark"), scribus_setpdfbookmark, METH_VARARGS, tr(scribus_setpdfbookmark__doc__)}, {const_cast<char*>("setParagraphStyle"), scribus_setparagraphstyle, METH_VARARGS, tr(scribus_setparagraphstyle__doc__)}, {const_cast<char*>("setRedraw"), scribus_setredraw, METH_VARARGS, tr(scribus_setredraw__doc__)}, + {const_cast<char*>("setRotation"), (PyCFunction)scribus_setrotation, METH_VARARGS|METH_KEYWORDS, tr(scribus_setrotation__doc__)}, {const_cast<char*>("setRowGuides"), (PyCFunction)scribus_setRowGuides, METH_VARARGS|METH_KEYWORDS, tr(scribus_setRowGuides__doc__)}, {const_cast<char*>("setScaleFrameToImage"), (PyCFunction)scribus_setscaleframetoimage, METH_VARARGS, tr(scribus_setscaleframetoimage__doc__)}, {const_cast<char*>("setScaleImageToFrame"), (PyCFunction)scribus_setscaleimagetoframe, METH_VARARGS|METH_KEYWORDS, tr(scribus_setscaleimagetoframe__doc__)}, @@ -914,6 +915,16 @@ PyObject* PyInit_scribus(void) PyDict_SetItemString(d, "TAB_PERIOD", Py_BuildValue("i", 2)); PyDict_SetItemString(d, "TAB_COMMA", Py_BuildValue("i", 3)); PyDict_SetItemString(d, "TAB_CENTER", Py_BuildValue("i", 4)); + // Basepoint / AnchorPoint + PyDict_SetItemString(d, "BASEPOINT_TOPLEFT", Py_BuildValue("i", (int) AnchorPoint::TopLeft)); + PyDict_SetItemString(d, "BASEPOINT_TOP", Py_BuildValue("i", (int) AnchorPoint::Top)); + PyDict_SetItemString(d, "BASEPOINT_TOPRIGHT", Py_BuildValue("i", (int) AnchorPoint::TopRight)); + PyDict_SetItemString(d, "BASEPOINT_LEFT", Py_BuildValue("i", (int) AnchorPoint::Left)); + PyDict_SetItemString(d, "BASEPOINT_CENTER", Py_BuildValue("i", (int) AnchorPoint::Center)); + PyDict_SetItemString(d, "BASEPOINT_RIGHT", Py_BuildValue("i", (int) AnchorPoint::Right)); + PyDict_SetItemString(d, "BASEPOINT_BOTTOMLEFT", Py_BuildValue("i", (int) AnchorPoint::BottomLeft)); + PyDict_SetItemString(d, "BASEPOINT_BOTTOM", Py_BuildValue("i", (int) AnchorPoint::Bottom)); + PyDict_SetItemString(d, "BASEPOINT_BOTTOMRIGHT", Py_BuildValue("i", (int) AnchorPoint::BottomRight)); // Measurement units understood by Scribus's units.cpp functions are exported as constant conversion // factors to be used from Python. |
|
I have pushed this to 1.7.0. The patch did not apply, strangely, manually applied it. If it works, I could apply to 1.5.9.svn |
|
Please confirm if its ok, so I can commit to 1.5.9.svn |
|
yes, i finally had some time to test it. it seems to be working correctly! i've written a python file with a .sla that does a visual test of the function. i'm creating a repository of tests in python for scribus. for now it's about testing the new scripter functions (i've started it for getGroupItem), but i'd like to extend it also for testing other aspects of scribus. do you or jean have automatic tests? or do you have tests files that could be added to automatic tests? when everything is ready, i should be able to export files to pdf and compare their png version with a previous output. |
|
ok, please check 1.5.9 now.. no enum in use there for the rotation anchor point. We don't have automatic tests.. no. |
|
since it's using the enum in the scripter, your change should be fine (the documentation is the same : - ) i'll let gitlab produce the appimage and i can test tomorrow with it. thanks for the commit! |
|
tested with the 1.5.9 appimage: seems to be fine. and now i can pick a scribus executable for the tests : - ) |
Date Modified | Username | Field | Change |
---|---|---|---|
2023-12-17 20:59 | ale | New Issue | |
2023-12-18 07:35 | ale | Summary | scripter: create setRotation(), deprecated rotateObjectAbs() and add a way to use a specific basepoint => scripter: create setRotation(), deprecate rotateObjectAbs() and add a way to use a specific basepoint |
2023-12-18 12:33 | ale | Note Added: 0050620 | |
2023-12-18 12:33 | ale | File Added: set-rotation.diff | |
2023-12-18 12:33 | ale | Summary | scripter: create setRotation(), deprecate rotateObjectAbs() and add a way to use a specific basepoint => PATCH: scripter: create setRotation(), deprecate rotateObjectAbs() and add a way to use a specific basepoint |
2023-12-18 12:33 | ale | Patch | No => Yes |
2023-12-18 21:47 | cbradney | Note Added: 0050625 | |
2023-12-19 21:47 | cbradney | Note Added: 0050631 | |
2023-12-19 22:12 | ale | Note Added: 0050633 | |
2023-12-19 22:41 | cbradney | Note Added: 0050634 | |
2023-12-19 22:41 | cbradney | Assigned To | => cbradney |
2023-12-19 22:41 | cbradney | Status | new => resolved |
2023-12-19 22:41 | cbradney | Resolution | open => fixed |
2023-12-19 22:41 | cbradney | Fixed in Version | => 1.6.0.svn |
2023-12-19 23:15 | ale | Note Added: 0050636 | |
2023-12-20 11:54 | ale | Note Added: 0050640 | |
2023-12-24 10:00 | cbradney | Status | resolved => closed |