diff --git a/src/Gui/Application.h b/src/Gui/Application.h index df5df231c8..36de3b5b4e 100644 --- a/src/Gui/Application.h +++ b/src/Gui/Application.h @@ -259,6 +259,7 @@ public: static PyObject* sRunCommand (PyObject *self,PyObject *args); static PyObject* sAddCommand (PyObject *self,PyObject *args); static PyObject* sListCommands (PyObject *self,PyObject *args); + static PyObject* sGetShortcut (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 cf059d2906..d040510160 100644 --- a/src/Gui/ApplicationPy.cpp +++ b/src/Gui/ApplicationPy.cpp @@ -144,6 +144,9 @@ 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."}, {"updateCommands", (PyCFunction) Application::sUpdateCommands, METH_VARARGS, "updateCommands\n\n" "Update all command active status"}, @@ -1273,6 +1276,28 @@ PyObject* Application::sUpdateCommands(PyObject * /*self*/, PyObject *args) Py_Return; } +PyObject* Application::sGetShortcut(PyObject * /*self*/, PyObject *args) +{ + char* pName; + if (!PyArg_ParseTuple(args, "s", &pName)) + return NULL; + + Command* cmd = Application::Instance->commandManager().getCommandByName(pName); + if (cmd) { + +#if PY_MAJOR_VERSION >= 3 + PyObject* str = PyUnicode_FromString(cmd->getAccel()); +#else + PyObject* str = PyString_FromString(cmd->getAccel()); +#endif + return str; + } + else { + PyErr_Format(Base::BaseExceptionFreeCADError, "No such command '%s'", pName); + return 0; + } +} + PyObject* Application::sListCommands(PyObject * /*self*/, PyObject *args) { if (!PyArg_ParseTuple(args, ""))