Skip to content

Commit

Permalink
Mod/Complete: Check for modules at runtime.This fixes runtime errors …
Browse files Browse the repository at this point in the history
…if e. g. TestGui isn't installed due to -DBUILD_TEST=OFF ...
  • Loading branch information
jobermayr authored and wwmayer committed Feb 8, 2015
1 parent b63c5d0 commit 4ef4369
Showing 1 changed file with 28 additions and 42 deletions.
70 changes: 28 additions & 42 deletions src/Mod/Complete/Gui/AppCompleteGui.cpp
Expand Up @@ -36,6 +36,8 @@
#include <Mod/Complete/App/CompleteConfiguration.h>


QList<QString> mods;

// use a different name to CreateCommand()
void CreateCompleteCommands(void);

Expand All @@ -59,30 +61,25 @@ void CompleteGuiExport initCompleteGui()
return;
}

// load dependent module
try {
Base::Interpreter().loadModule("PartGui");
Base::Interpreter().loadModule("MeshGui");
try {
Base::Interpreter().loadModule("MeshPartGui");
}
catch (const Base::Exception& e) {
Base::Console().Error("Failed to load MeshPartGui: %s\n", e.what());
PyErr_Clear();
}
Base::Interpreter().loadModule("PointsGui");
//Base::Interpreter().loadModule("MeshPartGui");
//Base::Interpreter().loadModule("AssemblyGui");
Base::Interpreter().loadModule("DrawingGui");
Base::Interpreter().loadModule("RaytracingGui");
# ifdef COMPLETE_SHOW_SKETCHER
Base::Interpreter().loadModule("SketcherGui");
# endif
Base::Interpreter().loadModule("PartDesignGui");
Base::Interpreter().loadModule("ImageGui");
//Base::Interpreter().loadModule("CamGui");
Base::Interpreter().loadModule("TestGui");
# ifdef COMPLETE_USE_DRAFTING
// try to load dependent modules, currently not (AssemblyGui, CamGui)
char *modules[] = {"PartGui", "MeshGui", "MeshPartGui", "PointsGui", "DrawingGui", "RaytracingGui", "SketcherGui", "PartDesignGui", "ImageGui", "TestGui"};
char nModules = sizeof(modules) / sizeof(char*);
for (char 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 @@ -110,25 +107,14 @@ void CompleteGuiExport initCompleteGui()

// Get the CompleteWorkbench handler
args.setItem(0,Py::String("CompleteWorkbench"));
# endif
}
catch(const Base::Exception& e) {
PyErr_SetString(PyExc_ImportError, e.what());
return;
}
catch (Py::Exception& e) {
Py::Object o = Py::type(e);
if (o.isString()) {
Py::String s(o);
Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());
}
else {
Py::String s(o.repr());
Base::Console().Error("%s\n", s.as_std_string("utf-8").c_str());
}
// Prints message to console window if we are in interactive mode
PyErr_Print();
}
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) Py_InitModule("CompleteGui", CompleteGui_Import_methods); /* mod name, table ptr */
Base::Console().Log("Loading GUI of Complete module... done\n");
Expand Down

0 comments on commit 4ef4369

Please sign in to comment.