Skip to content

Commit

Permalink
Gui: extend MainWindowPy
Browse files Browse the repository at this point in the history
* implement MainWindowPy::getWindows
* implement MainWindowPy::getWindowsOfType
  • Loading branch information
wwmayer committed Nov 19, 2021
1 parent 6bf724c commit 7512274
Showing 1 changed file with 31 additions and 2 deletions.
33 changes: 31 additions & 2 deletions src/Gui/MainWindowPy.cpp
Expand Up @@ -32,6 +32,7 @@
#include "MDIView.h"
#include "MDIViewPy.h"
#include "PythonWrapper.h"
#include <Base/TypePy.h>


using namespace Gui;
Expand Down Expand Up @@ -118,12 +119,40 @@ Py::Object MainWindowPy::getWindows(const Py::Tuple& args)
if (!PyArg_ParseTuple(args.ptr(), ""))
throw Py::Exception();

return Py::None();
Py::List mdis;
if (_mw) {
QList<QWidget*> windows = _mw->windows();
for (auto it : windows) {
MDIView* view = qobject_cast<MDIView*>(it);
if (view) {
mdis.append(Py::asObject(view->getPyObject()));
}
}
}

return mdis;
}

Py::Object MainWindowPy::getWindowsOfType(const Py::Tuple& args)
{
return Py::None();
PyObject* t;
if (!PyArg_ParseTuple(args.ptr(), "O!", &Base::TypePy::Type, &t))
throw Py::Exception();

Base::Type typeId = *static_cast<Base::TypePy*>(t)->getBaseTypePtr();

Py::List mdis;
if (_mw) {
QList<QWidget*> windows = _mw->windows();
for (auto it : windows) {
MDIView* view = qobject_cast<MDIView*>(it);
if (view && view->isDerivedFrom(typeId)) {
mdis.append(Py::asObject(view->getPyObject()));
}
}
}

return mdis;
}

Py::Object MainWindowPy::setActiveWindow(const Py::Tuple& args)
Expand Down

0 comments on commit 7512274

Please sign in to comment.