From d6c8d6c62c3163734bc08c5d3fa4a835568ba517 Mon Sep 17 00:00:00 2001 From: Yorik van Havre Date: Wed, 27 Apr 2016 22:42:22 -0300 Subject: [PATCH] added FreeCADGui.listCommands() method --- src/Gui/Application.h | 1 + src/Gui/ApplicationPy.cpp | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/Gui/Application.h b/src/Gui/Application.h index d5d8e71ee..3dec079a5 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -222,6 +222,7 @@ public: PYFUNCDEF_S(sRunCommand); PYFUNCDEF_S(sAddCommand); + PYFUNCDEF_S(sListCommands); PYFUNCDEF_S(sHide); // deprecated PYFUNCDEF_S(sShow); // deprecated diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index 1e3833fd5..be69ecdf7 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -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 cmds = Application::Instance->commandManager().getAllCommands(); + PyObject* pyList = PyList_New(cmds.size()); + int i=0; + for ( std::vector::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;