py3: ported Complete to python3

This commit is contained in:
wmayer
2016-01-23 19:30:15 +01:00
committed by looooo
parent a88afb33af
commit 843a36ccf8
2 changed files with 36 additions and 32 deletions

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);
}