Gui: [skip ci] add method to return list of QAction of a Command

This commit is contained in:
wmayer
2020-11-23 16:49:25 +01:00
parent cd3cf83415
commit 84d730c194
2 changed files with 36 additions and 0 deletions

View File

@@ -94,5 +94,10 @@ Usage: menuText, tooltipText, whatsThisText, statustipText, pixmapText, shortcut
</UserDocu>
</Documentation>
</Methode>
<Methode Name="getAction">
<Documentation>
<UserDocu>getAction() -> list of QAction</UserDocu>
</Documentation>
</Methode>
</PythonExport>
</GenerateModel>

View File

@@ -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<ActionGroup*>(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;