| 776 | } |
| 777 | |
| 778 | PyObject* 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 |
nothing calls this directly
no test coverage detected