r22784 by jghali - #15509: puzzling definition of scripter getTextColor() function
scribus-commit
scribus-commit at lists.scribus.net
Fri Dec 14 22:56:06 UTC 2018
Author: jghali
Date: Fri Dec 14 22:56:06 2018
New Revision: 22784
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=22784
Log:
#15509: puzzling definition of scripter getTextColor() function
Modified:
trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h
trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22784&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdgetprop.cpp Fri Dec 14 22:56:06 2018
@@ -105,18 +105,7 @@
it = GetUniqueItem(QString::fromUtf8(Name));
if (it == nullptr)
return nullptr;
- if ((it->HasSel) && ((it->itemType() == PageItem::TextFrame) || (it->itemType() == PageItem::PathText)))
- {
- for (int b = 0; b < it->itemText.length(); ++b)
- {
- if (it->itemText.selected(b))
- return PyString_FromString(it->itemText.charStyle(b).fillColor().toUtf8());
- }
- }
- else
- return PyString_FromString(it->lineColor().toUtf8());
- PyErr_SetString(NotFoundError, QObject::tr("Color not found - python error", "python error").toLocal8Bit().constData());
- return nullptr;
+ return PyString_FromString(it->lineColor().toUtf8());
}
PyObject *scribus_getlinetrans(PyObject* /* self */, PyObject* args)
@@ -163,17 +152,7 @@
it = GetUniqueItem(QString::fromUtf8(Name));
if (it == nullptr)
return nullptr;
- if ((it->HasSel) && ((it->itemType() == PageItem::TextFrame) || (it->itemType() == PageItem::PathText)))
- {
- for (int b = 0; b < it->itemText.length(); ++b)
- {
- if (it->itemText.selected(b))
- return PyInt_FromLong(static_cast<long>(it->itemText.charStyle(b).fillShade()));
- }
- }
- else
- return PyInt_FromLong(static_cast<long>(it->lineShade()));
- return PyInt_FromLong(0L);
+ return PyInt_FromLong(static_cast<long>(it->lineShade()));
}
PyObject *scribus_getlinejoin(PyObject* /* self */, PyObject* args)
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22784&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp Fri Dec 14 22:56:06 2018
@@ -98,6 +98,60 @@
return PyString_FromString(item->currentCharStyle().font().scName().toUtf8());
}
+PyObject *scribus_gettextcolor(PyObject* /* self */, PyObject* args)
+{
+ char *Name = const_cast<char*>("");
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+ return nullptr;
+ if (!checkHaveDocument())
+ return nullptr;
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == nullptr)
+ return nullptr;
+ if (!(item->isTextFrame()) && !(item->isPathText()))
+ {
+ PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text color of non-text frame.", "python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+ if (item->HasSel)
+ {
+ for (int i = 0; i < item->itemText.length(); ++i)
+ {
+ if (item->itemText.selected(i))
+ return PyString_FromString(item->itemText.charStyle(i).fillColor().toUtf8());
+ }
+ return nullptr;
+ }
+ return PyString_FromString(item->currentCharStyle().fillColor().toUtf8());
+}
+
+PyObject *scribus_gettextshade(PyObject* /* self */, PyObject* args)
+{
+ char *Name = const_cast<char*>("");
+ if (!PyArg_ParseTuple(args, "|es", "utf-8", &Name))
+ return nullptr;
+ if (!checkHaveDocument())
+ return nullptr;
+ PageItem *item = GetUniqueItem(QString::fromUtf8(Name));
+ if (item == nullptr)
+ return nullptr;
+ if (!(item->isTextFrame()) && !(item->isPathText()))
+ {
+ PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get text color of non-text frame.", "python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+ if (item->HasSel)
+ {
+ for (int i = 0; i < item->itemText.length(); ++i)
+ {
+ if (item->itemText.selected(i))
+ return PyInt_FromLong(item->itemText.charStyle(i).fillShade());
+ }
+ return nullptr;
+ }
+ return PyInt_FromLong(item->currentCharStyle().fillShade());
+}
+
PyObject *scribus_gettextsize(PyObject* /* self */, PyObject* args)
{
char *Name = const_cast<char*>("");
@@ -200,7 +254,7 @@
return nullptr;
if (!(item->isTextFrame()) && !(item->isPathText()))
{
- PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get fontfeatures of non-text frame.","python error").toLocal8Bit().constData());
+ PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get fontfeatures of non-text frame.","python error").toLocal8Bit().constData());
return nullptr;
}
if (item->HasSel)
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22784&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h Fri Dec 14 22:56:06 2018
@@ -48,6 +48,29 @@
/*! Get fontfeatures */
PyObject *scribus_getfontfeatures(PyObject * /*self*/, PyObject* args);
+/*! docstring */
+PyDoc_STRVAR(scribus_gettextcolor__doc__,
+ QT_TR_NOOP("getTextColor([\"name\"]) -> string\n\
+\n\
+Returns the name of the text color used for text frame \"name\".\n\
+If this text frame has some text selected the value assigned\n\
+to the first character of the selection is returned.\n\
+If \"name\" is not given the currently selected item is used.\n\
+"));
+/*! Returns color of the line */
+PyObject *scribus_gettextcolor(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
+PyDoc_STRVAR(scribus_gettextshade__doc__,
+ QT_TR_NOOP("getTextShade([\"name\"]) -> integer\n\
+\n\
+Returns the shade of text color used for text frame \"name\".\n\
+If this text frame has some text selected the value assigned\n\
+to the first character of the selection is returned.\n\
+If \"name\" is not given the currently selected item is used.\n\
+"));
+/*! Returns color of the line */
+PyObject *scribus_gettextshade(PyObject * /*self*/, PyObject* args);
/*! docstring */
PyDoc_STRVAR(scribus_gettextsize__doc__,
Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=22784&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp Fri Dec 14 22:56:06 2018
@@ -410,11 +410,11 @@
{const_cast<char*>("getTableColumnWidth"), scribus_gettablecolumnwidth, METH_VARARGS, tr(scribus_gettablecolumnwidth__doc__)},
{const_cast<char*>("getTableStyle"), scribus_gettablestyle, METH_VARARGS, tr(scribus_gettablestyle__doc__)},
{const_cast<char*>("getTableFillColor"), scribus_gettablefillcolor, METH_VARARGS, tr(scribus_gettablefillcolor__doc__)},
- {const_cast<char*>("getTextColor"), scribus_getlinecolor, METH_VARARGS, tr(scribus_getlinecolor__doc__)},
+ {const_cast<char*>("getText"), scribus_getframetext, METH_VARARGS, tr(scribus_getframetext__doc__)},
+ {const_cast<char*>("getTextColor"), scribus_gettextcolor, METH_VARARGS, tr(scribus_gettextcolor__doc__)},
{const_cast<char*>("getTextLength"), scribus_gettextsize, METH_VARARGS, tr(scribus_gettextsize__doc__)},
{const_cast<char*>("getTextLines"), scribus_gettextlines, METH_VARARGS, tr(scribus_gettextlines__doc__)},
- {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*>("getTextShade"), scribus_gettextshade, METH_VARARGS, tr(scribus_gettextshade__doc__)},
{const_cast<char*>("getTextVerticalAlignment"), scribus_gettextverticalalignment, METH_VARARGS, tr(scribus_gettextverticalalignment__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__)},
More information about the scribus-commit
mailing list