From 4a437814480d9e9c1e0dcf043a9252b7426ed598 Mon Sep 17 00:00:00 2001
From: Juraj Fedel <wtxnh-scribus@yahoo.com.au>
Date: Sat, 21 Oct 2017 10:48:44 +0200
Subject: [PATCH 1/2] Get/Set Custom Line Style python command

---
 scribus/plugins/scriptplugin/cmdgetprop.cpp   | 15 +++++++++++++++
 scribus/plugins/scriptplugin/cmdgetprop.h     | 10 ++++++++++
 scribus/plugins/scriptplugin/cmdsetprop.cpp   | 23 +++++++++++++++++++++++
 scribus/plugins/scriptplugin/cmdsetprop.h     | 17 +++++++++++++++--
 scribus/plugins/scriptplugin/scriptplugin.cpp |  2 ++
 5 files changed, 65 insertions(+), 2 deletions(-)

diff --git a/scribus/plugins/scriptplugin/cmdgetprop.cpp b/scribus/plugins/scriptplugin/cmdgetprop.cpp
index 8a2a0cfdc..7a47818c5 100644
--- a/scribus/plugins/scriptplugin/cmdgetprop.cpp
+++ b/scribus/plugins/scriptplugin/cmdgetprop.cpp
@@ -80,6 +80,20 @@ PyObject *scribus_getfillblend(PyObject* /* self */, PyObject* args)
 	return i != NULL ? PyInt_FromLong(static_cast<long>(i->fillBlendmode())) : NULL;
 }
 
