From f956a00baaf3ba556bbb18ae777d23e81fc6c42e Mon Sep 17 00:00:00 2001 From: mwganson Date: Wed, 8 Apr 2020 10:23:29 -0500 Subject: [PATCH] add getCommandInfo() rename getShortcut to getCommandShortcut --- src/Gui/Application.h | 3 +- src/Gui/ApplicationPy.cpp | 60 +++++++++++++++++++++++++++++++++++---- 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/src/Gui/Application.h b/src/Gui/Application.h index 36de3b5b4e..8925f29ee6 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -258,8 +258,9 @@ public: static PyObject* sRunCommand (PyObject *self,PyObject *args); static PyObject* sAddCommand (PyObject *self,PyObject *args); + static PyObject* sGetCommandInfo (PyObject *self,PyObject *args); static PyObject* sListCommands (PyObject *self,PyObject *args); - static PyObject* sGetShortcut (PyObject *self,PyObject *args); + static PyObject* sGetCommandShortcut (PyObject *self,PyObject *args); static PyObject* sIsCommandActive (PyObject *self,PyObject *args); static PyObject* sUpdateCommands (PyObject *self,PyObject *args); diff --git a/src/Gui/ApplicationPy.cpp b/src/Gui/ApplicationPy.cpp index d040510160..894f76ff58 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -144,9 +144,12 @@ PyMethodDef Application::Methods[] = { {"listCommands", (PyCFunction) Application::sListCommands, METH_VARARGS, "listCommands() -> list of strings\n\n" "Returns a list of all commands known to FreeCAD."}, - {"getShortcut", (PyCFunction) Application::sGetShortcut, METH_VARARGS, - "getShortcut(string) -> string\n\n" - "Returns shortcut string representing shortcut key accelerator for command."}, + {"getCommandInfo", (PyCFunction) Application::sGetCommandInfo, METH_VARARGS, + "getCommandInfo(string) -> list of strings\n\n" + "Usage: menuText,tooltipText,whatsThisText,statustipText,pixmapText,shortcutText = getCommandInfo(string)"}, + {"getCommandShortcut", (PyCFunction) Application::sGetCommandShortcut, METH_VARARGS, + "getCommandShortcut(string) -> string\n\n" + "Returns string representing shortcut key accelerator for command."}, {"updateCommands", (PyCFunction) Application::sUpdateCommands, METH_VARARGS, "updateCommands\n\n" "Update all command active status"}, @@ -1276,7 +1279,7 @@ PyObject* Application::sUpdateCommands(PyObject * /*self*/, PyObject *args) Py_Return; } -PyObject* Application::sGetShortcut(PyObject * /*self*/, PyObject *args) +PyObject* Application::sGetCommandShortcut(PyObject * /*self*/, PyObject *args) { char* pName; if (!PyArg_ParseTuple(args, "s", &pName)) @@ -1286,9 +1289,9 @@ PyObject* Application::sGetShortcut(PyObject * /*self*/, PyObject *args) if (cmd) { #if PY_MAJOR_VERSION >= 3 - PyObject* str = PyUnicode_FromString(cmd->getAccel()); + PyObject* str = PyUnicode_FromString(cmd->getAccel() ? cmd->getAccel() : ""); #else - PyObject* str = PyString_FromString(cmd->getAccel()); + PyObject* str = PyString_FromString(cmd->getAccel() ? cmd->getAccel() : ""); #endif return str; } @@ -1298,6 +1301,51 @@ PyObject* Application::sGetShortcut(PyObject * /*self*/, PyObject *args) } } +PyObject* Application::sGetCommandInfo(PyObject * /*self*/, PyObject *args) +{ + char* pName; + if (!PyArg_ParseTuple(args, "s", &pName)) + return NULL; + + Command* cmd = Application::Instance->commandManager().getCommandByName(pName); + if (cmd) { + PyObject* pyList = PyList_New(6); + const char* menuTxt = cmd->getMenuText(); + const char* tooltipTxt = cmd->getToolTipText(); + const char* whatsThisTxt = cmd->getWhatsThis(); + const char* statustipTxt = cmd->getStatusTip(); + const char* pixMapTxt = cmd->getPixmap(); + const char* shortcutTxt = cmd->getAccel(); + +#if PY_MAJOR_VERSION >= 3 + PyObject* strMenuTxt = PyUnicode_FromString(menuTxt ? menuTxt : ""); + PyObject* strTooltipTxt = PyUnicode_FromString(tooltipTxt ? tooltipTxt : ""); + PyObject* strWhatsThisTxt = PyUnicode_FromString(whatsThisTxt ? whatsThisTxt : ""); + PyObject* strStatustipTxt = PyUnicode_FromString(statustipTxt ? statustipTxt : ""); + PyObject* strPixMapTxt = PyUnicode_FromString(pixMapTxt ? pixMapTxt : ""); + PyObject* strShortcutTxt = PyUnicode_FromString(shortcutTxt ? shortcutTxt : ""); +#else + PyObject* strMenuTxt = PyString_FromString(menuTxt ? menuTxt : ""); + PyObject* strTooltipTxt = PyString_FromString(tooltipTxt ? tooltipTxt : ""); + PyObject* strWhatsThisTxt = PyString_FromString(whatsThisTxt ? whatsThisTxt : ""); + PyObject* strStatustipTxt = PyString_FromString(statustipTxt ? statustipTxt : ""); + PyObject* strPixMapTxt = PyString_FromString(pixMapTxt ? pixMapTxt : ""); + PyObject* strShortcutTxt = PyString_FromString(shortcutTxt ? shortcutTxt : ""); +#endif + PyList_SetItem(pyList, 0, strMenuTxt); + PyList_SetItem(pyList, 1, strTooltipTxt); + PyList_SetItem(pyList, 2, strWhatsThisTxt); + PyList_SetItem(pyList, 3, strStatustipTxt); + PyList_SetItem(pyList, 4, strPixMapTxt); + PyList_SetItem(pyList, 5, strShortcutTxt); + return pyList; + } + else { + PyErr_Format(Base::BaseExceptionFreeCADError, "No such command '%s'", pName); + return 0; + } +} + PyObject* Application::sListCommands(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, ""))