+ use PyCXX for module initialization
This commit is contained in:
@@ -38,17 +38,31 @@
|
||||
#include <Base/Parameter.h>
|
||||
|
||||
|
||||
/* registration table */
|
||||
extern struct PyMethodDef Surface_methods[];
|
||||
namespace Surface {
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
{
|
||||
public:
|
||||
Module() : Py::ExtensionModule<Module>("Surface")
|
||||
{
|
||||
initialize("This module is the Surface module."); // register with Python
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(module_Surface_doc,
|
||||
"This module is the Surface module.");
|
||||
virtual ~Module() {}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
PyObject* initModule()
|
||||
{
|
||||
return (new Module)->module().ptr();
|
||||
}
|
||||
|
||||
} // namespace Surface
|
||||
|
||||
|
||||
/* Python entry */
|
||||
extern "C" {
|
||||
void SurfaceExport initSurface() {
|
||||
|
||||
PyMODINIT_FUNC initSurface()
|
||||
{
|
||||
try {
|
||||
Base::Interpreter().runString("import Part");
|
||||
}
|
||||
@@ -60,7 +74,7 @@ void SurfaceExport initSurface() {
|
||||
// ADD YOUR CODE HERE
|
||||
//
|
||||
//
|
||||
(void) Py_InitModule3("Surface", Surface_methods, module_Surface_doc); /* mod name, table ptr */
|
||||
(void) Surface::initModule();
|
||||
Base::Console().Log("Loading Surface module... done\n");
|
||||
|
||||
// Add types to module
|
||||
@@ -71,5 +85,3 @@ void SurfaceExport initSurface() {
|
||||
Surface::BezSurf ::init();
|
||||
Surface::BSplineSurf ::init();
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Nathan Miller Nathan.A.Mill[at]gmail.com *
|
||||
* *
|
||||
* 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 <Python.h>
|
||||
|
||||
#include <Base/Console.h>
|
||||
#include <Base/PyObjectBase.h>
|
||||
#include <Base/Exception.h>
|
||||
|
||||
|
||||
/* registration table */
|
||||
struct PyMethodDef Surface_methods[] = {
|
||||
{NULL, NULL} /* end of table marker */
|
||||
};
|
||||
@@ -21,7 +21,6 @@ set(Surface_LIBS
|
||||
SET(Surface_SRCS
|
||||
../FillType.h
|
||||
AppSurface.cpp
|
||||
AppSurfacePy.cpp
|
||||
PreCompiled.cpp
|
||||
PreCompiled.h
|
||||
FeatureBSurf.h
|
||||
|
||||
@@ -39,23 +39,36 @@
|
||||
void CreateSurfaceCommands(void);
|
||||
|
||||
|
||||
/* registration table */
|
||||
extern struct PyMethodDef SurfaceGui_methods[];
|
||||
namespace SurfaceGui {
|
||||
class Module : public Py::ExtensionModule<Module>
|
||||
{
|
||||
public:
|
||||
Module() : Py::ExtensionModule<Module>("SurfaceGui")
|
||||
{
|
||||
initialize("This module is the SurfaceGui module."); // register with Python
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(module_SurfaceGui_doc,
|
||||
"This module is the SurfaceGui module.");
|
||||
virtual ~Module() {}
|
||||
|
||||
private:
|
||||
};
|
||||
|
||||
PyObject* initModule()
|
||||
{
|
||||
return (new Module)->module().ptr();
|
||||
}
|
||||
|
||||
} // namespace SurfaceGui
|
||||
|
||||
/* Python entry */
|
||||
extern "C" {
|
||||
void SurfaceGuiExport initSurfaceGui()
|
||||
PyMODINIT_FUNC initSurfaceGui()
|
||||
{
|
||||
if (!Gui::Application::Instance) {
|
||||
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
|
||||
return;
|
||||
}
|
||||
|
||||
// Base::Interpreter().runString("import SurfaceGui"); infinite Python recursion comes
|
||||
Base::Interpreter().runString("import Surface");
|
||||
Base::Interpreter().runString("import PartGui");
|
||||
|
||||
// instanciating the commands
|
||||
@@ -66,8 +79,6 @@ void SurfaceGuiExport initSurfaceGui()
|
||||
|
||||
// SurfaceGui::ViewProviderCut::init();
|
||||
|
||||
(void) Py_InitModule3("SurfaceGui", SurfaceGui_methods, module_SurfaceGui_doc); /* mod name, table ptr */
|
||||
(void) SurfaceGui::initModule();
|
||||
Base::Console().Log("Loading GUI of Surface module... done\n");
|
||||
}
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@@ -1,35 +0,0 @@
|
||||
/***************************************************************************
|
||||
* Copyright (c) 2014 Nathan Miller <Nathan.A.Mill[at]gmail.com> *
|
||||
* *
|
||||
* 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 <Base/Console.h>
|
||||
#include <Base/Exception.h>
|
||||
|
||||
/* registration table */
|
||||
struct PyMethodDef SurfaceGui_methods[] = {
|
||||
{NULL, NULL} /* end of table marker */
|
||||
};
|
||||
@@ -45,7 +45,6 @@ SET(SurfaceGui_SRCS
|
||||
BSurf.h
|
||||
../FillType.h
|
||||
AppSurfaceGui.cpp
|
||||
AppSurfaceGuiPy.cpp
|
||||
Command.cpp
|
||||
PreCompiled.cpp
|
||||
PreCompiled.h
|
||||
|
||||
@@ -46,7 +46,6 @@ Workbench::~Workbench()
|
||||
|
||||
Gui::MenuItem* Workbench::setupMenuBar() const
|
||||
{
|
||||
|
||||
Gui::MenuItem* root = StdWorkbench::setupMenuBar();
|
||||
Gui::MenuItem* item = root->findItem( "&Windows" );
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# (c) 2001 Juergen Riegel LGPL
|
||||
|
||||
class SurfaceWorkbench ( Workbench ):
|
||||
"Surface workbench object"
|
||||
"Surface workbench object"
|
||||
Icon = """
|
||||
/* XPM */
|
||||
static char * Surface_Tools_Workbench_Main_xpm[] = {
|
||||
@@ -72,26 +72,18 @@ class SurfaceWorkbench ( Workbench ):
|
||||
" ",
|
||||
" "};
|
||||
"""
|
||||
MenuText = "Surface"
|
||||
ToolTip = "Surface workbench: Create and edit complex surfaces"
|
||||
def Initialize(self):
|
||||
# load the module
|
||||
import SurfaceGui
|
||||
import FreeCADGui
|
||||
import Surface
|
||||
MenuText = "Surface"
|
||||
ToolTip = "Surface workbench: Create and edit complex surfaces"
|
||||
def Initialize(self):
|
||||
# load the module
|
||||
import SurfaceGui
|
||||
import FreeCADGui
|
||||
import Surface
|
||||
|
||||
# Set path to icon labels
|
||||
FreeCADGui.addIconPath('./Gui/Resources/Icons/')
|
||||
|
||||
def GetClassName(self):
|
||||
return "SurfaceGui::Workbench"
|
||||
|
||||
def Activated(self):
|
||||
# do something here if needed...
|
||||
Msg ("SurfaceWorkbench.Activated()\n")
|
||||
|
||||
def Deactivated(self):
|
||||
# do something here if needed...
|
||||
Msg ("SurfaceWorkbench.Deactivated()\n")
|
||||
# Set path to icon labels
|
||||
FreeCADGui.addIconPath('./Gui/Resources/Icons/')
|
||||
|
||||
def GetClassName(self):
|
||||
return "SurfaceGui::Workbench"
|
||||
|
||||
Gui.addWorkbench(SurfaceWorkbench())
|
||||
|
||||
Reference in New Issue
Block a user