r24043 by jghali - #16254: Add getCellText() function scripter
scribus-commit
scribus-commit at lists.scribus.net
Mon Sep 28 22:48:43 UTC 2020
Author: jghali
Date: Mon Sep 28 22:48:43 2020
New Revision: 24043
URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=24043
Log:
#16254: Add getCellText() function scripter
Modified:
trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.cpp
trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.h
trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.cpp
trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.h
trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptplugin.cpp
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24043&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.cpp Mon Sep 28 22:48:43 2020
@@ -10,7 +10,50 @@
#include "cmdcell.h"
#include "cmdutil.h"
#include "pageitem_table.h"
+#include "pageitem_textframe.h"
#include "tableborder.h"
+
+PyObject *scribus_getcelltext(PyObject* /* self */, PyObject* args)
+{
+ char *Name = const_cast<char*>("");
+ int row, column;
+ if (!PyArg_ParseTuple(args, "ii|es", &row, &column, "utf-8", &Name))
+ return nullptr;
+ if (!checkHaveDocument())
+ return nullptr;
+ PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
+ if (i == nullptr)
+ return nullptr;
+ PageItem_Table *table = i->asTable();
+ if (!table)
+ {
+ PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get cell text on a non-table item.","python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+ if (column < 0 || column >= table->columns() || row < 0 || row >= table->rows())
+ {
+ PyErr_SetString(PyExc_ValueError, QObject::tr("The cell %1,%2 does not exist in table", "python error").arg(row).arg(column).toLocal8Bit().constData());
+ return nullptr;
+ }
+
+ PageItem* textFrame = table->cellAt(row, column).textFrame();
+ const StoryText& story = textFrame->itemText;
+ QString text;
+ text.reserve(story.hasSelection() ? story.selectionLength() : story.length());
+ for (int i = 0; i < story.length(); i++)
+ {
+ if (textFrame->HasSel)
+ {
+ if (story.selected(i))
+ text += story.text(i);
+ }
+ else
+ {
+ text += story.text(i);
+ }
+ }
+ return PyUnicode_FromString(text.toUtf8());
+}
PyObject *scribus_setcelltext(PyObject* /* self */, PyObject* args)
{
@@ -61,6 +104,9 @@
PyErr_SetString(PyExc_ValueError, QObject::tr("The cell %1,%2 does not exist in table", "python error").arg(row).arg(column).toLocal8Bit().constData());
return nullptr;
}
+
+
+
return PyUnicode_FromString(table->cellAt(row, column).styleName().toUtf8());
}
@@ -461,6 +507,7 @@
<< scribus_getcellfillcolor__doc__
<< scribus_getcellrowspan__doc__
<< scribus_getcellstyle__doc__
+ << scribus_getcelltext__doc__
<< scribus_setcellbottomborder__doc__
<< scribus_setcellbottompadding__doc__
<< scribus_setcellfillcolor__doc__
Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24043&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdcell.h Mon Sep 28 22:48:43 2020
@@ -16,6 +16,19 @@
#define CMDCELL_H
/*! docstring */
+PyDoc_STRVAR(scribus_getcelltext__doc__,
+QT_TR_NOOP("getCellText(row, column, [\"name\"]) -> string\n\
+\n\
+Returns the text content of the cell at \"row\", \"column\" in the table \"name\".\n\
+If cell has some text selected, the selected text is returned.\n\
+If \"name\" is not given the currently selected item is used.\n\
+\n\
+May throw ValueError if the cell does not exist.\n\
+"));
+/*! Get cell text */
+PyObject *scribus_getcelltext(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
PyDoc_STRVAR(scribus_setcelltext__doc__,
QT_TR_NOOP("setCellText(row, column, text, [\"name\"])\n\
\n\
Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24043&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp Mon Sep 28 22:48:43 2020
@@ -334,11 +334,12 @@
{const_cast<char*>("getAllObjects"), (PyCFunction)scribus_getallobj, METH_VARARGS|METH_KEYWORDS, tr(scribus_getallobj__doc__)},
{const_cast<char*>("getAllStyles"), (PyCFunction)scribus_getparagraphstyles, METH_NOARGS, tr(scribus_getallstyles__doc__)}, //Deprecated
{const_cast<char*>("getAllText"), scribus_getalltext, METH_VARARGS, tr(scribus_getalltext__doc__)},
+ {const_cast<char*>("getCellColumnSpan"), scribus_getcellcolumnspan, METH_VARARGS, tr(scribus_getcellcolumnspan__doc__)},
+ {const_cast<char*>("getCellFillColor"), scribus_getcellfillcolor, METH_VARARGS, tr(scribus_getcellfillcolor__doc__)},
+ {const_cast<char*>("getCellRowSpan"), scribus_getcellrowspan, METH_VARARGS, tr(scribus_getcellrowspan__doc__)},
{const_cast<char*>("getCellStyle"), scribus_getcellstyle, METH_VARARGS, tr(scribus_getcellstyle__doc__)},
{const_cast<char*>("getCellStyles"), (PyCFunction)scribus_getcellstyles, METH_VARARGS, tr(scribus_getcellstyles__doc__)},
- {const_cast<char*>("getCellColumnSpan"), scribus_getcellcolumnspan, METH_VARARGS, tr(scribus_getcellcolumnspan__doc__)},
- {const_cast<char*>("getCellRowSpan"), scribus_getcellrowspan, METH_VARARGS, tr(scribus_getcellrowspan__doc__)},
- {const_cast<char*>("getCellFillColor"), scribus_getcellfillcolor, METH_VARARGS, tr(scribus_getcellfillcolor__doc__)},
+ {const_cast<char*>("getCellText"), scribus_getcelltext, METH_VARARGS, tr(scribus_getcelltext__doc__)},
{const_cast<char*>("getCharacterStyle"), scribus_getcharacterstyle, METH_VARARGS, tr(scribus_getcharacterstyle__doc__) },
{const_cast<char*>("getCharStyles"), (PyCFunction)scribus_getcharstylenames, METH_NOARGS, tr(scribus_getcharstylenames__doc__)},
{const_cast<char*>("getColorNames"), (PyCFunction)scribus_colornames, METH_NOARGS, tr(scribus_colornames__doc__)},
Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24043&path=/trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.cpp Mon Sep 28 22:48:43 2020
@@ -12,6 +12,48 @@
#include "pageitem_table.h"
#include "tableborder.h"
+PyObject *scribus_getcelltext(PyObject* /* self */, PyObject* args)
+{
+ char *Name = const_cast<char*>("");
+ int row, column;
+ if (!PyArg_ParseTuple(args, "ii|es", &row, &column, "utf-8", &Name))
+ return nullptr;
+ if (!checkHaveDocument())
+ return nullptr;
+ PageItem *i = GetUniqueItem(QString::fromUtf8(Name));
+ if (i == nullptr)
+ return nullptr;
+ PageItem_Table *table = i->asTable();
+ if (!table)
+ {
+ PyErr_SetString(WrongFrameTypeError, QObject::tr("Cannot get cell text on a non-table item.","python error").toLocal8Bit().constData());
+ return nullptr;
+ }
+ if (column < 0 || column >= table->columns() || row < 0 || row >= table->rows())
+ {
+ PyErr_SetString(PyExc_ValueError, QObject::tr("The cell %1,%2 does not exist in table", "python error").arg(row).arg(column).toLocal8Bit().constData());
+ return nullptr;
+ }
+
+ PageItem* textFrame = table->cellAt(row, column).textFrame();
+ const StoryText& story = textFrame->itemText;
+ QString text;
+ text.reserve(story.hasSelection() ? story.selectionLength() : story.length());
+ for (int i = 0; i < story.length(); i++)
+ {
+ if (textFrame->HasSel)
+ {
+ if (story.selected(i))
+ text += story.text(i);
+ }
+ else
+ {
+ text += story.text(i);
+ }
+ }
+ return PyString_FromString(text.toUtf8());
+}
+
PyObject *scribus_setcelltext(PyObject* /* self */, PyObject* args)
{
char *Name = const_cast<char*>("");
@@ -461,6 +503,7 @@
<< scribus_getcellfillcolor__doc__
<< scribus_getcellrowspan__doc__
<< scribus_getcellstyle__doc__
+ << scribus_getcelltext__doc__
<< scribus_setcellbottomborder__doc__
<< scribus_setcellbottompadding__doc__
<< scribus_setcellfillcolor__doc__
Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24043&path=/trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin_py2x/cmdcell.h Mon Sep 28 22:48:43 2020
@@ -16,6 +16,19 @@
#define CMDCELL_H
/*! docstring */
+PyDoc_STRVAR(scribus_getcelltext__doc__,
+QT_TR_NOOP("getCellText(row, column, [\"name\"]) -> string\n\
+\n\
+Returns the text content of the cell at \"row\", \"column\" in the table \"name\".\n\
+If cell has some text selected, the selected text is returned.\n\
+If \"name\" is not given the currently selected item is used.\n\
+\n\
+May throw ValueError if the cell does not exist.\n\
+"));
+/*! Get cell text */
+PyObject *scribus_getcelltext(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
PyDoc_STRVAR(scribus_setcelltext__doc__,
QT_TR_NOOP("setCellText(row, column, text, [\"name\"])\n\
\n\
Modified: trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=24043&path=/trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin_py2x/scriptplugin.cpp Mon Sep 28 22:48:43 2020
@@ -334,11 +334,12 @@
{const_cast<char*>("getAllObjects"), (PyCFunction)scribus_getallobj, METH_VARARGS|METH_KEYWORDS, tr(scribus_getallobj__doc__)},
{const_cast<char*>("getAllStyles"), (PyCFunction)scribus_getparagraphstyles, METH_NOARGS, tr(scribus_getallstyles__doc__)}, //Deprecated
{const_cast<char*>("getAllText"), scribus_getalltext, METH_VARARGS, tr(scribus_getalltext__doc__)},
+ {const_cast<char*>("getCellColumnSpan"), scribus_getcellcolumnspan, METH_VARARGS, tr(scribus_getcellcolumnspan__doc__)},
+ {const_cast<char*>("getCellFillColor"), scribus_getcellfillcolor, METH_VARARGS, tr(scribus_getcellfillcolor__doc__)},
+ {const_cast<char*>("getCellRowSpan"), scribus_getcellrowspan, METH_VARARGS, tr(scribus_getcellrowspan__doc__)},
{const_cast<char*>("getCellStyle"), scribus_getcellstyle, METH_VARARGS, tr(scribus_getcellstyle__doc__)},
{const_cast<char*>("getCellStyles"), (PyCFunction)scribus_getcellstyles, METH_VARARGS, tr(scribus_getcellstyles__doc__)},
- {const_cast<char*>("getCellColumnSpan"), scribus_getcellcolumnspan, METH_VARARGS, tr(scribus_getcellcolumnspan__doc__)},
- {const_cast<char*>("getCellRowSpan"), scribus_getcellrowspan, METH_VARARGS, tr(scribus_getcellrowspan__doc__)},
- {const_cast<char*>("getCellFillColor"), scribus_getcellfillcolor, METH_VARARGS, tr(scribus_getcellfillcolor__doc__)},
+ {const_cast<char*>("getCellText"), scribus_getcelltext, METH_VARARGS, tr(scribus_getcelltext__doc__)},
{const_cast<char*>("getCharacterStyle"), scribus_getcharacterstyle, METH_VARARGS, tr(scribus_getcharacterstyle__doc__) },
{const_cast<char*>("getCharStyles"), (PyCFunction)scribus_getcharstylenames, METH_NOARGS, tr(scribus_getcharstylenames__doc__)},
{const_cast<char*>("getColorNames"), (PyCFunction)scribus_colornames, METH_NOARGS, tr(scribus_colornames__doc__)},
More information about the scribus-commit
mailing list