MCPcopy Create free account
hub / github.com/FreeCAD/FreeCAD / sActiveView

Method sActiveView

src/Gui/ApplicationPy.cpp:778–816  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778PyObject* Gui::ApplicationPy::sActiveView(PyObject* /*self*/, PyObject* args)
779{
780 const char* typeName = nullptr;
781 if (!PyArg_ParseTuple(args, "|s", &typeName)) {
782 return nullptr;
783 }
784
785 requirePythonMainThread("FreeCADGui.activeView");
786
787 PY_TRY
788 {
789 Base::Type type;
790 if (typeName) {
791 type = Base::Type::fromName(typeName);
792 if (type.isBad()) {
793 PyErr_Format(PyExc_TypeError, "Invalid type '%s'", typeName);
794 return nullptr;
795 }
796 }
797
798 Gui::MDIView* mdiView = Application::Instance->activeView();
799 if (mdiView && (type.isBad() || mdiView->isDerivedFrom(type))) {
800 auto res = Py::asObject(mdiView->getPyObject());
801 if (!res.isNone() || !type.isBad()) {
802 return Py::new_reference_to(res);
803 }
804 }
805
806 if (type.isBad()) {
807 type = Gui::View3DInventor::getClassTypeId();
808 }
809 Application::Instance->activateView(type, true);
810 mdiView = Application::Instance->activeView();
811 if (mdiView) {
812 return mdiView->getPyObject();
813 }
814
815 Py_Return;
816 }
817 PY_CATCH
818}
819

Callers

nothing calls this directly

Calls 9

requirePythonMainThreadFunction · 0.85
new_reference_toFunction · 0.85
isNoneMethod · 0.80
TypeEnum · 0.70
isBadMethod · 0.45
activeViewMethod · 0.45
isDerivedFromMethod · 0.45
getPyObjectMethod · 0.45
activateViewMethod · 0.45

Tested by

no test coverage detected