+ simplify porting of Start module to Python3

This commit is contained in:
wmayer 2016-01-17 22:13:32 +01:00
parent a467612b9f
commit d78d747760
6 changed files with 35 additions and 83 deletions

View File

@ -28,21 +28,29 @@
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
#include "StartConfiguration.h"
extern struct PyMethodDef Start_methods[];
namespace Start {
class Module : public Py::ExtensionModule<Module>
{
public:
Module() : Py::ExtensionModule<Module>("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"

View File

@ -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 <Python.h>
#endif
/* registration table */
struct PyMethodDef Start_methods[] = {
{NULL, NULL} /* end of table marker */
};

View File

@ -12,7 +12,6 @@ set(Start_LIBS
SET(Start_SRCS
AppStart.cpp
AppStartPy.cpp
PreCompiled.cpp
PreCompiled.h
StartConfiguration.h

View File

@ -26,6 +26,9 @@
# include <Python.h>
#endif
#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
#include <Base/Console.h>
#include <Base/Interpreter.h>
#include <Gui/Application.h>
@ -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<Module>
{
public:
Module() : Py::ExtensionModule<Module>("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" {

View File

@ -1,33 +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 StartGui_Import_methods[] = {
{NULL, NULL} /* end of table marker */
};

View File

@ -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