diff --git a/src/Mod/Complete/Gui/AppCompleteGui.cpp b/src/Mod/Complete/Gui/AppCompleteGui.cpp index c844fd223a..c43fa33bc3 100644 --- a/src/Mod/Complete/Gui/AppCompleteGui.cpp +++ b/src/Mod/Complete/Gui/AppCompleteGui.cpp @@ -36,6 +36,8 @@ #include +QList mods; + // use a different name to CreateCommand() void CreateCompleteCommands(void); @@ -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"))); @@ -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");