From d78d74776071938b8f063beb0af99bfd31937567 Mon Sep 17 00:00:00 2001 From: wmayer Date: Sun, 17 Jan 2016 22:13:32 +0100 Subject: [PATCH] + simplify porting of Start module to Python3 --- src/Mod/Start/App/AppStart.cpp | 24 ++++++++++++++------- src/Mod/Start/App/AppStartPy.cpp | 33 ----------------------------- src/Mod/Start/App/CMakeLists.txt | 1 - src/Mod/Start/Gui/AppStartGui.cpp | 26 +++++++++++++++++------ src/Mod/Start/Gui/AppStartGuiPy.cpp | 33 ----------------------------- src/Mod/Start/Gui/CMakeLists.txt | 1 - 6 files changed, 35 insertions(+), 83 deletions(-) delete mode 100644 src/Mod/Start/App/AppStartPy.cpp delete mode 100644 src/Mod/Start/Gui/AppStartGuiPy.cpp diff --git a/src/Mod/Start/App/AppStart.cpp b/src/Mod/Start/App/AppStart.cpp index f882fce6c230..2837c415246d 100644 --- a/src/Mod/Start/App/AppStart.cpp +++ b/src/Mod/Start/App/AppStart.cpp @@ -28,21 +28,29 @@ #include #include +#include +#include #include "StartConfiguration.h" -extern struct PyMethodDef Start_methods[]; +namespace Start { +class Module : public Py::ExtensionModule +{ +public: + Module() : Py::ExtensionModule("Start") + { + initialize("This module is the Start module."); // register with Python + } -PyDoc_STRVAR(module_Start_doc, -"This module is the Start module."); + virtual ~Module() {} +private: +}; +} // namespace Start /* Python entry */ -extern "C" { -void AppStartExport initStart() +PyMODINIT_FUNC initStart() { - Py_InitModule3("Start", Start_methods, module_Start_doc); /* mod name, table ptr */ + new Start::Module(); Base::Console().Log("Loading Start module... done\n"); } - -} // extern "C" diff --git a/src/Mod/Start/App/AppStartPy.cpp b/src/Mod/Start/App/AppStartPy.cpp deleted file mode 100644 index ebc9b8c426c5..000000000000 --- a/src/Mod/Start/App/AppStartPy.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2010 Jürgen Riegel (juergen.riegel@web.de) * - * * - * 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_ -# include -#endif - - -/* registration table */ -struct PyMethodDef Start_methods[] = { - {NULL, NULL} /* end of table marker */ -}; diff --git a/src/Mod/Start/App/CMakeLists.txt b/src/Mod/Start/App/CMakeLists.txt index d5358d6f93b9..a12d323b8409 100644 --- a/src/Mod/Start/App/CMakeLists.txt +++ b/src/Mod/Start/App/CMakeLists.txt @@ -12,7 +12,6 @@ set(Start_LIBS SET(Start_SRCS AppStart.cpp - AppStartPy.cpp PreCompiled.cpp PreCompiled.h StartConfiguration.h diff --git a/src/Mod/Start/Gui/AppStartGui.cpp b/src/Mod/Start/Gui/AppStartGui.cpp index 8cf2b7251683..898806f95c8c 100644 --- a/src/Mod/Start/Gui/AppStartGui.cpp +++ b/src/Mod/Start/Gui/AppStartGui.cpp @@ -26,6 +26,9 @@ # include #endif +#include +#include + #include #include #include @@ -46,13 +49,24 @@ void loadStartResource() Gui::Translator::instance()->refresh(); } -/* registration table */ -extern struct PyMethodDef StartGui_Import_methods[]; +namespace StartGui { +class Module : public Py::ExtensionModule +{ +public: + Module() : Py::ExtensionModule("StartGui") + { + initialize("This module is the StartGui module."); // register with Python + } + + virtual ~Module() {} + +private: +}; +} // namespace StartGui /* Python entry */ -extern "C" { -void StartGuiExport initStartGui() +PyMODINIT_FUNC initStartGui() { if (!Gui::Application::Instance) { PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application."); @@ -81,7 +95,7 @@ void StartGuiExport initStartGui() PyErr_Print(); } - (void) Py_InitModule("StartGui", StartGui_Import_methods); /* mod name, table ptr */ + new StartGui::Module(); Base::Console().Log("Loading GUI of Start module... done\n"); // instantiating the commands @@ -91,5 +105,3 @@ void StartGuiExport initStartGui() // add resources and reloads the translators loadStartResource(); } - -} // extern "C" { diff --git a/src/Mod/Start/Gui/AppStartGuiPy.cpp b/src/Mod/Start/Gui/AppStartGuiPy.cpp deleted file mode 100644 index d928b8dfe342..000000000000 --- a/src/Mod/Start/Gui/AppStartGuiPy.cpp +++ /dev/null @@ -1,33 +0,0 @@ -/*************************************************************************** - * Copyright (c) 2008 Werner Mayer * - * * - * 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_ -# include -#endif - - -/* registration table */ -struct PyMethodDef StartGui_Import_methods[] = { - {NULL, NULL} /* end of table marker */ -}; diff --git a/src/Mod/Start/Gui/CMakeLists.txt b/src/Mod/Start/Gui/CMakeLists.txt index 089d2f45e746..99bfa6e1dea3 100644 --- a/src/Mod/Start/Gui/CMakeLists.txt +++ b/src/Mod/Start/Gui/CMakeLists.txt @@ -18,7 +18,6 @@ qt4_add_resources(Start_QRC_SRCS Resources/Start.qrc) SET(StartGui_SRCS ${Start_QRC_SRCS} AppStartGui.cpp - AppStartGuiPy.cpp Command.cpp PreCompiled.cpp PreCompiled.h