From b8e436d8fb9ec7996d50202ca3c51a3940fbc01e Mon Sep 17 00:00:00 2001 From: Bob Jamison Date: Sat, 14 Apr 2007 15:52:31 +0000 Subject: Change python binding mechanism (bzr r2885) --- src/extension/script/InkscapePython.cpp | 150 +++++++++++++++++++++++++------- 1 file changed, 120 insertions(+), 30 deletions(-) (limited to 'src/extension/script/InkscapePython.cpp') diff --git a/src/extension/script/InkscapePython.cpp b/src/extension/script/InkscapePython.cpp index 49e6a11a2..f7cfe81db 100644 --- a/src/extension/script/InkscapePython.cpp +++ b/src/extension/script/InkscapePython.cpp @@ -4,7 +4,7 @@ * Authors: * Bob Jamison * - * Copyright (C) 2004 Authors + * Copyright (C) 2004-2007 Authors * * Released under GNU GPL, read the file 'COPYING' for more information */ @@ -16,57 +16,147 @@ #include +#include +#include -#include "inkscape_py.py.h" +#include -/* - * Generated by SWIG - */ -extern "C" void init_inkscape_py(void); +namespace Inkscape +{ +namespace Extension +{ +namespace Script +{ -namespace Inkscape { -namespace Extension { -namespace Script { +//######################################################################## +//# I N K S C A P E +//######################################################################## -/* - * - */ -InkscapePython::InkscapePython() +class PyDialogManager : public Py::PythonExtension { -} +public: -/* - * - */ -InkscapePython::~InkscapePython() +private: + +}; + + + +class PyDesktop : public Py::PythonExtension +{ +public: + + + +private: + +}; + + + +class PyDocument : public Py::PythonExtension +{ +public: + + + +private: + +}; + + + +class PyInkscape : public Py::PythonExtension +{ +public: + + PyInkscape() + { + inkscape = INKSCAPE; + } + + virtual ~PyInkscape() + { + } + + + virtual Py::Object getattr(const char *name) + { + if (strcmp(name, "activeDesktop")==0) + { + } + else if (strcmp(name, "activeDocument")==0) + { + } + else if (strcmp(name, "dialogManager")==0) + { + } + return getattr_methods(name); + } + + virtual Py::Object exit(const Py::Tuple &args) + { + //exit(); + } + + static void init_type() + { + behaviors().name("inkscape"); + behaviors().doc("inkscape objects: activeDesktop activeDocument dialogManager"); + behaviors().supportRepr(); + behaviors().supportGetattr(); + + add_varargs_method("exit", &PyInkscape::exit, + "exit from the current application"); + } + +private: + + Inkscape::Application *inkscape; + +}; + + + + +//######################################################################## +//# M A I N +//######################################################################## + + +bool InkscapePython::initialize() { + if (initialized) + return true; + + Py_Initialize(); + + + + initialized = true; + return true; } -static bool initialized = false; /* * Interpret an in-memory string */ bool InkscapePython::interpretScript(const Glib::ustring &script, - Glib::ustring &output, - Glib::ustring &error) + Glib::ustring &output, Glib::ustring &error) { - if (!initialized) - { - Py_Initialize(); - init_inkscape_py(); - initialized = true; - } + if (!initialize()) + return false; + char *codeStr = (char *)script.raw().c_str(); - PyRun_SimpleString(inkscape_module_script); - PyRun_SimpleString("inkscape = _inkscape_py.getInkscape()\n"); - PyRun_SimpleString(codeStr); + //PyRun_SimpleString(inkscape_module_script); + //PyRun_SimpleString("inkscape = _inkscape_py.getInkscape()\n"); + //PyRun_SimpleString(codeStr); //## Check for errors if (PyErr_Occurred()) -- cgit v1.2.3