r17795 by jghali - #11104 : support HTML import in Python scripts

scribus-commit scribus-commit at lists.scribus.net
Tue Oct 9 22:02:19 UTC 2012


Author: jghali
Date: Tue Oct  9 22:02:19 2012
New Revision: 17795

URL: http://scribus.net/websvn/listing.php?repname=Scribus&sc=1&rev=17795
Log:
#11104 : support HTML import in Python scripts

Modified:
    trunk/Scribus/doc/en/scripterapi-textframes.html
    trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
    trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h
    trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp

Modified: trunk/Scribus/doc/en/scripterapi-textframes.html
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17795&path=/trunk/Scribus/doc/en/scripterapi-textframes.html
==============================================================================
--- trunk/Scribus/doc/en/scripterapi-textframes.html (original)
+++ trunk/Scribus/doc/en/scripterapi-textframes.html Tue Oct  9 22:02:19 2012
@@ -70,6 +70,11 @@
 <dt><a name="-hyphenateText"><strong>hyphenateText</strong></a>(...)</dt>
 <dd><code>hyphenateText(["name"]) -> bool</code>
 <p>Does hyphenation on text frame "name". If "name" is not given the currently selected item is used.</p>
+<p>May raise WrongFrameTypeError if the target frame is not a text frame</p></dd>
+
+<dt><a name="-insertHtmlText"><strong>insertHtmlText</strong></a>(...)</dt>
+<dd><code>insertHtmlText("text", ["name"])</code>
+<p>Inserts the text from "file" into the text frame "name". Text must be UTF encoded (see <a href="#-setText">setText</a>() as reference). If "name" is not given the currently selected Item is used.</p>
 <p>May raise WrongFrameTypeError if the target frame is not a text frame</p></dd>
 
 <dt><a name="-insertText"><strong>insertText</strong></a>(...)</dt>

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17795&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.cpp Tue Oct  9 22:02:19 2012
@@ -309,6 +309,41 @@
 //	Py_INCREF(Py_None);
 //	return Py_None;
 	Py_RETURN_NONE;
+}
+
+PyObject *scribus_inserthtmltext(PyObject* /* self */, PyObject* args)
+{
+    char *name = const_cast<char*>("");
+    char *file;
+    QString data;
+
+    if (!PyArg_ParseTuple(args, "es|es", "utf-8", &file, "utf-8", &name)) {
+        return NULL;
+    }
+
+    if(!checkHaveDocument()) {
+        return NULL;
+    }
+
+    PageItem *it = GetUniqueItem(QString::fromUtf8(name));
+    if (it == NULL) {
+        return NULL;
+    }
+
+    if (!(it->asTextFrame()) && !(it->asPathText())) {
+        PyErr_SetString(WrongFrameTypeError,
+                QObject::tr("Cannot insert text into non-text frame.",
+                    "python error").toLocal8Bit().constData());
+        return NULL;
+    }
+
+	QString fileName = QString::fromUtf8(file);
+
+    gtGetText gt(ScCore->primaryMainWindow()->doc);
+    gt.launchImporter(-1, fileName, false, QString("utf-8"), false, it);
+
+    // FIXME: PyMem_Free() - are any needed??
+    Py_RETURN_NONE;
 }
 
 PyObject *scribus_setalign(PyObject* /* self */, PyObject* args)

Modified: trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17795&path=/trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/cmdtext.h Tue Oct  9 22:02:19 2012
@@ -148,6 +148,17 @@
 PyObject *scribus_inserttext(PyObject * /*self*/, PyObject* args);
 
 /*! docstring */
+PyDoc_STRVAR(scribus_inserthtmltext__doc__,
+QT_TR_NOOP("insertHTMLText(\"file\", [\"name\"])\n\
+\n\
+Inserts the text from \"file\" into the text frame \"name\".\n\
+Text must be UTF encoded (see setText() as reference). If \"name\" is\n\
+not given the currently selected Item is used.\n\
+"));
+/*! Insert HTML text */
+PyObject *scribus_inserthtmltext(PyObject * /*self*/, PyObject* args);
+
+/*! docstring */
 PyDoc_STRVAR(scribus_setfont__doc__,
 QT_TR_NOOP("setFont(\"font\", [\"name\"])\n\
 \n\

Modified: trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
URL: http://scribus.net/websvn/diff.php?repname=Scribus&rev=17795&path=/trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp
==============================================================================
--- trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp (original)
+++ trunk/Scribus/scribus/plugins/scriptplugin/scriptplugin.cpp Tue Oct  9 22:02:19 2012
@@ -412,6 +412,7 @@
 	{const_cast<char*>("insertTableRows"), scribus_inserttablerows, METH_VARARGS, tr(scribus_inserttablerows__doc__)},
 	{const_cast<char*>("insertTableColumns"), scribus_inserttablecolumns, METH_VARARGS, tr(scribus_inserttablecolumns__doc__)},
 	{const_cast<char*>("insertText"), scribus_inserttext, METH_VARARGS, tr(scribus_inserttext__doc__)},
+	{const_cast<char*>("insertHtmlText"), scribus_inserthtmltext, METH_VARARGS, tr(scribus_inserthtmltext__doc__)},
 	{const_cast<char*>("isLayerPrintable"), scribus_glayerprint, METH_VARARGS, tr(scribus_glayerprint__doc__)},
 	{const_cast<char*>("isLayerVisible"), scribus_glayervisib, METH_VARARGS, tr(scribus_glayervisib__doc__)},
 	{const_cast<char*>("isLayerLocked"), scribus_glayerlock, METH_VARARGS, tr(scribus_glayerlock__doc__)},




More information about the scribus-commit mailing list