summaryrefslogtreecommitdiffstats
path: root/src/extension/script/InkscapePython.cpp
diff options
context:
space:
mode:
authorMenTaLguY <mental@rydia.net>2006-01-16 02:36:01 +0000
committermental <mental@users.sourceforge.net>2006-01-16 02:36:01 +0000
commit179fa413b047bede6e32109e2ce82437c5fb8d34 (patch)
treea5a6ac2c1708bd02288fbd8edb2ff500ff2e0916 /src/extension/script/InkscapePython.cpp
downloadinkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.tar.gz
inkscape-179fa413b047bede6e32109e2ce82437c5fb8d34.zip
moving trunk for module inkscape
(bzr r1)
Diffstat (limited to 'src/extension/script/InkscapePython.cpp')
-rw-r--r--src/extension/script/InkscapePython.cpp120
1 files changed, 120 insertions, 0 deletions
diff --git a/src/extension/script/InkscapePython.cpp b/src/extension/script/InkscapePython.cpp
new file mode 100644
index 000000000..eca09951a
--- /dev/null
+++ b/src/extension/script/InkscapePython.cpp
@@ -0,0 +1,120 @@
+/**
+ * Python Interpreter wrapper for Inkscape
+ *
+ * Authors:
+ * Bob Jamison <rjamison@titan.com>
+ *
+ * Copyright (C) 2004 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+
+#include <Python.h>
+
+#include "InkscapePython.h"
+
+
+#include <stdio.h>
+
+#include "inkscape_py.py.h"
+
+
+/*
+ * Generated by SWIG
+ */
+extern "C" void init_inkscape_py(void);
+
+
+namespace Inkscape {
+namespace Extension {
+namespace Script {
+
+/*
+ *
+ */
+InkscapePython::InkscapePython()
+{
+}
+
+
+
+/*
+ *
+ */
+InkscapePython::~InkscapePython()
+{
+
+}
+
+
+
+static bool initialized = false;
+/*
+ * Interpret an in-memory string
+ */
+bool InkscapePython::interpretScript(Glib::ustring &script,
+ Glib::ustring &output,
+ Glib::ustring &error)
+{
+ if (!initialized)
+ {
+ Py_Initialize();
+ init_inkscape_py();
+ initialized = true;
+ }
+ char *codeStr = (char *)script.raw().c_str();
+ PyRun_SimpleString(inkscape_module_script);
+ PyRun_SimpleString("inkscape = _inkscape_py.getInkscape()\n");
+ PyRun_SimpleString(codeStr);
+
+ //## Check for errors
+ if (PyErr_Occurred())
+ {
+ PyObject *errobj = NULL;
+ PyObject *errdata = NULL;
+ PyObject *errtraceback = NULL;
+
+ PyErr_Fetch(&errobj, &errdata, &errtraceback);
+ //PyErr_Clear();
+
+ if (errobj && PyString_Check(errobj))
+ {
+ PyObject *pystring = PyObject_Str(errobj);
+ char *errStr = PyString_AsString(pystring);
+ error = errStr;
+ Py_XDECREF(pystring);
+ }
+ else
+ {
+ error = "Error occurred";
+ }
+ Py_XDECREF(errobj);
+ Py_XDECREF(errdata);
+ Py_XDECREF(errtraceback);
+ return false;
+ }
+ //Py_Finalize();
+ return true;
+}
+
+
+
+
+
+
+
+} // namespace Script
+} // namespace Extension
+} // namespace Inkscape
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :