View Issue Details

IDProjectCategoryView StatusLast Update
0015800ScribusScripterpublic2019-12-08 21:24
Reporterchefe Assigned Tojghali  
PrioritynormalSeverityfeatureReproducibilityunable to reproduce
Status closedResolutionfixed 
Product Version 
Target VersionFixed in Version1.5.6.svn 
Summary0015800: Add tabs support for scripter plugin
DescriptionAdd support to the scripter plugin to define tabs while creating a new paragraph style.

see https://github.com/scribusproject/scribus/pull/123
TagsNo tags attached.
PatchNo

Activities

chefe

2019-09-02 20:04

reporter   ~0046615

translation for french is not already done (english placeholder was inserted)

ale

2019-09-03 12:20

manager   ~0046620

i've commented the patch on github...

chefe

2019-09-28 08:42

reporter   ~0046711

I have created a new version of the patch based on the comment from the github. The patch is based on 5a813359d47bf7f45ad6f1a86196f7f74238a23c (https://github.com/scribusproject/scribus/commit/5a813359d47bf7f45ad6f1a86196f7f74238a23c).

tabs-support-for-scripter.patch (12,972 bytes)
From f8249e633857b899bfa0d3f902a17a138ca00717 Mon Sep 17 00:00:00 2001
From: chefe <hi@chefe.io>
Date: Sat, 28 Sep 2019 10:36:57 +0200
Subject: [PATCH] Add tabs support for scripter

---
 doc/de/scripterapi-constants.html             | 11 +++++
 doc/de/scripterapi-styles.html                |  8 ++++
 doc/en/scripterapi-constants.html             | 11 +++++
 doc/en/scripterapi-styles.html                |  8 ++++
 doc/fr/scripterapi-constants.html             | 11 +++++
 doc/fr/scripterapi-styles.html                |  8 ++++
 doc/it/scripterapi-constants.html             | 11 +++++
 doc/it/scripterapi-styles.html                |  8 ++++
 scribus/plugins/scriptplugin/cmdstyle.cpp     | 44 +++++++++++++++++--
 scribus/plugins/scriptplugin/cmdstyle.h       |  5 +++
 scribus/plugins/scriptplugin/scriptplugin.cpp |  6 +++
 11 files changed, 128 insertions(+), 3 deletions(-)

diff --git a/doc/de/scripterapi-constants.html b/doc/de/scripterapi-constants.html
index 36fcacf1d..1c4124a7b 100644
--- a/doc/de/scripterapi-constants.html
+++ b/doc/de/scripterapi-constants.html
@@ -295,5 +295,16 @@ you write 'value*mm/inch' .</p>
 </dl>
 </td></tr></table>
 
+<h4>Tab alignment</h4>
+<table><tr><td>
+<dl>
+	<dt>TAB_LEFT</dt>
+	<dt>TAB_RIGHT</dt>
+	<dt>TAB_PERIOD</dt>
+	<dt>TAB_COMMA</dt>
+	<dt>TAB_CENTER</dt>
+</dl>
+</td></tr></table>
+
 </body>
 </html>
diff --git a/doc/de/scripterapi-styles.html b/doc/de/scripterapi-styles.html
index ead9a9db3..c9b2c9384 100644
--- a/doc/de/scripterapi-styles.html
+++ b/doc/de/scripterapi-styles.html
@@ -163,6 +163,14 @@
 <li>dropcapoffset [optional] -> offset of the caps if used</li>
 <li>"charstyle" [optional] -> char style to use</li>
 <li>"bullet" [optional] -> string to use as bullet</li>
+<li>"tabs" [optional] -> a list of tab definitions
+<ul>
+    <li>a tab is defined as a tuple with the following format (position,type,fillchar)</li>
+    <li>position [required] -> float value for the position</li>
+    <li>type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4</li>
+    <li>fillchar [optional] -> the char to fill the space; default is none</li>
+</ul>
+</li>
 </ul>
 </p>
 <p>If you wish to skip a number of settings, unfortunately, this command will not accept null values, i.e., a series of commas. You <i>must</i> put some integer value for each of the potential parameters. For example, imagine you wish to only specify a name for the Paragraph Style, and the Character Style. Your command should be something like:
diff --git a/doc/en/scripterapi-constants.html b/doc/en/scripterapi-constants.html
index c5b814548..c79da2668 100644
--- a/doc/en/scripterapi-constants.html
+++ b/doc/en/scripterapi-constants.html
@@ -307,5 +307,16 @@ you write 'value*mm/inch' .</p>
 </dl>
 </td></tr></table>
 
+<h4>Tab alignment</h4>
+<table><tr><td>
+<dl>
+	<dt>TAB_LEFT</dt>
+	<dt>TAB_RIGHT</dt>
+	<dt>TAB_PERIOD</dt>
+	<dt>TAB_COMMA</dt>
+	<dt>TAB_CENTER</dt>
+</dl>
+</td></tr></table>
+
 </body>
 </html>
diff --git a/doc/en/scripterapi-styles.html b/doc/en/scripterapi-styles.html
index ead9a9db3..c9b2c9384 100644
--- a/doc/en/scripterapi-styles.html
+++ b/doc/en/scripterapi-styles.html
@@ -163,6 +163,14 @@
 <li>dropcapoffset [optional] -> offset of the caps if used</li>
 <li>"charstyle" [optional] -> char style to use</li>
 <li>"bullet" [optional] -> string to use as bullet</li>
+<li>"tabs" [optional] -> a list of tab definitions
+<ul>
+    <li>a tab is defined as a tuple with the following format (position,type,fillchar)</li>
+    <li>position [required] -> float value for the position</li>
+    <li>type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4</li>
+    <li>fillchar [optional] -> the char to fill the space; default is none</li>
+</ul>
+</li>
 </ul>
 </p>
 <p>If you wish to skip a number of settings, unfortunately, this command will not accept null values, i.e., a series of commas. You <i>must</i> put some integer value for each of the potential parameters. For example, imagine you wish to only specify a name for the Paragraph Style, and the Character Style. Your command should be something like:
diff --git a/doc/fr/scripterapi-constants.html b/doc/fr/scripterapi-constants.html
index e8c02d8cc..d40a49029 100644
--- a/doc/fr/scripterapi-constants.html
+++ b/doc/fr/scripterapi-constants.html
@@ -303,6 +303,17 @@ Ainsi, pour convertir les pouces en points, il suffit d'écrire 'valeur/inch'; p
 </dl>
 </td></tr></table>
 
+<h4>Tab alignment</h4>
+<table><tr><td>
+<dl>
+	<dt>TAB_LEFT</dt>
+	<dt>TAB_RIGHT</dt>
+	<dt>TAB_PERIOD</dt>
+	<dt>TAB_COMMA</dt>
+	<dt>TAB_CENTER</dt>
+</dl>
+</td></tr></table>
+
 </body>
 </html>
  
diff --git a/doc/fr/scripterapi-styles.html b/doc/fr/scripterapi-styles.html
index 063fd7cd7..85c009172 100644
--- a/doc/fr/scripterapi-styles.html
+++ b/doc/fr/scripterapi-styles.html
@@ -160,6 +160,14 @@
 <li>dropcapoffset [optionnel] -> décalage horizontal des lettrines si l'utilisation de lettrines est activée</li>
 <li>"charstyle" [optionnel] -> nom du style de caractère à utiliser</li>
 <li>"bullet" [optionnel] -> chaîne de caractère à utiliser pour les puces</li>
+<li>"tabs" [optional] -> a list of tab definitions
+<ul>
+    <li>a tab is defined as a tuple with the following format (position,type,fillchar)</li>
+    <li>position [required] -> float value for the position</li>
+    <li>type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4</li>
+    <li>fillchar [optional] -> the char to fill the space; default is none</li>
+</ul>
+</li>
 </ul>
 </p>
 <p>Si vous désirez omettre un certain nombre d'éléments, cette fonction n'acceptera pas de valeurs null, i.e., une série de virgule. Vous <i>devez</i> spécifier un paramètre entier pour chacun des paramètres omis. Par example, si vous désirez spécifier uniquement un nom de style de paragraphe et un nom de style de caractère, votre appel de fonction ressemblera à ceci:
diff --git a/doc/it/scripterapi-constants.html b/doc/it/scripterapi-constants.html
index e712c4966..fa054e075 100644
--- a/doc/it/scripterapi-constants.html
+++ b/doc/it/scripterapi-constants.html
@@ -295,5 +295,16 @@ you write 'value*mm/inch' .</p>
 </dl>
 </td></tr></table>
 
+<h4>Tab alignment</h4>
+<table><tr><td>
+<dl>
+	<dt>TAB_LEFT</dt>
+	<dt>TAB_RIGHT</dt>
+	<dt>TAB_PERIOD</dt>
+	<dt>TAB_COMMA</dt>
+	<dt>TAB_CENTER</dt>
+</dl>
+</td></tr></table>
+
 </body>
 </html>
diff --git a/doc/it/scripterapi-styles.html b/doc/it/scripterapi-styles.html
index ead9a9db3..c9b2c9384 100644
--- a/doc/it/scripterapi-styles.html
+++ b/doc/it/scripterapi-styles.html
@@ -163,6 +163,14 @@
 <li>dropcapoffset [optional] -> offset of the caps if used</li>
 <li>"charstyle" [optional] -> char style to use</li>
 <li>"bullet" [optional] -> string to use as bullet</li>
+<li>"tabs" [optional] -> a list of tab definitions
+<ul>
+    <li>a tab is defined as a tuple with the following format (position,type,fillchar)</li>
+    <li>position [required] -> float value for the position</li>
+    <li>type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4</li>
+    <li>fillchar [optional] -> the char to fill the space; default is none</li>
+</ul>
+</li>
 </ul>
 </p>
 <p>If you wish to skip a number of settings, unfortunately, this command will not accept null values, i.e., a series of commas. You <i>must</i> put some integer value for each of the potential parameters. For example, imagine you wish to only specify a name for the Paragraph Style, and the Character Style. Your command should be something like:
diff --git a/scribus/plugins/scriptplugin/cmdstyle.cpp b/scribus/plugins/scriptplugin/cmdstyle.cpp
index 0f907b0f9..11ad78a9b 100644
--- a/scribus/plugins/scriptplugin/cmdstyle.cpp
+++ b/scribus/plugins/scriptplugin/cmdstyle.cpp
@@ -39,17 +39,19 @@ PyObject *scribus_createparagraphstyle(PyObject* /* self */, PyObject* args, PyO
 			const_cast<char*>("dropcapoffset"),
 			const_cast<char*>("charstyle"),
 			const_cast<char*>("bullet"),
+			const_cast<char*>("tabs"),
 			nullptr};
 	char *name = const_cast<char*>(""), *charStyle = const_cast<char*>("");
 	char *bullet = const_cast<char*>("");
 	int lineSpacingMode = 0, alignment = 0, dropCapLines = 2, hasDropCap = 0;
 	double lineSpacing = 15.0, leftMargin = 0.0, rightMargin = 0.0;
 	double gapBefore = 0.0, gapAfter = 0.0, firstIndent = 0.0, peOffset = 0;
-	if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|ididddddiideses",
+	PyObject *tabDefinitions = nullptr;
+	if (!PyArg_ParseTupleAndKeywords(args, keywords, "es|ididddddiidesesO",
 		 keywordargs, "utf-8", &name, &lineSpacingMode, &lineSpacing, &alignment,
 		&leftMargin, &rightMargin, &gapBefore, &gapAfter, &firstIndent,
 		&hasDropCap, &dropCapLines, &peOffset, "utf-8", &charStyle,
-		"utf-8", &bullet))
+		"utf-8", &bullet, &tabDefinitions))
 		return nullptr;
 	if (!checkHaveDocument())
 		return nullptr;
