added FreeCADGui.listCommands() method

This commit is contained in:
Yorik van Havre
2016-04-27 22:42:22 -03:00
parent bb800e768d
commit e70f6e8a10
2 changed files with 19 additions and 0 deletions

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;