View Issue Details

IDProjectCategoryView StatusLast Update
0015441ScribusPlug-inspublic2019-06-04 20:56
ReporterGibbz Assigned Tojghali  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionfixed 
Product Version1.5.4 
Fixed in Version1.5.5.svn 
Summary0015441: Text vertical alignment not accessible from python/scripter
DescriptionOn a text frame under columns & text distances is a vertical alignment drop down box.
There is no way to access this from the scripter api.

TagsNo tags attached.
PatchYes

Activities

Gibbz

2018-10-11 04:13

reporter   ~0045505

Hi,

I have made a patch which adds support for this to the latest version from git 1.5.5.svn.

What is the process for getting this included, checked and rough time frame before this will make it into a build?
Are there nightlies?
verticalalignment.patch (8,350 bytes)   
diff --git a/scribus/plugins/scripter/api_item.cpp b/scribus/plugins/scripter/api_item.cpp
index 6ae8a2dcb..78f22cd89 100644
--- a/scribus/plugins/scripter/api_item.cpp
+++ b/scribus/plugins/scripter/api_item.cpp
@@ -282,6 +282,18 @@ void ItemAPI::setColumns(int value)
 	item->Cols = value;
 }
 
+int ItemAPI::verticalAlignment()
+{
+    return item->verticalAlignment();
+}
+
+void ItemAPI::setVerticalAlignment(int value)
+{
+    if (!checkHaveDocument())
+        RAISE("No document open");
+    item->setVerticalAlignment(value);
+}
+
 
 /**
  * Methods
diff --git a/scribus/plugins/scripter/api_item.h b/scribus/plugins/scripter/api_item.h
index 31c14ce44..738ee38ec 100644
--- a/scribus/plugins/scripter/api_item.h
+++ b/scribus/plugins/scripter/api_item.h
@@ -42,6 +42,7 @@ class ItemAPI : public QObject
 	Q_PROPERTY(double cornerRadius READ cornerRadius WRITE setCornerRadius)
 	Q_PROPERTY(double columnGap READ columnGap WRITE setColumnGap)
 	Q_PROPERTY(int columns READ columns WRITE setColumns)
+    Q_PROPERTY(int verticalAlignment READ verticalAlignment WRITE setVerticalAlignment)
 
 public:
     ItemAPI(PageItem *it);
@@ -134,6 +135,9 @@ private:
 	
 	int columns();
 	void setColumns(int value);
+
+    int verticalAlignment();
+    void setVerticalAlignment(int value);
 };
 
 #endif /*API_ITEM_H_*/
diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp
index 16e7cd6fa..17dc5c938 100644
--- a/scribus/plugins/scriptplugin/cmdtext.cpp
+++ b/scribus/plugins/scriptplugin/cmdtext.cpp
@@ -150,6 +150,24 @@ PyObject *scribus_getcolumns(PyObject* /* self */, PyObject* args)
 	return PyInt_FromLong(static_cast<long>(i->Cols));
 }
 
