+ simplify porting of MeshPart module to Python3

This commit is contained in:
wmayer
2016-01-20 22:38:45 +01:00
parent 4481208899
commit afcdd66734
5 changed files with 170 additions and 164 deletions

View File

@@ -26,6 +26,9 @@
# include <Python.h>
#endif
#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
#include <Base/Console.h>
#include <Gui/Application.h>
#include <Gui/Language/Translator.h>
@@ -41,20 +44,37 @@ void loadMeshPartResource()
Gui::Translator::instance()->refresh();
}
/* registration table */
extern struct PyMethodDef MeshPartGui_Import_methods[];
namespace MeshPartGui {
class Module : public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("MeshPartGui")
{
initialize("This module is the MeshPartGui module."); // register with Python
}
virtual ~Module() {}
private:
};
PyObject* initModule()
{
return (new Module)->module().ptr();
}
} // namespace MeshPartGui
/* Python entry */
extern "C" {
void MeshPartGuiExport initMeshPartGui()
PyMODINIT_FUNC initMeshPartGui()
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
}
(void) Py_InitModule("MeshPartGui", MeshPartGui_Import_methods); /* mod name, table ptr */
(void)MeshPartGui::initModule();
Base::Console().Log("Loading GUI of MeshPart module... done\n");
// instantiating the commands
@@ -64,5 +84,3 @@ void MeshPartGuiExport initMeshPartGui()
// add resources and reloads the translators
loadMeshPartResource();
}
} // extern "C" {

View File

@@ -1,32 +0,0 @@
/***************************************************************************
* Copyright (c) 2008 Werner Mayer <wmayer[at]users.sourceforge.net> *
* *
* 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 <Python.h>
#endif
/* registration table */
struct PyMethodDef MeshPartGui_Import_methods[] = {
{NULL, NULL} /* end of table marker */
};

View File

@@ -48,7 +48,6 @@ SET(MeshPartGui_SRCS
${MeshPartGui_QRC_SRCS}
${MeshPartGui_UIC_HDRS}
AppMeshPartGui.cpp
AppMeshPartGuiPy.cpp
Command.cpp
Resources/MeshPart.qrc
PreCompiled.cpp