Skip to content

Commit

Permalink
py3: ported module init to python3
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer committed Feb 4, 2017
1 parent 915a1b1 commit 76b3397
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 37 deletions.
7 changes: 4 additions & 3 deletions src/Mod/Image/App/AppImage.cpp
Expand Up @@ -18,6 +18,7 @@
#include <CXX/Objects.hxx>

#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include "ImagePlane.h"


Expand All @@ -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);
}
8 changes: 5 additions & 3 deletions src/Mod/Image/Gui/AppImageGui.cpp
Expand Up @@ -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
Expand All @@ -55,4 +55,6 @@ PyMODINIT_FUNC initImageGui()

// add resources and reloads the translators
loadImageResource();

PyMOD_Return(mod);
}
4 changes: 3 additions & 1 deletion src/Mod/Mesh/App/AppMesh.cpp
Expand Up @@ -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");
Expand Down Expand Up @@ -99,4 +99,6 @@ PyMODINIT_FUNC initMesh()
Mesh::Cone ::init();
Mesh::Torus ::init();
Mesh::Cube ::init();

PyMOD_Return(meshModule);
}
10 changes: 6 additions & 4 deletions src/Mod/Mesh/Gui/AppMeshGui.cpp
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -154,4 +154,6 @@ PyMODINIT_FUNC initMeshGui()

// add resources and reloads the translators
loadMeshResource();

PyMOD_Return(mod);
}
4 changes: 2 additions & 2 deletions src/Mod/Points/App/AppPoints.cpp
Expand Up @@ -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");
Expand All @@ -60,5 +60,5 @@ PyMODINIT_FUNC initPoints()
Points::Structured ::init();
Points::FeatureCustom ::init();
Points::StructuredCustom ::init();
Points::FeaturePython ::init();
Points::FeaturePython ::init();
}
15 changes: 11 additions & 4 deletions src/Mod/Points/Gui/AppPointsGui.cpp
Expand Up @@ -61,15 +61,20 @@ class Module : public Py::ExtensionModule<Module>
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
Expand All @@ -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();
Expand All @@ -98,4 +103,6 @@ PyMODINIT_FUNC initPointsGui()

// add resources and reloads the translators
loadPointsResource();

PyMOD_Return(mod);
}
26 changes: 17 additions & 9 deletions src/Mod/Test/Gui/AppTestGui.cpp
Expand Up @@ -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)
Expand Down Expand Up @@ -82,6 +83,13 @@ class UnitTestModule : public Py::ExtensionModule<UnitTestModule>
}
};

PyObject* initModule()
{
return (new Module())->module().ptr();
}

}

void loadTestResource()
{
// add resources and reloads the translators
Expand All @@ -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);
}
14 changes: 11 additions & 3 deletions src/Mod/Web/App/AppWeb.cpp
Expand Up @@ -29,6 +29,7 @@
#endif

#include <Base/Console.h>
#include <Base/PyObjectBase.h>

#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
Expand Down Expand Up @@ -99,7 +100,7 @@ class Module : public Py::ExtensionModule<Module>
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 {
Expand All @@ -125,15 +126,22 @@ class Module : public Py::ExtensionModule<Module>
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);
}
12 changes: 10 additions & 2 deletions src/Mod/Web/Gui/AppWebGui.cpp
Expand Up @@ -100,6 +100,12 @@ class Module : public Py::ExtensionModule<Module>
return Py::None();
}
};

PyObject* initModule()
{
return (new Module())->module().ptr();
}

} // namespace WebGui


Expand All @@ -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
Expand All @@ -120,4 +126,6 @@ PyMODINIT_FUNC initWebGui()

// add resources and reloads the translators
loadWebResource();

PyMOD_Return(mod);
}
15 changes: 12 additions & 3 deletions src/Tools/_TEMPLATE_/App/App_TEMPLATE_.cpp
Expand Up @@ -27,6 +27,7 @@
#endif

#include <Base/Console.h>
#include <Base/PyObjectBase.h>

#include <CXX/Extensions.hxx>
#include <CXX/Objects.hxx>
Expand All @@ -45,15 +46,23 @@ class Module : public Py::ExtensionModule<Module>

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);
}
14 changes: 11 additions & 3 deletions src/Tools/_TEMPLATE_/Gui/App_TEMPLATE_Gui.cpp
Expand Up @@ -27,6 +27,7 @@
#endif

#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include <Gui/Application.h>

#include "Workbench.h"
Expand All @@ -51,15 +52,21 @@ class Module : public Py::ExtensionModule<Module>

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
Expand All @@ -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);
}

0 comments on commit 76b3397

Please sign in to comment.