From b1ea3f70dad8a1e41df20b871d6f5a6e89f1bf45 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sat, 24 Oct 2015 18:16:17 +0200 Subject: [PATCH] + move module Python stuff into C++ class --- src/Tools/_TEMPLATE_/App/App_TEMPLATE_.cpp | 22 ++++++++--- src/Tools/_TEMPLATE_/App/App_TEMPLATE_Py.cpp | 38 ------------------- src/Tools/_TEMPLATE_/App/CMakeLists.txt | 1 - src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_Gui.cpp | 23 ++++++++--- .../_TEMPLATE_/Gui/App_TEMPLATE_GuiPy.cpp | 35 ----------------- src/Tools/_TEMPLATE_/Gui/CMakeLists.txt | 1 - 6 files changed, 34 insertions(+), 86 deletions(-) delete mode 100644 src/Tools/_TEMPLATE_/App/App_TEMPLATE_Py.cpp delete mode 100644 src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_GuiPy.cpp diff --git a/src/Tools/_TEMPLATE_/App/App_TEMPLATE_.cpp b/src/Tools/_TEMPLATE_/App/App_TEMPLATE_.cpp index 2425c76f3..f6721bb0d 100644 --- a/src/Tools/_TEMPLATE_/App/App_TEMPLATE_.cpp +++ b/src/Tools/_TEMPLATE_/App/App_TEMPLATE_.cpp @@ -28,12 +28,24 @@ #include +#include +#include -/* registration table */ -extern struct PyMethodDef _TEMPLATE__methods[]; -PyDoc_STRVAR(module__TEMPLATE__doc, -"This module is the _TEMPLATE_ module."); +namespace _TEMPLATE_ { +class Module : public Py::ExtensionModule +{ +public: + Module() : Py::ExtensionModule("_TEMPLATE_") + { + initialize("This module is the _TEMPLATE_ module."); // register with Python + } + + virtual ~Module() {} + +private: +}; +} // namespace _TEMPLATE_ /* Python entry */ @@ -43,7 +55,7 @@ void _TEMPLATE_AppExport init_TEMPLATE_() { // ADD YOUR CODE HERE // // - (void) Py_InitModule3("_TEMPLATE_", _TEMPLATE__methods, module__TEMPLATE__doc); /* mod name, table ptr */ + new _TEMPLATE_::Module(); Base::Console().Log("Loading _TEMPLATE_ module... done\n"); } diff --git a/src/Tools/_TEMPLATE_/App/App_TEMPLATE_Py.cpp b/src/Tools/_TEMPLATE_/App/App_TEMPLATE_Py.cpp deleted file mode 100644 index df13eca60..000000000 --- a/src/Tools/_TEMPLATE_/App/App_TEMPLATE_Py.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/*************************************************************************** - * Copyright (c) YEAR YOUR NAME * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -#endif - -#include - -#include -#include -#include - - -/* registration table */ -struct PyMethodDef _TEMPLATE__methods[] = { - {NULL, NULL} /* end of table marker */ -}; diff --git a/src/Tools/_TEMPLATE_/App/CMakeLists.txt b/src/Tools/_TEMPLATE_/App/CMakeLists.txt index 6605c0670..5dea7beb9 100644 --- a/src/Tools/_TEMPLATE_/App/CMakeLists.txt +++ b/src/Tools/_TEMPLATE_/App/CMakeLists.txt @@ -13,7 +13,6 @@ set(_TEMPLATE__LIBS SET(_TEMPLATE__SRCS App_TEMPLATE_.cpp - App_TEMPLATE_Py.cpp PreCompiled.cpp PreCompiled.h ) diff --git a/src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_Gui.cpp b/src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_Gui.cpp index 963ca2148..394b3f2a9 100644 --- a/src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_Gui.cpp +++ b/src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_Gui.cpp @@ -31,15 +31,27 @@ #include "Workbench.h" +#include +#include + // use a different name to CreateCommand() void Create_TEMPLATE_Commands(void); -/* registration table */ -extern struct PyMethodDef _TEMPLATE_Gui_methods[]; +namespace _TEMPLATE_Gui { +class Module : public Py::ExtensionModule +{ +public: + Module() : Py::ExtensionModule("_TEMPLATE_Gui") + { + initialize("This module is the _TEMPLATE_Gui module."); // register with Python + } -PyDoc_STRVAR(module__TEMPLATE_Gui_doc, -"This module is the _TEMPLATE_Gui module."); + virtual ~Module() {} + +private: +}; +} // namespace _TEMPLATE_Gui /* Python entry */ @@ -58,8 +70,7 @@ void _TEMPLATE_GuiExport init_TEMPLATE_Gui() // ADD YOUR CODE HERE // // - - (void) Py_InitModule3("_TEMPLATE_Gui", _TEMPLATE_Gui_methods, module__TEMPLATE_Gui_doc); /* mod name, table ptr */ + new _TEMPLATE_Gui::Module(); Base::Console().Log("Loading GUI of _TEMPLATE_ module... done\n"); } diff --git a/src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_GuiPy.cpp b/src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_GuiPy.cpp deleted file mode 100644 index 7ef76d7c6..000000000 --- a/src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_GuiPy.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/*************************************************************************** - * Copyright (c) YEAR YOUR NAME * - * * - * This file is part of the FreeCAD CAx development system. * - * * - * This library is free software; you can redistribute it and/or * - * modify it under the terms of the GNU Library General Public * - * License as published by the Free Software Foundation; either * - * version 2 of the License, or (at your option) any later version. * - * * - * This library is distributed in the hope that it will be useful, * - * but WITHOUT ANY WARRANTY; without even the implied warranty of * - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * - * GNU Library General Public License for more details. * - * * - * You should have received a copy of the GNU Library General Public * - * License along with this library; see the file COPYING.LIB. If not, * - * write to the Free Software Foundation, Inc., 59 Temple Place, * - * Suite 330, Boston, MA 02111-1307, USA * - * * - ***************************************************************************/ - - -#include "PreCompiled.h" -#ifndef _PreComp_ -#endif - - -#include -#include - -/* registration table */ -struct PyMethodDef _TEMPLATE_Gui_methods[] = { - {NULL, NULL} /* end of table marker */ -}; diff --git a/src/Tools/_TEMPLATE_/Gui/CMakeLists.txt b/src/Tools/_TEMPLATE_/Gui/CMakeLists.txt index 67e98baee..5154e7e5e 100644 --- a/src/Tools/_TEMPLATE_/Gui/CMakeLists.txt +++ b/src/Tools/_TEMPLATE_/Gui/CMakeLists.txt @@ -20,7 +20,6 @@ qt4_add_resources(_TEMPLATE__QRC_SRCS Resources/_TEMPLATE_.qrc) SET(_TEMPLATE_Gui_SRCS ${_TEMPLATE__QRC_SRCS} App_TEMPLATE_Gui.cpp - App_TEMPLATE_GuiPy.cpp Command.cpp PreCompiled.cpp PreCompiled.h