+PyObject *scribus_getcustomlinestyle(PyObject* /* self */, PyObject* args)
+{
+	char *Name = const_cast<char*>("");
+	if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+		return NULL;
+	if(!checkHaveDocument())
+		return NULL;
+	PageItem *it;
+	it = GetUniqueItem(QString::fromUtf8(Name));
+	if (it == NULL)
+		return NULL;
+	return PyString_FromString(it->customLineStyle().toUtf8());
+}
+
 PyObject *scribus_getlinecolor(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -386,6 +400,7 @@ void cmdgetpropdocwarnings()
 {
 	QStringList s;
 	s << scribus_getobjecttype__doc__ << scribus_getfillcolor__doc__
+	  << scribus_getcustomlinestyle__doc__
 	  << scribus_getfilltrans__doc__ << scribus_getfillblend__doc__ 
 	  << scribus_getlinecolor__doc__ << scribus_getlinetrans__doc__ 
 	  << scribus_getlineblend__doc__ << scribus_getlinewidth__doc__ 
diff --git a/scribus/plugins/scriptplugin/cmdgetprop.h b/scribus/plugins/scriptplugin/cmdgetprop.h
index 301dd94e7..4924ffa9a 100644
--- a/scribus/plugins/scriptplugin/cmdgetprop.h
+++ b/scribus/plugins/scriptplugin/cmdgetprop.h
@@ -51,6 +51,16 @@ is not given the currently selected Item is used.\n\
 /*! Returns fill blendmode of the object */
 PyObject *scribus_getfillblend(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_getcustomlinestyle__doc__,
+QT_TR_NOOP("getCustomLineStyle([\"name\"]) -> string\n\
+\n\
+Returns the styleName of custom line style for the object. If object's \"name\" is not given the\n\
+currently selected item is used.\n\
+"));
+/*! Returns custom style of the line */
+PyObject *scribus_getcustomlinestyle(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_getlinecolor__doc__,
 QT_TR_NOOP("getLineColor([\"name\"]) -> string\n\
diff --git a/scribus/plugins/scriptplugin/cmdsetprop.cpp b/scribus/plugins/scriptplugin/cmdsetprop.cpp
index c8adb7aab..4d5398741 100644
--- a/scribus/plugins/scriptplugin/cmdsetprop.cpp
+++ b/scribus/plugins/scriptplugin/cmdsetprop.cpp
@@ -178,6 +178,28 @@ PyObject *scribus_setfillblend(PyObject* /* self */, PyObject* args)
 	Py_RETURN_NONE;
 }
 
+PyObject *scribus_setcustomlinestyle(PyObject* /* self */, PyObject* args)
+{
+	char *Name = const_cast<char*>("");
+	char *Style;
+	if (!PyArg_ParseTuple(args, "es|es", "utf-8", &Style, "utf-8", &Name))
+		return NULL;
+	if(!checkHaveDocument())
+		return NULL;
+	PageItem *it = GetUniqueItem(QString::fromUtf8(Name));
+	if (it == NULL)
+		return NULL;
+	QString qStyle = QString::fromUtf8(Style);
+	if (! ScCore->primaryMainWindow()->doc->MLineStyles.contains(qStyle))
+	{
+		PyErr_SetString(NotFoundError, QObject::tr("Line Style not found.","python error").toLocal8Bit().constData());
+		return NULL;
+
+	}
+	it->setCustomLineStyle(qStyle);
+	Py_RETURN_NONE;
+}
+
 PyObject *scribus_setlinecolor(PyObject* /* self */, PyObject* args)
 {
 	char *Name = const_cast<char*>("");
@@ -510,6 +532,7 @@ void cmdsetpropdocwarnings()
 {
 	QStringList s;
 	s << scribus_setgradfill__doc__  << scribus_setgradstop__doc__
+	  << scribus_setcustomlinestyle__doc__
 	  << scribus_setfillcolor__doc__ << scribus_setfilltrans__doc__ 
 	  << scribus_setfillblend__doc__ << scribus_setlinecolor__doc__ 
 	  << scribus_setlinetrans__doc__ << scribus_setlineblend__doc__ 
diff --git a/scribus/plugins/scriptplugin/cmdsetprop.h b/scribus/plugins/scriptplugin/cmdsetprop.h
index f4fcab54d..eaba38d5a 100644
--- a/scribus/plugins/scriptplugin/cmdsetprop.h
+++ b/scribus/plugins/scriptplugin/cmdsetprop.h
@@ -65,6 +65,17 @@ If \"name\" is not given the currently selected item is used.\n\
 /*! Set fill blendmode */
 PyObject *scribus_setfillblend(PyObject * /*self*/, PyObject* args);
 
+/*! docstring */
+PyDoc_STRVAR(scribus_setcustomlinestyle__doc__,
+QT_TR_NOOP("setCustomLineStyle(\"styleName\", [\"name\"])\n\
+\n\
+Sets the custom line style of the object \"name\" to \"styleName\"\n\
+Argument \"styleName\" is string - name of line style as seen in Style Manager\n\
+If \"name\" is not given the currently selected item is used.\n\
+"));
+/*! Set custom line style */
+PyObject *scribus_setcustomlinestyle(PyObject * /*self*/, PyObject* args);
+
 /*! docstring */
 PyDoc_STRVAR(scribus_setlinecolor__doc__,
 QT_TR_NOOP("setLineColor(\"color\", [\"name\"])\n\
@@ -149,8 +160,10 @@ PyDoc_STRVAR(scribus_setlinestyle__doc__,
 QT_TR_NOOP("setLineStyle(style, [\"name\"])\n\
 \n\
 Sets the line style of the object \"name\" to the style \"style\". If \"name\"\n\
-is not given the currently selected item is used. There are predefined\n\
-constants for \"style\" - LINE_<style>.\n\
+is not given the currently selected item is used.\n\
+Argument for this function is number - value from 1 to 37\n\
+There are few predefined constants for \"style\" - LINE_<style>.\n\
+In Property Palette this feature is selected in box named 'Type of line'\n\
 "));
 /*! Set line end */
 PyObject *scribus_setlinestyle(PyObject * /*self*/, PyObject* args);
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 82aa3b5c6..8585177a9 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -354,6 +354,7 @@ PyMethodDef scribus_methods[] = {
 	{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*>("getCornerRadius"), scribus_getcornerrad, METH_VARARGS, tr(scribus_getcornerrad__doc__)},
+	{const_cast<char*>("getCustomLineStyle"), scribus_getcustomlinestyle, METH_VARARGS, tr(scribus_getcustomlinestyle__doc__)},
 	{const_cast<char*>("getFillColor"), scribus_getfillcolor, METH_VARARGS, tr(scribus_getfillcolor__doc__)},
 	{const_cast<char*>("getFillShade"), scribus_getfillshade, METH_VARARGS, tr(scribus_getfillshade__doc__)},
 	{const_cast<char*>("getFillBlendmode"), scribus_getfillblend, METH_VARARGS, tr(scribus_getfillblend__doc__)},
@@ -490,6 +491,7 @@ PyMethodDef scribus_methods[] = {
 	{const_cast<char*>("setColumns"), scribus_setcolumns, METH_VARARGS, tr(scribus_setcolumns__doc__)},
 	{const_cast<char*>("setCornerRadius"), scribus_setcornerrad, METH_VARARGS, tr(scribus_setcornerrad__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__)},
 	{const_cast<char*>("setDocType"), scribus_setdoctype, METH_VARARGS, tr(scribus_setdoctype__doc__)},
 	{const_cast<char*>("setFillColor"), scribus_setfillcolor, METH_VARARGS, tr(scribus_setfillcolor__doc__)},
 	{const_cast<char*>("setFillTransparency"), scribus_setfilltrans, METH_VARARGS, tr(scribus_setfilltrans__doc__)},
-- 
2.15.0.rc1

