Skip to content

Commit

Permalink
py3: ported Complete to python3
Browse files Browse the repository at this point in the history
  • Loading branch information
wwmayer authored and looooo committed Jan 25, 2017
1 parent 9f2a389 commit 38921cf
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 33 deletions.
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 38921cf

Please sign in to comment.