View Issue Details

IDProjectCategoryView StatusLast Update
0017296ScribusScripterpublic2024-10-23 18:42
Reporterhugowett Assigned Tojghali  
PrioritynormalSeverityfeatureReproducibilityN/A
Status closedResolutionfixed 
Product Version1.7.0.svn 
Fixed in Version1.6.3.svn 
Summary0017296: Add script method getBaseLine() to complement setBaseLine()
DescriptionI'm scripting automatic layout adjustments where I need to adjust the baseline grid offset. The adjustments need to use the current grid offset as a starting point, but I could find a way to get to it using the scripting API.
TagsNo tags attached.
PatchYes

Activities

hugowett

2024-10-20 11:17

reporter  

0001-Add-script-method-getBaseLine-to-complement-setBaseL.patch (3,352 bytes)   
From 7f560ad47e99ca194cd74045f27345fe31fa4560 Mon Sep 17 00:00:00 2001
From: Hugo Wetterberg <hugo@wetterberg.nu>
Date: Sun, 20 Oct 2024 13:07:36 +0200
Subject: [PATCH] Add script method getBaseLine() to complement setBaseLine()

---
 scribus/plugins/scriptplugin/cmddoc.cpp       | 12 ++++++++++++
 scribus/plugins/scriptplugin/cmddoc.h         | 11 +++++++++++
 scribus/plugins/scriptplugin/scriptplugin.cpp |  1 +
 3 files changed, 24 insertions(+)

diff --git a/scribus/plugins/scriptplugin/cmddoc.cpp b/scribus/plugins/scriptplugin/cmddoc.cpp
index a96f9230a..903c1c2e1 100644
--- a/scribus/plugins/scriptplugin/cmddoc.cpp
+++ b/scribus/plugins/scriptplugin/cmddoc.cpp
@@ -171,6 +171,17 @@ PyObject *scribus_setbaseline(PyObject* /* self */, PyObject* args)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_getbaseline(PyObject* /* self */)
+{
+    if (!checkHaveDocument())
+        return nullptr;
+
+    GuidesPrefs& guides = ScCore->primaryMainWindow()->doc->guidesPrefs();
+
+    return Py_BuildValue("(dd)",
+                         guides.valueBaselineGrid,
+                         guides.offsetBaselineGrid);
+}
 
 PyObject *scribus_closedoc(PyObject* /* self */)
 {
@@ -513,6 +524,7 @@ void cmddocdocwarnings()
 	  << scribus_savedoc__doc__
 	  << scribus_savedocas__doc__
 	  << scribus_setbaseline__doc__
+	  << scribus_getbaseline__doc__
 	  << scribus_setbleeds__doc__
 	  << scribus_setdoctype__doc__ 
 	  << scribus_setinfo__doc__
diff --git a/scribus/plugins/scriptplugin/cmddoc.h b/scribus/plugins/scriptplugin/cmddoc.h
index fe77ef462..5017f1c1b 100644
--- a/scribus/plugins/scriptplugin/cmddoc.h
+++ b/scribus/plugins/scriptplugin/cmddoc.h
@@ -226,6 +226,17 @@ constants.\n\
 /** Sets document baseline settings - grid and offset. */
 PyObject *scribus_setbaseline(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getbaseline__doc__,
+QT_TR_NOOP("getBaseLine() -> (grid, offset)\n\
+\n\
+Gets the base line settings of the document, grid spacing(grid), grid offset(offset).\n\
+Values are given in the measurement units of the document - see UNIT_<type>\n\
+constants.\n\
+"));
+/** Sets document baseline settings - grid and offset. */
+PyObject *scribus_getbaseline(PyObject * /*self*/);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_setunit__doc__,
 QT_TR_NOOP("setUnit(type)\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index c18f7c7bb..2791f9754 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -507,6 +507,7 @@ PyMethodDef scribus_methods[] = {
 	{ "sentToLayer", scribus_sendtolayer, METH_VARARGS, tr(scribus_sendtolayer__doc__)}, // Deprecated, alias to sentToLayer
 	{ "setActiveLayer", scribus_setactivelayer, METH_VARARGS, tr(scribus_setactivelayer__doc__)},
 	{ "setBaseLine", scribus_setbaseline, METH_VARARGS, tr(scribus_setbaseline__doc__)},
+	{ "getBaseLine", (PyCFunction) scribus_getbaseline, METH_NOARGS, tr(scribus_getbaseline__doc__)},
 	{ "setBleeds", scribus_setbleeds, METH_VARARGS, tr(scribus_setbleeds__doc__)},
 	{ "setCellBottomBorder", scribus_setcellbottomborder, METH_VARARGS, tr(scribus_setcellbottomborder__doc__)},
 	{ "setCellBottomPadding", scribus_setcellbottompadding, METH_VARARGS, tr(scribus_setcellbottompadding__doc__)},
-- 
2.47.0

jghali

2024-10-20 19:36

administrator   ~0051467

Thanks for this patch. It has been applied with a few fixes, noticeably the unit used to return the baseline grid values. Your unmodified patch was returning the values in point units while getBaseline() docstring was specifying the values were returned in document units. I consequently modified your code to effectively return the values in document unit to be consistent with the new function docstring and also with the setBaseline() function.

jghali

2024-10-20 21:20

administrator   ~0051468

I also added getBleeds() and getMargins() in the process

hugowett

2024-10-21 06:29

reporter   ~0051469

Thank you, that was quick! Good call on adding the other "getters" as well.

I don't have a good handle on points vs. document units, so not surprising that I got that wrong. I looked through the documentation, but couldn't find any python functions for converting between the two. Might that be a good second patch (if I didn't just fail at reading the docs)?

Issue History

Date Modified Username Field Change
2024-10-20 11:17 hugowett New Issue
2024-10-20 11:17 hugowett File Added: 0001-Add-script-method-getBaseLine-to-complement-setBaseL.patch
2024-10-20 19:36 jghali Assigned To => jghali
2024-10-20 19:36 jghali Status new => resolved
2024-10-20 19:36 jghali Resolution open => fixed
2024-10-20 19:36 jghali Fixed in Version => 1.6.3.svn
2024-10-20 19:36 jghali Note Added: 0051467
2024-10-20 21:20 jghali Note Added: 0051468
2024-10-21 06:29 hugowett Note Added: 0051469
2024-10-23 18:42 cbradney Status resolved => closed