void ViewProviderPythonFeatureImp::setupContextMenu(QMenu* menu) { // Run the attach method of the proxy object. Base::PyGILStateLocker lock; try { App::Property* proxy = object->getPropertyByName("Proxy"); if (proxy && proxy->getTypeId() == App::PropertyPythonObject::getClassTypeId()) { Py::Object vp = static_cast<App::PropertyPythonObject*>(proxy)->getValue(); if (vp.hasAttr(std::string("setupContextMenu"))) { if (vp.hasAttr("__object__")) { PythonWrapper wrap; wrap.loadGuiModule(); wrap.loadWidgetsModule(); Py::Callable method(vp.getAttr(std::string("setupContextMenu"))); Py::Tuple args(1); args.setItem(0, wrap.fromQWidget(menu, "QMenu")); method.apply(args); } else { PythonWrapper wrap; wrap.loadGuiModule(); wrap.loadWidgetsModule(); Py::Callable method(vp.getAttr(std::string("setupContextMenu"))); Py::Tuple args(2); args.setItem(0, Py::Object(object->getPyObject(), true)); args.setItem(1, wrap.fromQWidget(menu, "QMenu")); method.apply(args); } } } } catch (Py::Exception&) { Base::PyException e; // extract the Python error text e.ReportException(); } }
PyObject* Application::sGetMainWindow(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; PythonWrapper wrap; wrap.loadCoreModule(); wrap.loadGuiModule(); wrap.loadWidgetsModule(); try { return Py::new_reference_to(wrap.fromQWidget(Gui::getMainWindow(), "QMainWindow")); } catch (const Py::Exception&) { return 0; } }
PyObject* Application::sGetMainWindow(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, "")) return NULL; PythonWrapper wrap; if (!wrap.loadCoreModule() || !wrap.loadGuiModule() || !wrap.loadWidgetsModule()) { PyErr_SetString(PyExc_RuntimeError, "Failed to load Python wrapper for Qt"); return 0; } try { return Py::new_reference_to(wrap.fromQWidget(Gui::getMainWindow(), "QMainWindow")); } catch (const Py::Exception&) { return 0; } }