AppCompleteGui.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #include "PreCompiled.h"
00025 #ifndef _PreComp_
00026 # include <Python.h>
00027 #endif
00028
00029 #include <Base/Console.h>
00030 #include <Base/Interpreter.h>
00031 #include <Gui/Application.h>
00032 #include <Gui/WorkbenchManager.h>
00033 #include <Gui/Language/Translator.h>
00034 #include "Workbench.h"
00035
00036 #include <Mod/Complete/App/CompleteConfiguration.h>
00037
00038
00039
00040 void CreateCompleteCommands(void);
00041
00042 void loadCompleteResource()
00043 {
00044
00045 Q_INIT_RESOURCE(Complete);
00046 Gui::Translator::instance()->refresh();
00047 }
00048
00049
00050 extern struct PyMethodDef CompleteGui_Import_methods[];
00051
00052
00053
00054 extern "C" {
00055 void CompleteGuiExport initCompleteGui()
00056 {
00057 if (!Gui::Application::Instance) {
00058 PyErr_SetString(PyExc_ImportError, "Cannot load Gui module in console application.");
00059 return;
00060 }
00061
00062
00063 try {
00064 Base::Interpreter().loadModule("PartGui");
00065 Base::Interpreter().loadModule("MeshGui");
00066 try {
00067 Base::Interpreter().loadModule("MeshPartGui");
00068 }
00069 catch (const Base::Exception& e) {
00070 Base::Console().Error("Failed to load MeshPartGui: %s\n", e.what());
00071 PyErr_Clear();
00072 }
00073 Base::Interpreter().loadModule("PointsGui");
00074
00075
00076 Base::Interpreter().loadModule("DrawingGui");
00077 Base::Interpreter().loadModule("RaytracingGui");
00078 # ifdef COMPLETE_SHOW_SKETCHER
00079 Base::Interpreter().loadModule("SketcherGui");
00080 # endif
00081 Base::Interpreter().loadModule("PartDesignGui");
00082 Base::Interpreter().loadModule("ImageGui");
00083
00084 Base::Interpreter().loadModule("TestGui");
00085 # ifdef COMPLETE_USE_DRAFTING
00086 Py::Module module(PyImport_ImportModule("FreeCADGui"),true);
00087 Py::Callable method(module.getAttr(std::string("getWorkbench")));
00088
00089
00090 Py::Tuple args(1);
00091 args.setItem(0,Py::String("DraftWorkbench"));
00092 Py::Object handler(method.apply(args));
00093
00094 std::string type;
00095 if (!handler.hasAttr(std::string("__Workbench__"))) {
00096
00097 Py::Callable method(handler.getAttr(std::string("GetClassName")));
00098 Py::Tuple args;
00099 Py::String result(method.apply(args));
00100 type = result.as_std_string();
00101 if (type == "Gui::PythonWorkbench") {
00102 Gui::Workbench* wb = Gui::WorkbenchManager::instance()->createWorkbench("DraftWorkbench", type);
00103 handler.setAttr(std::string("__Workbench__"), Py::Object(wb->getPyObject(), true));
00104 }
00105
00106
00107 Py::Callable activate(handler.getAttr(std::string("Initialize")));
00108 activate.apply(args);
00109 }
00110
00111
00112 args.setItem(0,Py::String("CompleteWorkbench"));
00113 # endif
00114 }
00115 catch(const Base::Exception& e) {
00116 PyErr_SetString(PyExc_ImportError, e.what());
00117 return;
00118 }
00119 catch (Py::Exception& e) {
00120 Py::Object o = Py::type(e);
00121 if (o.isString()) {
00122 Py::String s(o);
00123 Base::Console().Error("%s\n", s.as_std_string().c_str());
00124 }
00125 else {
00126 Py::String s(o.repr());
00127 Base::Console().Error("%s\n", s.as_std_string().c_str());
00128 }
00129
00130 PyErr_Print();
00131 }
00132
00133 (void) Py_InitModule("CompleteGui", CompleteGui_Import_methods);
00134 Base::Console().Log("Loading GUI of Complete module... done\n");
00135
00136
00137 CreateCompleteCommands();
00138 CompleteGui::Workbench::init();
00139
00140
00141 loadCompleteResource();
00142 }
00143
00144 }