View Issue Details
| ID | Project | Category | View Status | Date Submitted | Last Update |
|---|---|---|---|---|---|
| 0011104 | Scribus | Plug-ins | public | 2012-09-29 21:11 | 2012-11-13 20:30 |
| Reporter | jzeleny | Assigned To | jghali | ||
| Priority | normal | Severity | minor | Reproducibility | always |
| Status | closed | Resolution | fixed | ||
| Product Version | 1.4.2.svn | ||||
| Fixed in Version | 1.5.0svn | ||||
| Summary | 0011104: [PATCH] Support HTML import in Python scripts | ||||
| Description | Currently there is no way to import HTML file from import script. Attached patch adds this functionality by adding Python function insertHtmlText. | ||||
| Steps To Reproduce | Write a scribus Python script that will invoke following command: scribus.insertHtmlText(f , name) where f is a path to HTML file and name is a name of text frame where the HTML text should be imported. | ||||
| Tags | No tags attached. | ||||
| Attached Files | 0001-Added-the-base-function-for-importing-HTML-files-fro.patch (3,966 bytes)
From 8139c0ead3410cdc6b5057befb30a0636acfbbdd Mon Sep 17 00:00:00 2001
From: Jan Zeleny <jz@janzeleny.cz>
Date: Sat, 3 Mar 2012 14:06:39 +0100
Subject: [PATCH 1/5] Added the base function for importing HTML files from Python scripts
---
scribus/plugins/scriptplugin/cmdtext.cpp | 34 +++++++++++++++++++++++++
scribus/plugins/scriptplugin/cmdtext.h | 11 ++++++++
scribus/plugins/scriptplugin/scriptplugin.cpp | 1 +
3 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/scribus/plugins/scriptplugin/cmdtext.cpp b/scribus/plugins/scriptplugin/cmdtext.cpp
index 8249fb10ff535f096bdd80fe9873f6a2210c88e9..0b7934c263a5dbbad5b5d07dfe1c8b23f5603e31 100644
--- a/scribus/plugins/scriptplugin/cmdtext.cpp
+++ b/scribus/plugins/scriptplugin/cmdtext.cpp
@@ -315,6 +315,40 @@ PyObject *scribus_inserttext(PyObject* /* self */, PyObject* args)
Py_RETURN_NONE;
}
+PyObject *scribus_inserthtmltext(PyObject* /* self */, PyObject* args)
+{
+ char *name;
+ char *file;
+ QString data;
+ gtGetText *gt;
+
+ if (!PyArg_ParseTuple(args, "eses", "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;
+ }
+
+ gt = new gtGetText(ScCore->primaryMainWindow()->doc);
+ gt->launchImporter(-1, QString(file), false, QString("utf-8"), false, it);
+
+ // FIXME: PyMem_Free() - are any needed??
+ Py_RETURN_NONE;
+}
+
PyObject *scribus_setalign(PyObject* /* self */, PyObject* args)
{
char *Name = const_cast<char*>("");
diff --git a/scribus/plugins/scriptplugin/cmdtext.h b/scribus/plugins/scriptplugin/cmdtext.h
index ffff82d65194be84fd4c190251289136083020da..3232551cdb1052933d509b92c5488b86c9c5412a 100644
--- a/scribus/plugins/scriptplugin/cmdtext.h
+++ b/scribus/plugins/scriptplugin/cmdtext.h
@@ -148,6 +148,17 @@ May throw IndexError for an insertion out of bounds.\n\
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\
diff --git a/scribus/plugins/scriptplugin/scriptplugin.cpp b/scribus/plugins/scriptplugin/scriptplugin.cpp
index 3f043b00043efe75363cb08c0a8fd7cd1e3c8495..464f65f049f2fa8c8d1a57e54504bd34f73c18fe 100644
--- a/scribus/plugins/scriptplugin/scriptplugin.cpp
+++ b/scribus/plugins/scriptplugin/scriptplugin.cpp
@@ -374,6 +374,7 @@ PyMethodDef scribus_methods[] = {
{const_cast<char*>("placeSXD"), scribus_placesxd, METH_VARARGS, tr(scribus_placesxd__doc__)},
{const_cast<char*>("placeODG"), scribus_placeodg, METH_VARARGS, tr(scribus_placeodg__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__)},
--
1.7.4.1
| ||||
| Patch | |||||
|
|
I committed your patch to trunk. Thanks! I had to fix several issues tho : - unnecessary manual memory management (+ forgotten object deletion) - incorrect specification of optional arguments in PyArg_ParseTuple format string - incorrect conversion of filename string to QString At last when adding a function to scripter, do not forget also to add its documentation to scripter documentation, Scribus/doc/en/scripterapi-textframes.html in this case. |
| Date Modified | Username | Field | Change |
|---|---|---|---|
| 2012-09-29 21:11 | jzeleny | New Issue | |
| 2012-09-29 21:11 | jzeleny | File Added: 0001-Added-the-base-function-for-importing-HTML-files-fro.patch | |
| 2012-10-09 22:09 | jghali | Note Added: 0029033 | |
| 2012-10-09 22:09 | jghali | Status | new => resolved |
| 2012-10-09 22:09 | jghali | Fixed in Version | => 1.5.0svn |
| 2012-10-09 22:09 | jghali | Resolution | open => fixed |
| 2012-10-09 22:09 | jghali | Assigned To | => jghali |
| 2012-10-09 22:09 | jghali | Note Edited: 0029033 | |
| 2012-11-13 20:30 | cbradney | Status | resolved => closed |