added FreeCADGui.listCommands() method

This commit is contained in:
Yorik van Havre 2016-04-27 22:42:22 -03:00
parent c12c4368cc
commit d6c8d6c62c
No known key found for this signature in database
GPG Key ID: 4C7794EF1595A813
2 changed files with 19 additions and 0 deletions

View File

@ -222,6 +222,7 @@ public:
PYFUNCDEF_S(sRunCommand);
PYFUNCDEF_S(sAddCommand);
PYFUNCDEF_S(sListCommands);
PYFUNCDEF_S(sHide); // deprecated
PYFUNCDEF_S(sShow); // deprecated

View File

@ -121,6 +121,9 @@ PyMethodDef Application::Methods[] = {
{"runCommand", (PyCFunction) Application::sRunCommand, 1,
"runCommand(string) -> None\n\n"
"Run command with name"},
{"listCommands", (PyCFunction) Application::sListCommands,1,
"listCommands() -> list of strings\n\n"
"Returns a list of all commands known to FreeCAD."},
{"SendMsgToActiveView", (PyCFunction) Application::sSendActiveView, 1,
"deprecated -- use class View"},
{"hide", (PyCFunction) Application::sHide, 1,
@ -1014,6 +1017,21 @@ PyObject* Application::sRunCommand(PyObject * /*self*/, PyObject *args,PyObject
}
}
PyObject* Application::sListCommands(PyObject * /*self*/, PyObject *args,PyObject * /*kwd*/)
{
if (!PyArg_ParseTuple(args, "")) // convert args: Python->C
return NULL; // NULL triggers exception
std::vector <Command*> cmds = Application::Instance->commandManager().getAllCommands();
PyObject* pyList = PyList_New(cmds.size());
int i=0;
for ( std::vector<Command*>::iterator it = cmds.begin(); it != cmds.end(); ++it ) {
PyObject* str = PyString_FromString((*it)->getName());
PyList_SetItem(pyList, i++, str);
}
return pyList;
}
PyObject* Application::sDoCommand(PyObject * /*self*/, PyObject *args, PyObject * /*kwd*/)
{
char *sCmd=0;