View Issue Details
ID | Project | Category | View Status | Date Submitted | Last Update |
---|---|---|---|---|---|
0015027 | Scribus | Scripter | public | 2017-10-24 10:35 | 2017-12-20 20:58 |
Reporter | jurajF | Assigned To | jghali | ||
Priority | normal | Severity | minor | Reproducibility | always |
Status | closed | Resolution | fixed | ||
Platform | x86_64 | OS | GNU/Linux | OS Version | Debian 8/Jessie |
Fixed in Version | 1.5.4.svn | ||||
Summary | 0015027: Scripter commands for creating and using Line Styles | ||||
Description | Recently there was a request in mailing list for setting styles to lines using python. As currently we do not have such command I made this patch that enable to create set and get line styles. It create style lines that you can later see in Style Manager and enable to use those named style with python commands. Attached is also an test.py file that show how to use those commands. | ||||
Tags | No tags attached. | ||||
Patch | Yes | ||||
|
0001-Get-Set-Custom-Line-Style-python-command.patch (7,908 bytes)
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 |
|
0002-Create-custom-line-style-python-command.patch (5,554 bytes)
From 29405f762dc371ad45b48570fb01aa1227991b0c Mon Sep 17 00:00:00 2001 From: Juraj Fedel <wtxnh-scribus@yahoo.com.au> Date: Sat, 21 Oct 2017 11:18:01 +0200 Subject: [PATCH 2/2] Create custom line style python command --- scribus/plugins/scriptplugin/cmdstyle.cpp | 67 +++++++++++++++++++++++++++ scribus/plugins/scriptplugin/cmdstyle.h | 19 ++++++++ scribus/plugins/scriptplugin/scriptplugin.cpp | 1 + 3 files changed, 87 insertions(+) diff --git a/scribus/plugins/scriptplugin/cmdstyle.cpp b/scribus/plugins/scriptplugin/cmdstyle.cpp index c5b16a026..ad599ea86 100644 --- a/scribus/plugins/scriptplugin/cmdstyle.cpp +++ b/scribus/plugins/scriptplugin/cmdstyle.cpp @@ -170,6 +170,72 @@ PyObject *scribus_createcharstyle(PyObject* /* self */, PyObject* args, PyObject Py_RETURN_NONE; } +PyObject *scribus_createcustomlinestyle(PyObject * /* self */, PyObject* args) +{ + char *Name = const_cast<char*>(""); + PyObject *obj; + + if (!PyArg_ParseTuple(args, "esO", "utf-8", &Name, &obj)) + return NULL; + + if (!PyList_Check(obj)) { + PyErr_SetString(PyExc_TypeError, "'style' must be list."); + return NULL; + } + + multiLine ml; + for (int i = 0; i < PyList_Size(obj); i++) { + PyObject *line = PyList_GetItem(obj, i); + if (!PyDict_Check(line)) { + PyErr_SetString(PyExc_TypeError, "elements of list must be Dictionary."); + return NULL; + } + struct SingleLine sl; + PyObject *val; + val = PyDict_GetItemString(line, "Color"); + if (val) { + sl.Color = PyString_AsString(val); + } else + sl.Color = ScCore->primaryMainWindow()->doc->itemToolPrefs().lineColor;; + val = PyDict_GetItemString(line, "Dash"); + if (val) { + sl.Dash = PyInt_AsLong(val); + } else + sl.Dash = Qt::SolidLine; + val = PyDict_GetItemString(line, "LineEnd"); + if (val) { + sl.LineEnd = PyInt_AsLong(val); + } else + sl.LineEnd = Qt::FlatCap; + val = PyDict_GetItemString(line, "LineJoin"); + if (val) { + sl.LineJoin = PyInt_AsLong(val); + } else + sl.LineJoin = Qt::MiterJoin; + val = PyDict_GetItemString(line, "Shade"); + if (val) { + sl.Shade = PyInt_AsLong(val); + } else + sl.Shade = ScCore->primaryMainWindow()->doc->itemToolPrefs().lineColorShade; + val = PyDict_GetItemString(line, "Width"); + if (val) { + sl.Width = PyFloat_AsDouble(val); + } else + sl.Width = ScCore->primaryMainWindow()->doc->itemToolPrefs().lineWidth; + + val = PyDict_GetItemString(line, "Shortcut"); + if (val) { + ml.shortcut = PyString_AsString(val); + } else + ml.shortcut = ""; + ml.push_back(sl); + } + if (ml.size() > 0) + ScCore->primaryMainWindow()->doc->MLineStyles[Name] = ml; + Py_RETURN_NONE; +} + + /*! HACK: this removes "warning: 'blah' defined but not used" compiler warnings with header files structure untouched (docstrings are kept near declarations) PV */ @@ -177,4 +243,5 @@ void cmdstyledocwarnings() { QStringList s; s << scribus_createparagraphstyle__doc__ << scribus_createcharstyle__doc__; + s << scribus_createcustomlinestyle__doc__; } diff --git a/scribus/plugins/scriptplugin/cmdstyle.h b/scribus/plugins/scriptplugin/cmdstyle.h index 127988485..d2ae6e575 100644 --- a/scribus/plugins/scriptplugin/cmdstyle.h +++ b/scribus/plugins/scriptplugin/cmdstyle.h @@ -82,5 +82,24 @@ tracking [optional] -> tracking of the text\n\n\ Special thanks go to avox for helping me! */ PyObject *scribus_createcharstyle(PyObject * /* self */, PyObject* args, PyObject* keywords); +/* LINE STYLES */ + +/*! docstring */ +PyDoc_STRVAR(scribus_createcustomlinestyle__doc__, +QT_TR_NOOP("createCustomLineStyle(styleName, style)\n\n\ +Creates the custom line style 'styleName'.\n\n\ +styleName -> name of the custom line style to create\n\n\ +This function takes list of dictionary\n\ +as parameter for \"style\". Each dictionary represent\n\ +one subline within style. Dictionary can have those keys:\n\n\ +\tColor [optional] -> name of the color to use (string)\n\n\ +\tDash [optional] -> type of line to use (integer)\n\n\ +\tLineEnd [optional] -> type of LineEnd to use (integer)\n\n\ +\tLineJoin [optional] -> type of LineJoin to use (integer)\n\n\ +\tShade [optional] -> opacity of line (integer)\n\n\ +\tWidth [optional] -> width of line (double)\n\ +")); +PyObject *scribus_createcustomlinestyle(PyObject * /* self */, PyObject* args); + #endif diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp index 8585177a9..be0723944 100644 --- a/scribus/plugins/scriptplugin/scriptplugin.cpp +++ b/scribus/plugins/scriptplugin/scriptplugin.cpp @@ -320,6 +320,7 @@ PyMethodDef scribus_methods[] = { {const_cast<char*>("createTable"), scribus_newtable, METH_VARARGS, tr(scribus_newtable__doc__)}, {const_cast<char*>("createParagraphStyle"), (PyCFunction)scribus_createparagraphstyle, METH_KEYWORDS, tr(scribus_createparagraphstyle__doc__)}, {const_cast<char*>("createCharStyle"), (PyCFunction)scribus_createcharstyle, METH_KEYWORDS, tr(scribus_createcharstyle__doc__)}, + {const_cast<char*>("createCustomLineStyle"), scribus_createcustomlinestyle, METH_VARARGS, tr(scribus_createcustomlinestyle__doc__)}, {const_cast<char*>("currentPage"), (PyCFunction)scribus_actualpage, METH_NOARGS, tr(scribus_actualpage__doc__)}, {const_cast<char*>("defineColor"), scribus_newcolor, METH_VARARGS, tr(scribus_newcolor__doc__)}, {const_cast<char*>("defineColorRGB"), scribus_newcolorrgb, METH_VARARGS, tr(scribus_newcolorrgb__doc__)}, -- 2.15.0.rc1 test.py (946 bytes)
import scribus scribus.newDocument(scribus.PAPER_A4, (15,15, 20, 20), scribus.PORTRAIT, 1, scribus.UNIT_POINTS, scribus.PAGE_1, 0, 1) line = scribus.createLine(100, 200, 110, 110, "testLine") # Dash can be number from 1 to 37 (util.cpp void getDashArray()) scribus.createCustomLineStyle("MyLine", [ { 'Color': "Blue", 'Dash': 2, # LINE_DASH = 2 'LineEnd': 32, # CAP_ROUND = 32 'LineJoin': 64, # JOIN_BEVEL = 64 'Shade': 75, 'Width': 2 } ]); scribus.createCustomLineStyle("Plain Line", [{}]); scribus.createCustomLineStyle("Red Line", [ { 'Color': "Red", } ]); scribus.createCustomLineStyle("Two Lines", [ { 'Color': "Yellow", 'Dash': 32, 'Width': 3 }, { 'Color': "Green", 'Dash': 5, 'Shade': 50, 'Width': 6 } ]); scribus.setCustomLineStyle("Two Lines", line) print scribus.getCustomLineStyle(line) scribus.saveDocAs("myline.sla") |
|
Applied, thanks! |
Date Modified | Username | Field | Change |
---|---|---|---|
2017-10-24 10:35 | jurajF | New Issue | |
2017-10-24 10:35 | jurajF | File Added: 0001-Get-Set-Custom-Line-Style-python-command.patch | |
2017-10-24 10:37 | jurajF | File Added: 0002-Create-custom-line-style-python-command.patch | |
2017-10-24 10:37 | jurajF | File Added: test.py | |
2017-10-26 18:04 | jghali | Assigned To | => jghali |
2017-10-26 18:04 | jghali | Status | new => resolved |
2017-10-26 18:04 | jghali | Resolution | open => fixed |
2017-10-26 18:04 | jghali | Fixed in Version | => 1.5.4.svn |
2017-10-26 18:04 | jghali | Note Added: 0044597 | |
2017-12-20 20:58 | cbradney | Status | resolved => closed |