Skip to content

Commit

Permalink
Merge pull request #472 from looooo/python3-complete
Browse files Browse the repository at this point in the history
py3: ported Complete to python3
  • Loading branch information
wwmayer committed Jan 27, 2017
2 parents f47fc48 + 38921cf commit a460c54
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 33 deletions.
15 changes: 15 additions & 0 deletions src/Base/PyObjectBase.h
Expand Up @@ -84,6 +84,21 @@
*/
#define PYFUNCIMP_S(CLASS,SFUNC) PyObject* CLASS::SFUNC (PyObject *self,PyObject *args,PyObject *kwd)


/** Macro for initialization function of Python modules.
*/
#if PY_MAJOR_VERSION >= 3
# define PyMOD_INIT_FUNC(name) PyMODINIT_FUNC PyInit_##name(void)
#else
# define PyMOD_INIT_FUNC(name) PyMODINIT_FUNC init##name(void)
#endif

#if PY_MAJOR_VERSION >= 3
# define PyMOD_Return(name) return name
#else
# define PyMOD_Return(name) return
#endif

/**
* Union to convert from PyTypeObject to PyObject pointer.
*/
Expand Down
8 changes: 5 additions & 3 deletions src/Mod/Complete/App/AppComplete.cpp
Expand Up @@ -30,6 +30,7 @@
#include <CXX/Objects.hxx>

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

#include "CompleteConfiguration.h"
Expand Down Expand Up @@ -57,7 +58,7 @@ PyObject* initModule()


/* Python entry */
PyMODINIT_FUNC initComplete()
PyMOD_INIT_FUNC(Complete)
{
// load dependent module
try {
Expand Down Expand Up @@ -86,8 +87,9 @@ PyMODINIT_FUNC initComplete()
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
PyMOD_Return(0);
}
(void)Complete::initModule();
PyObject* mod = Complete::initModule();
Base::Console().Log("Loading Complete module... done\n");
PyMOD_Return(mod);
}
62 changes: 32 additions & 30 deletions src/Mod/Complete/Gui/AppCompleteGui.cpp
Expand Up @@ -74,32 +74,32 @@ PyObject* initModule()


/* Python entry */
PyMODINIT_FUNC initCompleteGui()
PyMOD_INIT_FUNC(CompleteGui)
{
if (!Gui::Application::Instance) {
PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
return;
PyMOD_Return(0);
}

// try to load dependent modules, currently not (AssemblyGui, CamGui)
char *modules[] = {"PartGui", "MeshGui", "MeshPartGui", "PointsGui", "DrawingGui", "RaytracingGui", "SketcherGui", "PartDesignGui", "ImageGui", "TestGui"};
size_t nModules = sizeof(modules) / sizeof(char*);
for (size_t i = 0; i < nModules; i++) {
try {
Base::Interpreter().loadModule(modules[i]);
}
catch (const Base::Exception& e) {
Base::Console().Error("%s\n", e.what());
// Prints message to console window if we are in interactive mode
PyErr_Print();
continue;
}
mods.append(QSTRING(modules[i]));
}

# ifdef COMPLETE_USE_DRAFTING
mods.append(QSTRING("DraftGui"));
try {
// try to load dependent modules, currently not (AssemblyGui, CamGui)
char *modules[] = {"PartGui", "MeshGui", "MeshPartGui", "PointsGui", "DrawingGui", "RaytracingGui", "SketcherGui", "PartDesignGui", "ImageGui", "TestGui"};
size_t nModules = sizeof(modules) / sizeof(char*);
for (size_t i = 0; i < nModules; i++) {
try {
Base::Interpreter().loadModule(modules[i]);
}
catch (const Base::Exception& e) {
Base::Console().Error("%s\n", e.what());
// Prints message to console window if we are in interactive mode
PyErr_Print();
continue;
}
mods.append(QSTRING(modules[i]));
}

# ifdef COMPLETE_USE_DRAFTING
mods.append(QSTRING("DraftGui"));
try {
Py::Module module(PyImport_ImportModule("FreeCADGui"),true);
Py::Callable method(module.getAttr(std::string("getWorkbench")));

Expand Down Expand Up @@ -128,15 +128,15 @@ PyMODINIT_FUNC initCompleteGui()
// Get the CompleteWorkbench handler
args.setItem(0,Py::String("CompleteWorkbench"));
}
catch (const Base::Exception& e) {
Base::Console().Error("%s\n", e.what());
mods.removeAt(mods.size());
// Prints message to console window if we are in interactive mode
PyErr_Print();
}
# endif

(void) CompleteGui::initModule();
catch (const Base::Exception& e) {
Base::Console().Error("%s\n", e.what());
mods.removeAt(mods.size());
// Prints message to console window if we are in interactive mode
PyErr_Print();
}
# endif

PyObject* mod = CompleteGui::initModule();
Base::Console().Log("Loading GUI of Complete module... done\n");

// instantiating the commands
Expand All @@ -145,4 +145,6 @@ PyMODINIT_FUNC initCompleteGui()

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

PyMOD_Return(mod);
}

0 comments on commit a460c54

Please sign in to comment.