View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0017029 | Scribus | Scripter | public | 2023-10-15 07:29 | 2023-11-04 09:09 |
Reporter | ale | Assigned To | cbradney | ||
Priority | normal | Severity | feature | Reproducibility | N/A |
Status | closed | Resolution | fixed | ||
Product Version | 1.7.0.svn | ||||
Fixed in Version | 1.6.0.svn | ||||
Summary | 0017029: [PATCH] scripter: accessing page > guides > columns/rows | ||||
Description | add scripter functions for accessing the values of the column/rows tab in page guides: - getColumnGuides() -> {'number': int, 'gap': int, 'reference': 0|1|2, guides: [real]} - getRowGuides() -> {'number': int, 'gap': int, 'reference': 0|1|2, guides: [real]} - setColumnGuides(number, gap=0.0, refer_to=0) - setColumnGuides(number, gap=0.0, refer_to=0) | ||||
Tags | patch, scripter | ||||
Patch | Yes | ||||
|
https://gitlab.com/a.l.e/scribus/-/commits/scripter-column-row-guides https://gitlab.com/scribus/scribus/-/merge_requests/41.diff as written in https://forums.scribus.net/index.php/topic,4733.msg21768.html#msg21768 i had to move resetSelectionForPage() to guidemanagercore to make it callable from the scripter. the python file attached is a poor man unit testing for the four implemented functions... i wonder if there is a way, we could start adding tests for scribus code... scripter-column-row-guides.diff (17,211 bytes)
diff --git a/scribus/guidemanagercore.cpp b/scribus/guidemanagercore.cpp index 6ea38a1bce7ec2ef71ba47159d9fcc07f04ca7de..aa6d643bec538c0207f476e6b9cd476fc1838c09 100644 --- a/scribus/guidemanagercore.cpp +++ b/scribus/guidemanagercore.cpp @@ -638,6 +638,31 @@ double GuideManagerCore::closestVertRight(double x) const return closest; } +void GuideManagerCore::resetSelectionForPage(ScPage* page) +{ + auto doc = page->doc(); + int docSelectionCount = doc->m_Selection->count(); + + page->guides.gx = page->guides.gy = page->guides.gw = page->guides.gh = 0.0; + + // multiselection + if (docSelectionCount > 1) + { + double x, y; + doc->m_Selection->getGroupRect(&x, &y, &page->guides.gw, &page->guides.gh); + page->guides.gx = x - page->xOffset(); + page->guides.gy = y - page->yOffset(); + } + // only one item selected + else if (docSelectionCount == 1) + { + PageItem *currItem = doc->m_Selection->itemAt(0); + page->guides.gx = currItem->xPos() - page->xOffset(); + page->guides.gy = currItem->yPos() - page->yOffset(); + page->guides.gw = currItem->width(); + page->guides.gh = currItem->height(); + } +} void GuideManagerIO::readVerticalGuides(const QString& guideString, ScPage *page, GuideManagerCore::GuideType type, bool useOldGuides) { diff --git a/scribus/guidemanagercore.h b/scribus/guidemanagercore.h index 4d0781de777eb42a6c95ecbefb470b2ce93cf4b5..ec8fcb322e5e3cb61afed9231539dfbdbef8b138 100644 --- a/scribus/guidemanagercore.h +++ b/scribus/guidemanagercore.h @@ -103,6 +103,12 @@ public: //! \brief Properties for Auto guides remembrance. See GuideManager. void setVerticalAutoRefer(int val) { m_verticalAutoRefer = val; } + /*! \brief Recalculate the selection position and measurements for the current page. + It's used for automatic guides position. It's called for every + selection GUI widgets change to handle selection change only + when needed. */ + void resetSelectionForPage(ScPage* page); + /*! \brief Selection/group coordinates It's used to simulate the original selection "freezed in time" for parent page */ diff --git a/scribus/plugins/scriptplugin/cmdpage.cpp b/scribus/plugins/scriptplugin/cmdpage.cpp index 32f38e3f4a61ab0cb595a8ef2f02e70258b652c9..7bd612433a4275fed4d76cbe640b88f5b279ce06 100644 --- a/scribus/plugins/scriptplugin/cmdpage.cpp +++ b/scribus/plugins/scriptplugin/cmdpage.cpp @@ -11,6 +11,7 @@ for which a new license (GPL+exception) is in place. #include "scribuscore.h" #include "scribusdoc.h" #include "scribusview.h" +#include "selection.h" #include <QApplication> @@ -377,6 +378,176 @@ PyObject *scribus_setVguides(PyObject* /* self */, PyObject* args) Py_RETURN_NONE; } +PyObject *scribus_getColumnGuides(PyObject* /* self */) +{ + if (!checkHaveDocument()) + return nullptr; + auto guides = PyDict_New(); + + auto page = ScCore->primaryMainWindow()->doc->currentPage(); + + { + const char keyString[] = "number"; + PyObject *key = PyUnicode_FromString(keyString); + PyDict_SetItem(guides, key, PyLong_FromLong((long) page->guides.verticalAutoCount())); + } + { + const char keyString[] = "gap"; + PyObject *key = PyUnicode_FromString(keyString); + PyDict_SetItem(guides, key, Py_BuildValue("d", PointToValue(page->guides.verticalAutoGap()))); + } + { + const char keyString[] = "refer_to"; + PyObject *key = PyUnicode_FromString(keyString); + PyDict_SetItem(guides, key, PyLong_FromLong((long) page->guides.verticalAutoRefer())); + } + { + auto rowsList = PyList_New(0); + for (auto column: page->guides.getAutoVerticals(page)) // QList<double> Guides + { + PyList_Append(rowsList, Py_BuildValue("d", PointToValue(column))); + } + const char keyString[] = "guides"; + PyObject *key = PyUnicode_FromString(keyString); + PyDict_SetItem(guides, key, rowsList); + } + + return guides; +} + +PyObject *scribus_getRowGuides(PyObject* /* self */) +{ + if (!checkHaveDocument()) + return nullptr; + auto guides = PyDict_New(); + + auto page = ScCore->primaryMainWindow()->doc->currentPage(); + + { + const char keyString[] = "number"; + PyObject *key = PyUnicode_FromString(keyString); + PyDict_SetItem(guides, key, PyLong_FromLong((long) page->guides.horizontalAutoCount())); + } + { + const char keyString[] = "gap"; + PyObject *key = PyUnicode_FromString(keyString); + PyDict_SetItem(guides, key, Py_BuildValue("d", PointToValue(page->guides.horizontalAutoGap()))); + } + { + const char keyString[] = "refer_to"; + PyObject *key = PyUnicode_FromString(keyString); + PyDict_SetItem(guides, key, PyLong_FromLong((long) page->guides.horizontalAutoRefer())); + } + { + auto rowsList = PyList_New(0); + for (auto row: page->guides.getAutoHorizontals(page)) // QList<double> Guides + { + PyList_Append(rowsList, Py_BuildValue("d", PointToValue(row))); + } + const char keyString[] = "guides"; + PyObject *key = PyUnicode_FromString(keyString); + PyDict_SetItem(guides, key, rowsList); + } + return guides; +} + +PyObject *scribus_setColumnGuides(PyObject* /* self */, PyObject* args, PyObject* kw) +{ + if (!checkHaveDocument()) + return nullptr; + + int number; + double gap = 0.0; + int referTo = 0; + char* kwargs[] = {const_cast<char*>("number"), const_cast<char*>("gap"), const_cast<char*>("refer_to"), nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "i|di", kwargs, &number, &gap, &referTo)) + return nullptr; + + auto doc = ScCore->primaryMainWindow()->doc; + + if (referTo < 0 || referTo > 2) + { + QString message = QObject::tr("refer_to=0|1|2.","python error"); + PyErr_SetString(ScribusException, message.toLocal8Bit().constData()); + return nullptr; + } + else if (referTo == 2) + { + // refertTo a selection is only active, when there is a selection in the document + if (doc->m_Selection->isEmpty()) + { + QString message = QObject::tr("setColumnGuides() with refer_to=2 needs a selection.","python error"); + PyErr_SetString(ScribusException, message.toLocal8Bit().constData()); + return nullptr; + } + doc->currentPage()->guides.resetSelectionForPage(doc->currentPage()); + } + + + // If there are no guides, reset the values for the gap and for the reference + if (number == 0) + { + doc->currentPage()->guides.setVerticalAutoGap(0); + doc->currentPage()->guides.setVerticalAutoRefer(0); + doc->currentPage()->guides.setVerticalAutoCount(0); + Py_RETURN_NONE; + } + + doc->currentPage()->guides.setVerticalAutoGap(ValueToPoint(gap)); + doc->currentPage()->guides.setVerticalAutoRefer(referTo); + doc->currentPage()->guides.setVerticalAutoCount(number); + + Py_RETURN_NONE; +} + +PyObject *scribus_setRowGuides(PyObject* /* self */, PyObject* args, PyObject* kw) +{ + if (!checkHaveDocument()) + return nullptr; + + int number; + double gap = 0.0; + int referTo = 0; + char* kwargs[] = {const_cast<char*>("number"), const_cast<char*>("gap"), const_cast<char*>("refer_to"), nullptr}; + if (!PyArg_ParseTupleAndKeywords(args, kw, "i|di", kwargs, &number, &gap, &referTo)) + return nullptr; + + auto doc = ScCore->primaryMainWindow()->doc; + + if (referTo < 0 || referTo > 2) + { + QString message = QObject::tr("refer_to=0|1|2.","python error"); + PyErr_SetString(ScribusException, message.toLocal8Bit().constData()); + return nullptr; + } + else if (referTo == 2) + { + if (doc->m_Selection->isEmpty()) + { + // refertTo a selection is only active, when there is a selection in the document + QString message = QObject::tr("setRowGuides() with refer_to=2 needs a selection.","python error"); + PyErr_SetString(ScribusException, message.toLocal8Bit().constData()); + return nullptr; + } + doc->currentPage()->guides.resetSelectionForPage(doc->currentPage()); + } + + doc->currentPage()->guides.setHorizontalAutoCount(number); + + // If there are no guides, reset the values for the gap and for the reference + if (number == 0) + { + doc->currentPage()->guides.setHorizontalAutoGap(0); + doc->currentPage()->guides.setHorizontalAutoRefer(0); + Py_RETURN_NONE; + } + + doc->currentPage()->guides.setHorizontalAutoGap(ValueToPoint(gap)); + doc->currentPage()->guides.setHorizontalAutoRefer(referTo); + + Py_RETURN_NONE; +} + PyObject *scribus_getpagemargins(PyObject* /* self */) { PyObject *margins = nullptr; @@ -550,5 +721,9 @@ void cmdpagedocwarnings() << scribus_redraw__doc__ << scribus_savepageeps__doc__ << scribus_setHguides__doc__ - << scribus_setVguides__doc__; + << scribus_setVguides__doc__ + << scribus_getColumnGuides__doc__ + << scribus_getRowGuides__doc__ + << scribus_setColumnGuides__doc__ + << scribus_setRowGuides__doc__; } diff --git a/scribus/plugins/scriptplugin/cmdpage.h b/scribus/plugins/scriptplugin/cmdpage.h index e8c79b8fe18f3c3af9ccd9875aac65b6210451aa..e0edf552868f6fd891dc48552a462b8f71adb86b 100644 --- a/scribus/plugins/scriptplugin/cmdpage.h +++ b/scribus/plugins/scriptplugin/cmdpage.h @@ -153,6 +153,56 @@ See setHGuides.\n\ /*! set V guides */ PyObject *scribus_setVguides(PyObject * /*self*/, PyObject* args); +/*! docstring */ +PyDoc_STRVAR(scribus_getColumnGuides__doc__, +QT_TR_NOOP("getColumnGuides()\n\ +\n\ +Return the column guides for the current page.\n\ +\n\ +The return a dictionary containing:\n\ +{'number': int, 'gap': int, 'reference': 0|1|2, guides: [real]}\n\ +")); +/*! get column guides */ +PyObject *scribus_getColumnGuides(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_getRowGuides__doc__, +QT_TR_NOOP("getRowGuides()\n\ +\n\ +Return the row guides for the current page.\n\ +\n\ +The return a dictionary containing:\n\ +{'number': int, 'gap': int, 'reference': 0|1|2, guides: [real]}\n\ +")); +/*! get row guides */ +PyObject *scribus_getRowGuides(PyObject * /*self*/); + +/*! docstring */ +PyDoc_STRVAR(scribus_setColumnGuides__doc__, +QT_TR_NOOP("setColumnGuides(number, gap=0.0, refer_to=0)\n\ +\n\ +Set the column guides for the current page.\n\ +\n\ +number is the number of guides to be defined (if 0, all values get reset to their default)\n\ +\n\ +refer_to can have the values 0 (page), 1 (margin), 2 (selection)\n\ +")); +/*! set column guides */ +PyObject *scribus_setColumnGuides(PyObject * /*self*/, PyObject* args, PyObject* kw); + +/*! docstring */ +PyDoc_STRVAR(scribus_setRowGuides__doc__, +QT_TR_NOOP("setRowGuides(number, gap=0.0, refer_to=0)\n\ +\n\ +Set the row guides for the current page.\n\ +\n\ +number is the number of guides to be defined (if 0, all values get reset to their default)\n\ +\n\ +refer_to can have the values 0 (page), 1 (margin), 2 (selection)\n\ +")); +/*! set row guides */ +PyObject *scribus_setRowGuides(PyObject * /*self*/, PyObject* args, PyObject* kw); + /*! docstring */ PyDoc_STRVAR(scribus_getpagesize__doc__, QT_TR_NOOP("getPageSize() -> tuple\n\ diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp index dd2b93e2aeece0f7b0e08caa4b9fcbc80bfc568c..c1c56f8806394e9b321f3ba3e8280173f87f8dc0 100644 --- a/scribus/plugins/scriptplugin/scriptplugin.cpp +++ b/scribus/plugins/scriptplugin/scriptplugin.cpp @@ -349,6 +349,7 @@ PyMethodDef scribus_methods[] = { {const_cast<char*>("getColorNames"), (PyCFunction)scribus_getcolornames, METH_NOARGS, tr(scribus_getcolornames__doc__)}, {const_cast<char*>("getColumnGap"), scribus_getcolumngap, METH_VARARGS, tr(scribus_getcolumngap__doc__)}, {const_cast<char*>("getColumns"), scribus_getcolumns, METH_VARARGS, tr(scribus_getcolumns__doc__)}, + {const_cast<char*>("getColumnGuides"), (PyCFunction)scribus_getColumnGuides, METH_VARARGS|METH_KEYWORDS, tr(scribus_getColumnGuides__doc__)}, {const_cast<char*>("getCornerRadius"), scribus_getcornerradius, METH_VARARGS, tr(scribus_getcornerradius__doc__)}, {const_cast<char*>("getCustomLineStyle"), scribus_getcustomlinestyle, METH_VARARGS, tr(scribus_getcustomlinestyle__doc__)}, {const_cast<char*>("getDocName"), (PyCFunction)scribus_getdocname, METH_NOARGS, tr(scribus_getdocname__doc__)}, @@ -401,6 +402,7 @@ PyMethodDef scribus_methods[] = { {const_cast<char*>("getPosition"), scribus_getposition, METH_VARARGS, tr(scribus_getposition__doc__)}, {const_cast<char*>("getPrevLinkedFrame"), scribus_getprevlinkedframe, METH_VARARGS, tr(scribus_getprevlinkedframe__doc__)}, {const_cast<char*>("getRotation"), scribus_getrotation, METH_VARARGS, tr(scribus_getrotation__doc__)}, + {const_cast<char*>("getRowGuides"), (PyCFunction)scribus_getRowGuides, METH_VARARGS|METH_KEYWORDS, tr(scribus_getRowGuides__doc__)}, {const_cast<char*>("getSelectedObject"), scribus_getselectedobject, METH_VARARGS, tr(scribus_getselectedobject__doc__)}, {const_cast<char*>("getSize"), scribus_getsize, METH_VARARGS, tr(scribus_getsize__doc__)}, {const_cast<char*>("getStyle"), scribus_getparagraphstyle, METH_VARARGS, tr(scribus_getstyle__doc__) }, // Deprecated @@ -514,6 +516,7 @@ PyMethodDef scribus_methods[] = { {const_cast<char*>("setCharacterStyle"), scribus_setcharstyle, METH_VARARGS, tr(scribus_setcharstyle__doc__) }, {const_cast<char*>("setColumnGap"), scribus_setcolumngap, METH_VARARGS, tr(scribus_setcolumngap__doc__)}, {const_cast<char*>("setColumns"), scribus_setcolumns, METH_VARARGS, tr(scribus_setcolumns__doc__)}, + {const_cast<char*>("setColumnGuides"), (PyCFunction)scribus_setColumnGuides, METH_VARARGS|METH_KEYWORDS, tr(scribus_setColumnGuides__doc__)}, {const_cast<char*>("setCornerRadius"), scribus_setcornerradius, METH_VARARGS, tr(scribus_setcornerradius__doc__)}, {const_cast<char*>("setCursor"), scribus_setcursor, METH_VARARGS, tr(scribus_setcursor__doc__)}, {const_cast<char*>("setCustomLineStyle"), scribus_setcustomlinestyle, METH_VARARGS, tr(scribus_setcustomlinestyle__doc__)}, @@ -559,6 +562,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*>("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__)}, {const_cast<char*>("setSpotColor"), scribus_setspotcolor, METH_VARARGS, tr(scribus_setspotcolor__doc__)}, diff --git a/scribus/ui/guidemanager.cpp b/scribus/ui/guidemanager.cpp index a66bf4d81ff5050f63a0d5352d9b80ae77b7a181..5db1c306488e099d6ff2632cce2f1d3cdf2c1e21 100644 --- a/scribus/ui/guidemanager.cpp +++ b/scribus/ui/guidemanager.cpp @@ -591,31 +591,6 @@ Guides GuideManager::getAutoHorizontals(const ScPage * page) const return guides.getAutoHorizontals(page); } -void GuideManager::resetSelectionForPage() -{ - int docSelectionCount = currentPage->doc()->m_Selection->count(); - - currentPage->guides.gx = currentPage->guides.gy = currentPage->guides.gw = currentPage->guides.gh = 0.0; - - // multiselection - if (docSelectionCount > 1) - { - double x, y; - m_Doc->m_Selection->getGroupRect(&x, &y, ¤tPage->guides.gw, ¤tPage->guides.gh); - currentPage->guides.gx = x - currentPage->xOffset(); - currentPage->guides.gy = y - currentPage->yOffset(); - } - // only one item selected - else if (docSelectionCount == 1) - { - const PageItem *currItem = m_Doc->m_Selection->itemAt(0); - currentPage->guides.gx = currItem->xPos() - currentPage->xOffset(); - currentPage->guides.gy = currItem->yPos() - currentPage->yOffset(); - currentPage->guides.gw = currItem->width(); - currentPage->guides.gh = currItem->height(); - } -} - void GuideManager::verticalModel_valueChanged() { currentPage->guides.clearVerticals(GuideManagerCore::Standard); @@ -706,7 +681,7 @@ void GuideManager::horizontalSelectionAutoButton_toggled(bool state) return; currentPage->guides.setHorizontalAutoRefer(2); if (horizontalSelectionAutoButton->isEnabled()) - resetSelectionForPage(); + currentPage->guides.resetSelectionForPage(currentPage); drawGuides(); } @@ -734,7 +709,7 @@ void GuideManager::verticalSelectionAutoButton_toggled(bool state) return; currentPage->guides.setVerticalAutoRefer(2); if (verticalSelectionAutoButton->isEnabled()) - resetSelectionForPage(); + currentPage->guides.resetSelectionForPage(currentPage); drawGuides(); m_Doc->changed(); } diff --git a/scribus/ui/guidemanager.h b/scribus/ui/guidemanager.h index 7d62de476c8fd5d9f3b4cc70fcc87c63dcbb2286..a51bd6de13732af236a03dd23c9c2a4385a458ef 100644 --- a/scribus/ui/guidemanager.h +++ b/scribus/ui/guidemanager.h @@ -117,12 +117,6 @@ private: */ Guides getAutoVerticals(const ScPage * p) const; - /*! \brief Recalculate the selection position and measurements for the current page. - It's used for automatic guides position. It's called for every - selection GUI widgets change to handle selection change only - when needed. */ - void resetSelectionForPage(); - /*! \brief Draw guides into painter */ void drawGuides(); colomn-row-guides.py (4,252 bytes)
#!/usr/bin/env python3 import sys import subprocess def main(): try: import scribus run_script() except ImportError: run_scribus() def run_scribus(): # if len(sys.argv) < 2: # print(f'Usage: python3 {sys.argv[0]} filename') # return call_args = ['scribus', '-g', '-py', sys.argv[0]] # call_args += ['--', sys.argv[1]] subprocess.call(call_args) def run_script() : # print(scribus.getColumnRowGuides()) scribus.newDocument(scribus.PAPER_A4_MM, (10, 10, 10, 10), scribus.PORTRAIT, 1, scribus.UNIT_MILLIMETERS, scribus.PAGE_1, 0, 1) # set 3 column guides and use default values for the gap and refer_to scribus.setColumnGuides(3) columnGuides = scribus.getColumnGuides() # print(columnGuides) assert columnGuides['number'] == 3 assert columnGuides['refer_to'] == 0 assert len(columnGuides['guides']) == 3 # set new values for the column guides, with a gap of 10 mm scribus.setColumnGuides(2, gap=10) columnGuides = scribus.getColumnGuides() # print(columnGuides) assert columnGuides['number'] == 2 assert columnGuides['gap'] == 10 assert columnGuides['refer_to'] == 0 assert len(columnGuides['guides']) == 4 # set new values for the column guides, with a refer_to of 1 scribus.setColumnGuides(1, refer_to=1) columnGuides = scribus.getColumnGuides() # print(columnGuides) assert columnGuides['number'] == 1 assert columnGuides['gap'] == 0 assert columnGuides['refer_to'] == 1 assert len(columnGuides['guides']) == 1 assert round(columnGuides['guides'][0], 1) == 105.0 # remove the column guides scribus.setColumnGuides(0) columnGuides = scribus.getColumnGuides() # print(columnGuides) assert columnGuides['number'] == 0 # refer_to the current selection scribus.createRect(20, 20, 50, 50, 'rect') scribus.selectObject('rect') scribus.setColumnGuides(1, refer_to=2) columnGuides = scribus.getColumnGuides() # print(columnGuides) assert columnGuides['number'] == 1 assert columnGuides['gap'] == 0.0 assert columnGuides['refer_to'] == 2 assert len(columnGuides['guides']) == 1 assert columnGuides['guides'][0] == 45.0 # refer_to is 0|1|2 failed = False try: scribus.setColumnGuides(1, refer_to=3) failed = True except: pass finally: assert not failed # throw if it has not failed # set 3 row guides and use default values for the gap and refer_to scribus.setRowGuides(3) rowGuides = scribus.getRowGuides() # print(rowGuides) assert rowGuides['number'] == 3 assert rowGuides['refer_to'] == 0 assert len(rowGuides['guides']) == 3 # set new values for the row guides, with a gap of 10 mm scribus.setRowGuides(2, gap=10) rowGuides = scribus.getRowGuides() # print(rowGuides) assert rowGuides['number'] == 2 assert rowGuides['gap'] == 10 assert rowGuides['refer_to'] == 0 assert len(rowGuides['guides']) == 4 # set new values for the row guides, with a refer_to of 1 scribus.setRowGuides(1, refer_to=1) rowGuides = scribus.getRowGuides() # print(rowGuides) assert rowGuides['number'] == 1 assert rowGuides['gap'] == 0 assert rowGuides['refer_to'] == 1 assert len(rowGuides['guides']) == 1 assert round(rowGuides['guides'][0], 1) == 148.5 # remove the row guides scribus.setRowGuides(0) rowGuides = scribus.getRowGuides() # print(rowGuides) assert rowGuides['number'] == 0 # refer_to the current selection scribus.createRect(20, 20, 50, 50, 'rect') scribus.selectObject('rect') scribus.setRowGuides(1, refer_to=2) rowGuides = scribus.getRowGuides() # print(rowGuides) assert rowGuides['number'] == 1 assert rowGuides['gap'] == 0.0 assert rowGuides['refer_to'] == 2 assert len(rowGuides['guides']) == 1 assert round(rowGuides['guides'][0], 1) == 45.0 # refer_to is 0|1|2 failed = False try: scribus.setRowGuides(1, refer_to=3) failed = True except: pass finally: assert not failed # throw if it has not failed if __name__ == "__main__": main() |
|
btw, i'd like to use the getColumnGuides() and getRowGuides() for this: Scripts and Plugins / Re: Import_txt script https://forums.scribus.net/index.php/topic,4724.msg21744.html#msg21744 maybe, it can also be added to 1.6.1svn... (or 1.6.0?) |
|
I have committed to 1.7.0. Apart from resorting void cmdpagedocwarnings(), its as you wrote. Please test and if you give the confirmation, I will commit to 1.5.9.svn |
|
the test file runs through with no messages. one thing. if i create an A4 document, with 1cm margins and one vertical and one horintal column/row with 1cm gap each i get {'number': 1, 'gap': 20.0, 'refer_to': 1, 'guides': [94.99999999999999, 114.99999999999999]} The question is if the guides should be rounded to 95 and 115... |
|
Yes I would say they should be rounded with that many 9s in place. 10+95+20+95+10.. = 230? or is it just 95+20+95 = 210 - width of an A4? int unitGetPrecisionFromIndex(const int index) would be useful. |
|
i tried to do /** * Round value to the n-th decimal. * Since the argument and the returned value are both a double, there is no guarantee that the result will have indeed n decimals. * This function is mostly useful for getting something sane out of values like 94.99999999999999 */ auto roundDoubleToFloat = [](double value, int n) -> float { value *= 10 * n; value = qRound(value); value /= 10 * n; return (float) value; }; qDebug() << ">>>" << roundDoubleToFloat(PointToValue(column), ScCore->primaryMainWindow()->doc->unitIndex()); PyList_Append(rowsList, Py_BuildValue("f", roundDoubleToFloat(PointToValue(column), ScCore->primaryMainWindow()->doc->unitIndex()))); and it seems to do sane things inside of c++ but once the value gets to python i still get the .99999999999999 print(scribus.getRowGuides()) gives: >>> 45 {'number': 1, 'gap': 0.0, 'refer_to': 2, 'guides': [44.99999999999999]} i guess that the people using the scripter API will need to take of this. |
|
so, as far i am concerned, this seems to be ready for merging : - ) |
|
thanks! |
Date Modified | Username | Field | Change |
---|---|---|---|
2023-10-15 07:29 | ale | New Issue | |
2023-10-15 08:47 | ale | Note Added: 0050378 | |
2023-10-15 08:47 | ale | File Added: scripter-column-row-guides.diff | |
2023-10-15 08:47 | ale | File Added: colomn-row-guides.py | |
2023-10-15 08:48 | ale | Summary | scripter: accessing page > guides > columns/rows => [PATCH] scripter: accessing page > guides > columns/rows |
2023-10-15 08:48 | ale | Patch | No => Yes |
2023-10-15 08:48 | ale | Tag Attached: patch | |
2023-10-15 08:48 | ale | Tag Attached: scripter | |
2023-10-15 08:51 | ale | Note Added: 0050379 | |
2023-10-23 20:38 | cbradney | Note Added: 0050396 | |
2023-10-24 14:40 | ale | Note Added: 0050398 | |
2023-10-24 20:11 | cbradney | Note Added: 0050399 | |
2023-10-25 11:35 | ale | Note Added: 0050400 | |
2023-10-25 11:37 | ale | Note Edited: 0050400 | |
2023-10-25 11:38 | ale | Note Added: 0050401 | |
2023-10-25 19:36 | cbradney | Assigned To | => cbradney |
2023-10-25 19:36 | cbradney | Status | new => resolved |
2023-10-25 19:36 | cbradney | Resolution | open => fixed |
2023-10-25 19:36 | cbradney | Fixed in Version | => 1.6.0.svn |
2023-10-26 06:34 | ale | Note Added: 0050402 | |
2023-11-04 09:09 | cbradney | Status | resolved => closed |