@@ -105,10 +107,46 @@ PyObject *scribus_createparagraphstyle(PyObject* /* self */, PyObject* args, PyO
 	{
 		tmpParagraphStyle.setHasBullet(false);
 	}
-	
+
 	tmpParagraphStyle.setParEffectOffset(peOffset);
 	tmpParagraphStyle.charStyle().setParent(charStyle);
 
+	if (tabDefinitions != nullptr)
+	{
+		int n = PyList_Size(tabDefinitions);
+		for (int i = 0; i < n; i++)
+		{
+			PyObject* tabDefinition = PyList_GetItem(tabDefinitions, i);
+			int size = PyTuple_Check(tabDefinition) ? PyTuple_Size(tabDefinition) : 1;
+			PyObject* tabPositionDefinition = PyTuple_Check(tabDefinition) ? PyTuple_GetItem(tabDefinition, 0) : tabDefinition;
+
+			float tabPosition = 0.0;
+			if (!PyArg_Parse(tabPositionDefinition, "f", &tabPosition))
+			{
+				PyErr_SetString(PyExc_TypeError, QObject::tr("invalid tab-position specified.","python error").toLocal8Bit().constData());
+				return nullptr;
+			}
+
+			int tabType = 0;
+			if (size >= 2) {
+				PyArg_Parse(PyTuple_GetItem(tabDefinition, 1), "i", &tabType);
+			}
+
+			char *fillChar = const_cast<char*>("");
+			if (size == 3) {
+				PyArg_Parse(PyTuple_GetItem(tabDefinition, 2), "es", "utf-8", &fillChar);
+			}
+
+			QString fillCharString = QString::fromUtf8(fillChar).trimmed();
+
+			ParagraphStyle::TabRecord tr;
+			tr.tabFillChar = (fillCharString.size() > 0) ? fillCharString.at(0) : QChar();
+			tr.tabPosition = static_cast<qreal>(tabPosition);
+			tr.tabType = tabType;
+			tmpParagraphStyle.appendTabValue(tr);
+		}
+	}
+
 	StyleSet<ParagraphStyle> tmpStyleSet;
 	tmpStyleSet.create(tmpParagraphStyle);
 	ScCore->primaryMainWindow()->doc->redefineStyles(tmpStyleSet, false);
diff --git a/scribus/plugins/scriptplugin/cmdstyle.h b/scribus/plugins/scriptplugin/cmdstyle.h
index 25df7bbbc..fc3eb0746 100644
--- a/scribus/plugins/scriptplugin/cmdstyle.h
+++ b/scribus/plugins/scriptplugin/cmdstyle.h
@@ -41,6 +41,11 @@ dropcaplines [optional] -> height (in lines) of the caps if used\n\n\
 dropcapoffset [optional] -> offset of the caps if used\n\n\
 \"charstyle\" [optional] -> char style to use\n\n\
 \"bullet\" [optional] -> string to use as bullet\n\n\
+\"tabs\" [optional] -> a list containg tab definitions\n\n\
+-> a tab is defined as a tuple with the following format (position,type,fillchar)\"\n\n\
+-> position [required] -> float value for the position\n\n\
+-> type [optional] -> left: 0 [default], right: 1, period: 2, comma: 3, center: 4\n\n\
+-> fillchar [optional] -> the char to fill the space; default is none\n\n\
 "));
 /*! 02.01.2007 - 05.01.2007 : Joachim Neu : Create a paragraph style.
   		Special thanks go to avox for helping me! */
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 2149ef910..d8b840127 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -784,6 +784,12 @@ void initscribus(ScribusMainWindow *mainWin)
 	PyDict_SetItemString(d, const_cast<char*>("PAGE_2"), Py_BuildValue(const_cast<char*>("i"), 1));
 	PyDict_SetItemString(d, const_cast<char*>("PAGE_3"), Py_BuildValue(const_cast<char*>("i"), 2));
 	PyDict_SetItemString(d, const_cast<char*>("PAGE_4"), Py_BuildValue(const_cast<char*>("i"), 3));
