diff --git a/src/Gui/CommandPy.xml b/src/Gui/CommandPy.xml index 84f6550200..410be417fb 100644 --- a/src/Gui/CommandPy.xml +++ b/src/Gui/CommandPy.xml @@ -94,5 +94,10 @@ Usage: menuText, tooltipText, whatsThisText, statustipText, pixmapText, shortcut + + + getAction() -> list of QAction + + diff --git a/src/Gui/CommandPyImp.cpp b/src/Gui/CommandPyImp.cpp index 2597680a49..ac53da4441 100644 --- a/src/Gui/CommandPyImp.cpp +++ b/src/Gui/CommandPyImp.cpp @@ -31,6 +31,7 @@ #include "MainWindow.h" #include "Selection.h" #include "Window.h" +#include "WidgetFactory.h" // inclusion of the generated files (generated out of AreaPy.xml) #include "CommandPy.h" @@ -311,6 +312,36 @@ PyObject* CommandPy::getInfo(PyObject *args) } } +PyObject* CommandPy::getAction(PyObject *args) +{ + if (!PyArg_ParseTuple(args, "")) + return nullptr; + + Command* cmd = this->getCommandPtr(); + if (cmd) { + Action* action = cmd->getAction(); + ActionGroup* group = qobject_cast(action); + + PythonWrapper wrap; + wrap.loadWidgetsModule(); + + Py::List list; + if (group) { + for (auto a : group->actions()) + list.append(wrap.fromQObject(a)); + } + else if (action) { + list.append(wrap.fromQObject(action->action())); + } + + return Py::new_reference_to(list); + } + else { + PyErr_Format(Base::BaseExceptionFreeCADError, "No such command"); + return nullptr; + } +} + PyObject *CommandPy::getCustomAttributes(const char* /*attr*/) const { return 0;