py3: ported module init to python3

This commit is contained in:
wmayer 2016-01-23 15:30:29 +01:00
parent 915a1b18c4
commit 76b3397762
11 changed files with 92 additions and 37 deletions

View File

@ -18,6 +18,7 @@
#include <CXX/Objects.hxx>
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include "ImagePlane.h"
@ -43,12 +44,12 @@ PyObject* initModule()
} // namespace Image
/* Python entry */
PyMODINIT_FUNC initImage()
PyMOD_INIT_FUNC(Image)
{
(void) Image::initModule();
PyObject* mod = Image::initModule();
Base::Console().Log("Loading Image module... done\n");
Image::ImagePlane::init();
return;
PyMOD_Return(mod);
}

View File

@ -37,14 +37,14 @@ extern PyObject* initModule();
/* Python entry */
PyMODINIT_FUNC initImageGui()
PyMOD_INIT_FUNC(ImageGui)
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
PyMOD_Return(0);
}
(void) ImageGui::initModule();
PyObject* mod = ImageGui::initModule();
Base::Console().Log("Loading GUI of Image module... done\n");
// instantiating the commands
@ -55,4 +55,6 @@ PyMODINIT_FUNC initImageGui()
// add resources and reloads the translators
loadImageResource();
PyMOD_Return(mod);
}

View File

@ -49,7 +49,7 @@ extern PyObject* initModule();
}
/* Python entry */
PyMODINIT_FUNC initMesh()
PyMOD_INIT_FUNC(Mesh)
{
PyObject* meshModule = Mesh::initModule();
Base::Console().Log("Loading Mesh module... done\n");
@ -99,4 +99,6 @@ PyMODINIT_FUNC initMesh()
Mesh::Cone ::init();
Mesh::Torus ::init();
Mesh::Cube ::init();
PyMOD_Return(meshModule);
}

View File

@ -88,11 +88,11 @@ PyObject* initModule()
} // namespace MeshGui
/* Python entry */
PyMODINIT_FUNC initMeshGui()
PyMOD_INIT_FUNC(MeshGui)
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
PyMOD_Return(0);
}
// load dependent module
@ -101,9 +101,9 @@ PyMODINIT_FUNC initMeshGui()
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
PyMOD_Return(0);
}
(void) MeshGui::initModule();
PyObject* mod = MeshGui::initModule();
Base::Console().Log("Loading GUI of Mesh module... done\n");
// Register icons
@ -154,4 +154,6 @@ PyMODINIT_FUNC initMeshGui()
// add resources and reloads the translators
loadMeshResource();
PyMOD_Return(mod);
}

View File

@ -40,7 +40,7 @@ namespace Points {
}
/* Python entry */
PyMODINIT_FUNC initPoints()
PyMOD_INIT_FUNC(Points)
{
PyObject* pointsModule = Points::initModule();
Base::Console().Log("Loading Points module... done\n");
@ -60,5 +60,5 @@ PyMODINIT_FUNC initPoints()
Points::Structured ::init();
Points::FeatureCustom ::init();
Points::StructuredCustom ::init();
Points::FeaturePython ::init();
Points::FeaturePython ::init();
}

View File

@ -61,15 +61,20 @@ public:
private:
};
PyObject* initModule()
{
return (new Module)->module().ptr();
}
} // namespace PointsGui
/* Python entry */
PyMODINIT_FUNC initPointsGui()
PyMOD_INIT_FUNC(PointsGui)
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
PyMOD_Return(0);
}
// load dependent module
@ -78,11 +83,11 @@ PyMODINIT_FUNC initPointsGui()
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
PyMOD_Return(0);
}
Base::Console().Log("Loading GUI of Points module... done\n");
(void)new PointsGui::Module();
PyObject* mod = PointsGui::initModule();
// instantiating the commands
CreatePointsCommands();
@ -98,4 +103,6 @@ PyMODINIT_FUNC initPointsGui()
// add resources and reloads the translators
loadPointsResource();
PyMOD_Return(mod);
}

View File