+	// tab alignment
+	PyDict_SetItemString(d, const_cast<char*>("TAB_LEFT"), Py_BuildValue(const_cast<char*>("i"), 0));
+	PyDict_SetItemString(d, const_cast<char*>("TAB_RIGHT"), Py_BuildValue(const_cast<char*>("i"), 1));
+	PyDict_SetItemString(d, const_cast<char*>("TAB_PERIOD"), Py_BuildValue(const_cast<char*>("i"), 2));
+	PyDict_SetItemString(d, const_cast<char*>("TAB_COMMA"), Py_BuildValue(const_cast<char*>("i"), 3));
+	PyDict_SetItemString(d, const_cast<char*>("TAB_CENTER"), Py_BuildValue(const_cast<char*>("i"), 4));
 
 	// Measurement units understood by Scribus's units.cpp functions are exported as constant conversion
 	// factors to be used from Python.
-- 
2.23.0

chefe

2019-09-28 08:49

reporter   ~0046712

The gitlab pipeline to create the appimage is running on my account (see https://gitlab.com/chefe/scribus/commits/tabs-support-for-scripter)

ale

2019-09-28 10:10

manager   ~0046713

as written on github, the patch now looks good to me...

jghali

2019-10-03 04:22

administrator   ~0046730

Committed! I did the French translation.

Issue History

Date Modified Username Field Change
2019-09-02 19:57 chefe New Issue
2019-09-02 20:04 chefe Note Added: 0046615
2019-09-03 12:20 ale Note Added: 0046620
2019-09-28 08:42 chefe File Added: tabs-support-for-scripter.patch
2019-09-28 08:42 chefe Note Added: 0046711
2019-09-28 08:49 chefe Note Added: 0046712
2019-09-28 10:10 ale Note Added: 0046713
2019-10-03 04:22 jghali Assigned To => jghali
2019-10-03 04:22 jghali Status new => resolved
2019-10-03 04:22 jghali Resolution open => fixed
2019-10-03 04:22 jghali Fixed in Version => 1.5.6.svn
2019-10-03 04:22 jghali Note Added: 0046730
2019-12-08 21:24 cbradney Status resolved => closed