GUI: Add Python interface to create custom command
This commit is contained in:
@@ -321,6 +321,69 @@ PyObject* CommandPy::getAction(PyObject *args)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PyObject* CommandPy::createCustomCommand(PyObject* args)
|
||||
{
|
||||
const char* macroFile = nullptr;
|
||||
const char* menuTxt = nullptr;
|
||||
const char* tooltipTxt = nullptr;
|
||||
const char* whatsthisTxt = nullptr;
|
||||
const char* statustipTxt = nullptr;
|
||||
const char* pixmapTxt = nullptr;
|
||||
const char* shortcutTxt = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "s|zzzzzz", ¯oFile, &menuTxt, &tooltipTxt, &whatsthisTxt, &statustipTxt, &pixmapTxt, &shortcutTxt))
|
||||
return nullptr;
|
||||
|
||||
auto name = Application::Instance->commandManager().newMacroName();
|
||||
CommandManager& commandManager = Application::Instance->commandManager();
|
||||
MacroCommand* macro = new MacroCommand(name.c_str(), false);
|
||||
commandManager.addCommand(macro);
|
||||
|
||||
macro->setScriptName(macroFile);
|
||||
|
||||
if (menuTxt)
|
||||
macro->setMenuText(menuTxt);
|
||||
|
||||
if (tooltipTxt)
|
||||
macro->setToolTipText(tooltipTxt);
|
||||
|
||||
if (whatsthisTxt)
|
||||
macro->setWhatsThis(whatsthisTxt);
|
||||
|
||||
if (statustipTxt)
|
||||
macro->setStatusTip(statustipTxt);
|
||||
|
||||
if (pixmapTxt)
|
||||
macro->setPixmap(pixmapTxt);
|
||||
|
||||
if (shortcutTxt)
|
||||
macro->setAccel(shortcutTxt);
|
||||
|
||||
return PyUnicode_FromString(name.c_str());
|
||||
}
|
||||
|
||||
PyObject* CommandPy::removeCustomCommand(PyObject* args)
|
||||
{
|
||||
const char* actionName = nullptr;
|
||||
if (!PyArg_ParseTuple(args, "s", &actionName))
|
||||
return nullptr;
|
||||
|
||||
CommandManager& commandManager = Application::Instance->commandManager();
|
||||
std::vector<Command*> macros = commandManager.getGroupCommands("Macros");
|
||||
|
||||
auto action = std::find_if(macros.begin(), macros.end(), [actionName](const Command* c) {
|
||||
return std::string(c->getName()) == std::string(actionName);
|
||||
});
|
||||
|
||||
if (action != macros.end()) {
|
||||
commandManager.removeCommand(*action);
|
||||
return Py::new_reference_to(Py::Boolean(true));
|
||||
}
|
||||
else {
|
||||
return Py::new_reference_to(Py::Boolean(false));
|
||||
}
|
||||
}
|
||||
|
||||
PyObject *CommandPy::getCustomAttributes(const char* /*attr*/) const
|
||||
{
|
||||
return 0;
|
||||
@@ -330,3 +393,4 @@ int CommandPy::setCustomAttributes(const char* /*attr*/, PyObject* /*obj*/)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user