Merge pull request #472 from looooo/python3-complete

py3: ported Complete to python3
This commit is contained in:
wwmayer 2017-01-27 15:53:10 +01:00 committed by GitHub
commit a460c540f4
3 changed files with 51 additions and 32 deletions

View File

@ -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.
*/

View File

@ -30,6 +30,7 @@
#include <CXX/Objects.hxx>
#include <Base/Console.h>
#include <Base/PyObjectBase.h>
#include <Base/Interpreter.h>
#include "CompleteConfiguration.h"
@ -57,7 +58,7 @@ PyObject* initModule()
/* Python entry */
PyMODINIT_FUNC initComplete()
PyMOD_INIT_FUNC(Complete)
{
// load dependent module
try {
@ -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);
}

View File

@ -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")));
@ -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
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();
PyObject* mod = CompleteGui::initModule();
Base::Console().Log("Loading GUI of Complete module... done\n");
// instantiating the commands
@ -145,4 +145,6 @@ PyMODINIT_FUNC initCompleteGui()
// add resources and reloads the translators
loadCompleteResource();
PyMOD_Return(mod);
}