+PyObject *scribus_getverticalalignment(PyObject* /* self */, PyObject* args)
+{
+    char *Name = const_cast<char*>("");
+    if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+        return nullptr;
+    if (!checkHaveDocument())
+        return nullptr;
+    PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
+    if (i == nullptr)
+        return nullptr;
+    if (!i->isTextFrame())
+    {
+        PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get vertical alignment of non-text frame.","python error").toLocal8Bit().constData());
+        return nullptr;
+    }
+    return PyInt_FromLong(static_cast<long>(i->verticalAlignment()));
+}
+
 PyObject *scribus_getfontfeatures(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -709,6 +727,32 @@ PyObject *scribus_setcolumns(PyObject* /* self */, PyObject* args)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_setverticalalignment(PyObject* /* self */, PyObject* args)
+{
+    char *Name = const_cast<char*>("");
+    int w;
+    if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
+        return nullptr;
+    if (!checkHaveDocument())
+        return nullptr;
+    if (w < 0)
+    {
+        PyErr_SetString(PyExc_ValueError, QObject::tr("Vertical alignment out of bounds, must be > 1.","python error").toLocal8Bit().constData());
+        return nullptr;
+    }
+    PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
+    if (i == nullptr)
+        return nullptr;
+    if (!i->isTextFrame())
+    {
+        PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set vertical alignment on a non-text frame.","python error").toLocal8Bit().constData());
+        return nullptr;
+    }
+    i->setVerticalAlignment(w);
+
+    Py_RETURN_NONE;
+}
+
 PyObject *scribus_selecttext(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -1243,9 +1287,11 @@ void cmdtextdocwarnings()
 	  << scribus_getframetext__doc__   << scribus_gettext__doc__
 	  << scribus_getlinespace__doc__   << scribus_getcolumngap__doc__
 	  << scribus_getcolumns__doc__     << scribus_setboxtext__doc__
+      << scribus_getverticalalignment__doc__     << scribus_getverticalalignment__doc__
 	  << scribus_inserttext__doc__     << scribus_inserthtmltext__doc__<< scribus_setfont__doc__
 	  << scribus_setfontsize__doc__    << scribus_setlinespace__doc__
 	  << scribus_setcolumngap__doc__   << scribus_setcolumns__doc__
+      << scribus_setverticalalignment__doc__   << scribus_setverticalalignment__doc__
 	  << scribus_setalign__doc__       << scribus_selecttext__doc__
 	  << scribus_deletetext__doc__     << scribus_settextfill__doc__
 	  << scribus_settextstroke__doc__  << scribus_settextshade__doc__
diff --git a/scribus/plugins/scriptplugin/cmdtext.h b/scribus/plugins/scriptplugin/cmdtext.h
index 7e9ebe9ef..ffba68dcc 100644
--- a/scribus/plugins/scriptplugin/cmdtext.h
+++ b/scribus/plugins/scriptplugin/cmdtext.h
@@ -134,6 +134,16 @@ given the currently selected item is used.\n\
 /*! Get columns */
 PyObject *scribus_getcolumns(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getverticalalignment__doc__,
+QT_TR_NOOP("getVerticalAlignment([\"name\"]) -> integer\n\
+\n\
+Gets the vertical alignment of columns of the text frame \"name\". If \"name\" is not\n\
+given the currently selected item is used.\n\
+"));
+/*! Get columns */
+PyObject *scribus_getverticalalignment(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_setboxtext__doc__,
 QT_TR_NOOP("setText(\"text\", [\"name\"])\n\
@@ -275,6 +285,18 @@ May throw ValueError if number of columns is not at least one.\n\
 /*! Set columns */
 PyObject *scribus_setcolumns(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_setverticalalignment__doc__,
+QT_TR_NOOP("setVerticalAlignment(nr, [\"name\"])\n\
+\n\
+Sets the vertical alignment of columns of the text frame \"name\" to the integer \"nr\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+\n\
+May throw ValueError for an invalid alignment constant.\n\
+"));
+/*! Set vertical alignment */
+PyObject *scribus_setverticalalignment(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_setalign__doc__,
 QT_TR_NOOP("setTextAlignment(align, [\"name\"])\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index e57c4d041..861f3914f 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -415,7 +415,8 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("getText"), scribus_getframetext, METH_VARARGS, tr(scribus_getframetext__doc__)},
 	{const_cast<char*>("getTextShade"), scribus_getlineshade, METH_VARARGS, tr(scribus_getlineshade__doc__)},
 	{const_cast<char*>("getUnit"), (PyCFunction)scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)},
-	{const_cast<char*>("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)},
+    {const_cast<char*>("getVerticalAlignment"), scribus_getverticalalignment, METH_VARARGS, tr(scribus_getverticalalignment__doc__)},
+    {const_cast<char*>("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)},
 	{const_cast<char*>("getXFontNames"), (PyCFunction)scribus_xfontnames, METH_NOARGS, tr(scribus_xfontnames__doc__)},
 	{const_cast<char*>("gotoPage"), scribus_gotopage, METH_VARARGS, tr(scribus_gotopage__doc__)},
 	{const_cast<char*>("groupObjects"), (PyCFunction)scribus_groupobj, METH_VARARGS, tr(scribus_groupobj__doc__)},
@@ -563,7 +564,8 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("setTextShade"), scribus_settextshade, METH_VARARGS, tr(scribus_settextshade__doc__)},
 	{const_cast<char*>("setTextStroke"), scribus_settextstroke, METH_VARARGS, tr(scribus_settextstroke__doc__)},
 	{const_cast<char*>("setUnit"), scribus_setunit, METH_VARARGS, tr(scribus_setunit__doc__)},
-	{const_cast<char*>("setVGuides"), scribus_setVguides, METH_VARARGS, tr(scribus_setVguides__doc__)},
+    {const_cast<char*>("setVerticalAlignment"), scribus_setverticalalignment, METH_VARARGS, tr(scribus_setverticalalignment__doc__)},
+    {const_cast<char*>("setVGuides"), scribus_setVguides, METH_VARARGS, tr(scribus_setVguides__doc__)},
 	{const_cast<char*>("sizeObject"), scribus_sizeobjabs, METH_VARARGS, tr(scribus_sizeobjabs__doc__)},
 	{const_cast<char*>("statusMessage"), scribus_messagebartext, METH_VARARGS, tr(scribus_messagebartext__doc__)},
 	{const_cast<char*>("textFlowMode"), scribus_textflow, METH_VARARGS, tr(scribus_textflow__doc__)},
verticalalignment.patch (8,350 bytes)   

ale

2018-10-11 12:27

manager  

verticalalignment-2.patch (8,160 bytes)   
diff --git a/scribus/plugins/scripter/api_item.cpp b/scribus/plugins/scripter/api_item.cpp
index 6ae8a2dcb..78f22cd89 100644
--- a/scribus/plugins/scripter/api_item.cpp
+++ b/scribus/plugins/scripter/api_item.cpp
@@ -282,6 +282,18 @@ void ItemAPI::setColumns(int value)
 	item->Cols = value;
 }
 
+int ItemAPI::verticalAlignment()
+{
+	item->verticalAlignment();
+}
+
+void ItemAPI::setVerticalAlignment(int value)
+{
+	if (!checkHaveDocument())
+		RAISE("No document open");
+	item->setVerticalAlignment(value);
+}
+
 
 /**
  * Methods
diff --git a/scribus/plugins/scripter/api_item.h b/scribus/plugins/scripter/api_item.h
index 31c14ce44..738ee38ec 100644
--- a/scribus/plugins/scripter/api_item.h
+++ b/scribus/plugins/scripter/api_item.h
@@ -42,6 +42,7 @@ class ItemAPI : public QObject
 	Q_PROPERTY(double cornerRadius READ cornerRadius WRITE setCornerRadius)
 	Q_PROPERTY(double columnGap READ columnGap WRITE setColumnGap)
 	Q_PROPERTY(int columns READ columns WRITE setColumns)
+	Q_PROPERTY(int verticalAlignment READ verticalAlignment WRITE setVerticalAlignment)
 
 public:
     ItemAPI(PageItem *it);
@@ -134,6 +135,9 @@ private:
 	
 	int columns();
 	void setColumns(int value);
+
+	int verticalAlignment();
+	void setVerticalAlignment(int value);
 };
 
 #endif /*API_ITEM_H_*/
diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp
index 16e7cd6fa..17dc5c938 100644
--- a/scribus/plugins/scriptplugin/cmdtext.cpp
+++ b/scribus/plugins/scriptplugin/cmdtext.cpp
@@ -150,6 +150,24 @@ PyObject *scribus_getcolumns(PyObject* /* self */, PyObject* args)
 	return PyInt_FromLong(static_cast<long>(i->Cols));
 }
 
+PyObject *scribus_getverticalalignment(PyObject* /* self */, PyObject* args)
+{
+	char *Name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+		return nullptr;
+	if (!checkHaveDocument())
+		return nullptr;
+	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
+	if (i == nullptr)
+		return nullptr;
+	if (!i->isTextFrame())
+	{
+		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get vertical alignment of non-text frame.","python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+	return PyInt_FromLong(static_cast<long>(i->verticalAlignment()));
+}
+
 PyObject *scribus_getfontfeatures(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -709,6 +727,32 @@ PyObject *scribus_setcolumns(PyObject* /* self */, PyObject* args)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_setverticalalignment(PyObject* /* self */, PyObject* args)
+{
+	char *Name = const_cast<char*>("");
+	int w;
+	if (!PyArg_ParseTuple(args, "i|es", &w, "utf-8", &Name))
+		return nullptr;
+	if (!checkHaveDocument())
+		return nullptr;
+	if (w < 0)
+	{
+		PyErr_SetString(PyExc_ValueError, QObject::tr("Vertical alignment out of bounds, must be > 1.","python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+	PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
+	if (i == nullptr)
+		return nullptr;
+	if (!i->isTextFrame())
+	{
+		PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot set vertical alignment on a non-text frame.","python error").toLocal8Bit().constData());
+		return nullptr;
+	}
+	i->setVerticalAlignment(w);
+
+	Py_RETURN_NONE;
+}
+
 PyObject *scribus_selecttext(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -1243,9 +1287,11 @@ void cmdtextdocwarnings()
 	  << scribus_getframetext__doc__   << scribus_gettext__doc__
 	  << scribus_getlinespace__doc__   << scribus_getcolumngap__doc__
 	  << scribus_getcolumns__doc__     << scribus_setboxtext__doc__
+	  << scribus_getverticalalignment__doc__     << scribus_getverticalalignment__doc__
 	  << scribus_inserttext__doc__     << scribus_inserthtmltext__doc__<< scribus_setfont__doc__
 	  << scribus_setfontsize__doc__    << scribus_setlinespace__doc__
 	  << scribus_setcolumngap__doc__   << scribus_setcolumns__doc__
+	  << scribus_setverticalalignment__doc__   << scribus_setverticalalignment__doc__
 	  << scribus_setalign__doc__       << scribus_selecttext__doc__
 	  << scribus_deletetext__doc__     << scribus_settextfill__doc__
 	  << scribus_settextstroke__doc__  << scribus_settextshade__doc__
diff --git a/scribus/plugins/scriptplugin/cmdtext.h b/scribus/plugins/scriptplugin/cmdtext.h
index 7e9ebe9ef..ffba68dcc 100644
--- a/scribus/plugins/scriptplugin/cmdtext.h
+++ b/scribus/plugins/scriptplugin/cmdtext.h
@@ -134,6 +134,16 @@ given the currently selected item is used.\n\
 /*! Get columns */
 PyObject *scribus_getcolumns(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getverticalalignment__doc__,
+QT_TR_NOOP("getVerticalAlignment([\"name\"]) -> integer\n\
+\n\
+Gets the vertical alignment of columns of the text frame \"name\". If \"name\" is not\n\
+given the currently selected item is used.\n\
+"));
+/*! Get columns */
+PyObject *scribus_getverticalalignment(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_setboxtext__doc__,
 QT_TR_NOOP("setText(\"text\", [\"name\"])\n\
@@ -275,6 +285,18 @@ May throw ValueError if number of columns is not at least one.\n\
 /*! Set columns */
 PyObject *scribus_setcolumns(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_setverticalalignment__doc__,
+QT_TR_NOOP("setVerticalAlignment(nr, [\"name\"])\n\
+\n\
+Sets the vertical alignment of columns of the text frame \"name\" to the integer \"nr\".\n\
+If \"name\" is not given the currently selected item is used.\n\
+\n\
+May throw ValueError for an invalid alignment constant.\n\
+"));
+/*! Set vertical alignment */
+PyObject *scribus_setverticalalignment(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_setalign__doc__,
 QT_TR_NOOP("setTextAlignment(align, [\"name\"])\n\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index e57c4d041..861f3914f 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -415,7 +415,8 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("getText"), scribus_getframetext, METH_VARARGS, tr(scribus_getframetext__doc__)},
 	{const_cast<char*>("getTextShade"), scribus_getlineshade, METH_VARARGS, tr(scribus_getlineshade__doc__)},
 	{const_cast<char*>("getUnit"), (PyCFunction)scribus_getunit, METH_NOARGS, tr(scribus_getunit__doc__)},
-	{const_cast<char*>("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)},
+	{const_cast<char*>("getVerticalAlignment"), scribus_getverticalalignment, METH_VARARGS, tr(scribus_getverticalalignment__doc__)},
+	{const_cast<char*>("getVGuides"), (PyCFunction)scribus_getVguides, METH_NOARGS, tr(scribus_getVguides__doc__)},
 	{const_cast<char*>("getXFontNames"), (PyCFunction)scribus_xfontnames, METH_NOARGS, tr(scribus_xfontnames__doc__)},
 	{const_cast<char*>("gotoPage"), scribus_gotopage, METH_VARARGS, tr(scribus_gotopage__doc__)},
 	{const_cast<char*>("groupObjects"), (PyCFunction)scribus_groupobj, METH_VARARGS, tr(scribus_groupobj__doc__)},
@@ -563,7 +564,8 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("setTextShade"), scribus_settextshade, METH_VARARGS, tr(scribus_settextshade__doc__)},
 	{const_cast<char*>("setTextStroke"), scribus_settextstroke, METH_VARARGS, tr(scribus_settextstroke__doc__)},
 	{const_cast<char*>("setUnit"), scribus_setunit, METH_VARARGS, tr(scribus_setunit__doc__)},
-	{const_cast<char*>("setVGuides"), scribus_setVguides, METH_VARARGS, tr(scribus_setVguides__doc__)},
+	{const_cast<char*>("setVerticalAlignment"), scribus_setverticalalignment, METH_VARARGS, tr(scribus_setverticalalignment__doc__)},
+	{const_cast<char*>("setVGuides"), scribus_setVguides, METH_VARARGS, tr(scribus_setVguides__doc__)},
 	{const_cast<char*>("sizeObject"), scribus_sizeobjabs, METH_VARARGS, tr(scribus_sizeobjabs__doc__)},
 	{const_cast<char*>("statusMessage"), scribus_messagebartext, METH_VARARGS, tr(scribus_messagebartext__doc__)},
 	{const_cast<char*>("textFlowMode"), scribus_textflow, METH_VARARGS, tr(scribus_textflow__doc__)},
verticalalignment-2.patch (8,160 bytes)   

ale

2018-10-11 12:27

manager   ~0045510

patch with tabs instead of 4 spaces...

jghali

2018-10-14 10:35

administrator   ~0045513

I did quite a few modifications to the patch, but now it's in. Thanks!

Amongst the modifications I did are:
- use of ALIGNV_*constants similar to the ALIGN_* constants used by setTextAlignement() function
- rename get/setVerticalAlignment to get/setTextVerticalAlignment for consistency with other text functions

Issue History

Date Modified Username Field Change
2018-09-26 23:44 Gibbz New Issue
2018-10-11 04:13 Gibbz File Added: verticalalignment.patch
2018-10-11 04:13 Gibbz Note Added: 0045505
2018-10-11 06:14 ale Patch No => Yes
2018-10-11 12:27 ale File Added: verticalalignment-2.patch
2018-10-11 12:27 ale Note Added: 0045510
2018-10-12 09:07 ale Summary Vertical align columns not accessable in python/scripter => [patch] Vertical align columns not accessable in python/scripter
2018-10-14 10:31 jghali Summary [patch] Vertical align columns not accessable in python/scripter => Text vertical alignment not accessible from python/scripter
2018-10-14 10:35 jghali Assigned To => jghali
2018-10-14 10:35 jghali Status new => resolved
2018-10-14 10:35 jghali Resolution open => fixed
2018-10-14 10:35 jghali Fixed in Version => 1.5.5.svn
2018-10-14 10:35 jghali Note Added: 0045513
2019-06-04 20:56 cbradney Status resolved => closed