blob: 49e6a11a288789a8d35c499819b5ed5136b85348 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
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(const 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 :
|