@ -32,20 +32,21 @@
#include <Gui/Language/Translator.h>
#include <Base/Console.h>
class UnitTestModule : public Py::ExtensionModule<UnitTestModule>
namespace TestGui {
class Module : public Py::ExtensionModule<Module>
{
public:
UnitTestModule() : Py::ExtensionModule<UnitTestModule>("QtUnitGui")
Module() : Py::ExtensionModule<Module>("QtUnitGui")
{
TestGui::UnitTestDialogPy::init_type();
add_varargs_method("UnitTest",&UnitTestModule::new_UnitTest,"UnitTest");
add_varargs_method("setTest",&UnitTestModule::setTest,"setTest");
add_varargs_method("addTest",&UnitTestModule::addTest,"addTest");
add_varargs_method("UnitTest",&Module::new_UnitTest,"UnitTest");
add_varargs_method("setTest",&Module::setTest,"setTest");
add_varargs_method("addTest",&Module::addTest,"addTest");
initialize("This module is the QtUnitGui module"); // register with Python
}
virtual ~UnitTestModule() {}
virtual ~Module() {}
private:
Py::Object new_UnitTest(const Py::Tuple& args)
@ -82,6 +83,13 @@ private:
}
};
PyObject* initModule()
{
return (new Module())->module().ptr();
}
}
void loadTestResource()
{
// add resources and reloads the translators
@ -90,15 +98,15 @@ void loadTestResource()
}
/* Python entry */
PyMODINIT_FUNC initQtUnitGui()
PyMOD_INIT_FUNC(QtUnitGui)
{
// the following constructor call registers our extension module
// with the Python runtime system
(void)new UnitTestModule;
PyObject* mod = TestGui::initModule();
Base::Console().Log("Loading GUI of Test module... done\n");
// add resources and reloads the translators
loadTestResource();
return;
PyMOD_Return(mod);
}

View File

@ -29,6 +29,7 @@
#endif
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
@ -99,7 +100,7 @@ private:
quint16 p = server->serverPort();
Py::Tuple t(2);
t.setItem(0, Py::String((const char*)a.toLatin1()));
t.setItem(1, Py::Int(p));
t.setItem(1, Py::Long(p));
return t;
}
else {
@ -125,15 +126,22 @@ private:
return Py::None();
}
};
PyObject* initModule()
{
return (new Module())->module().ptr();
}
} // namespace Web
/* Python entry */
PyMODINIT_FUNC initWeb() {
PyMOD_INIT_FUNC(Web) {
// ADD YOUR CODE HERE
//
//
new Web::Module();
PyObject* mod = Web::initModule();
Base::Console().Log("Loading Web module... done\n");
PyMOD_Return(mod);
}

View File

@ -100,6 +100,12 @@ private:
return Py::None();
}
};
PyObject* initModule()
{
return (new Module())->module().ptr();
}
} // namespace WebGui
@ -108,10 +114,10 @@ PyMODINIT_FUNC initWebGui()
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
PyMOD_Return(0);
}
new WebGui::Module();
PyObject* mod = WebGui::initModule();
Base::Console().Log("Loading GUI of Web module... done\n");
// instantiating the commands
@ -120,4 +126,6 @@ PyMODINIT_FUNC initWebGui()
// add resources and reloads the translators
loadWebResource();
PyMOD_Return(mod);
}

View File

@ -27,6 +27,7 @@
#endif
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
@ -45,15 +46,23 @@ public:
private:
};
PyObject* initModule()
{
return (new Module)->module().ptr();
}
} // namespace _TEMPLATE_
/* Python entry */
PyMODINIT_FUNC init_TEMPLATE_() {
PyMOD_INIT_FUNC(_TEMPLATE_)
{
// ADD YOUR CODE HERE
//
//
new _TEMPLATE_::Module();
PyObject* mod = _TEMPLATE_::initModule();
Base::Console().Log("Loading _TEMPLATE_ module... done\n");
PyMOD_Return(mod);
}

View File

@ -27,6 +27,7 @@
#endif
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include <Gui/Application.h>
#include "Workbench.h"
@ -51,15 +52,21 @@ public:
private:
};
PyObject* initModule()
{
return (new Module)->module().ptr();
}
} // namespace _TEMPLATE_Gui
/* Python entry */
PyMODINIT_FUNC init_TEMPLATE_Gui()
PyMOD_INIT_FUNC(_TEMPLATE_Gui)
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
PyMOD_Return(0);
}
// instanciating the commands
@ -69,6 +76,7 @@ PyMODINIT_FUNC init_TEMPLATE_Gui()
// ADD YOUR CODE HERE
//
//
new _TEMPLATE_Gui::Module();
PyObject* mod = _TEMPLATE_Gui::initModule();
Base::Console().Log("Loading GUI of _TEMPLATE_ module... done\n");
PyMOD_Return(mod);
}