All: Reformat according to new standard

This commit is contained in:
pre-commit-ci[bot]
2025-11-11 13:49:01 +01:00
committed by Kacper Donat
parent eafd18dac0
commit 25c3ba7338
2390 changed files with 154630 additions and 115818 deletions

View File

@@ -20,9 +20,9 @@
* *
***************************************************************************/
# include <sstream>
# include <QRegularExpression>
# include <QRegularExpressionMatch>
#include <sstream>
#include <QRegularExpression>
#include <QRegularExpressionMatch>
#include <Base/PyWrapParseTupleAndKeywords.h>
@@ -46,11 +46,12 @@ std::string CommandPy::representation() const
return {"<Command object>"};
}
PyObject* CommandPy::get(PyObject *args)
PyObject* CommandPy::get(PyObject* args)
{
char* pName;
if (!PyArg_ParseTuple(args, "s", &pName))
if (!PyArg_ParseTuple(args, "s", &pName)) {
return nullptr;
}
Command* cmd = Application::Instance->commandManager().getCommandByName(pName);
if (cmd) {
@@ -61,64 +62,70 @@ PyObject* CommandPy::get(PyObject *args)
Py_Return;
}
PyObject* CommandPy::update(PyObject *args)
PyObject* CommandPy::update(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
getMainWindow()->updateActions();
Py_Return;
}
PyObject* CommandPy::listAll(PyObject *args)
PyObject* CommandPy::listAll(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
std::vector <Command*> cmds = Application::Instance->commandManager().getAllCommands();
std::vector<Command*> cmds = Application::Instance->commandManager().getAllCommands();
PyObject* pyList = PyList_New(cmds.size());
int i=0;
for (const auto & cmd : cmds) {
int i = 0;
for (const auto& cmd : cmds) {
PyObject* str = PyUnicode_FromString(cmd->getName());
PyList_SetItem(pyList, i++, str);
}
return pyList;
}
PyObject* CommandPy::listByShortcut(PyObject *args)
PyObject* CommandPy::listByShortcut(PyObject* args)
{
char* shortcut_to_find;
PyObject* bIsRegularExp = Py_False;
if (!PyArg_ParseTuple(args, "s|O!", &shortcut_to_find, &PyBool_Type, &bIsRegularExp))
if (!PyArg_ParseTuple(args, "s|O!", &shortcut_to_find, &PyBool_Type, &bIsRegularExp)) {
return nullptr;
}
std::vector <Command*> cmds = Application::Instance->commandManager().getAllCommands();
std::vector <std::string> matches;
std::vector<Command*> cmds = Application::Instance->commandManager().getAllCommands();
std::vector<std::string> matches;
for (Command* c : cmds) {
Action* action = c->getAction();
if (action) {
QString spc = QStringLiteral(" ");
if (Base::asBoolean(bIsRegularExp)) {
QRegularExpression re(QString::fromLatin1(shortcut_to_find), QRegularExpression::CaseInsensitiveOption);
if (!re.isValid()) {
std::stringstream str;
str << "Invalid regular expression:" << ' ' << shortcut_to_find;
throw Py::RuntimeError(str.str());
}
QRegularExpression re(
QString::fromLatin1(shortcut_to_find),
QRegularExpression::CaseInsensitiveOption
);
if (!re.isValid()) {
std::stringstream str;
str << "Invalid regular expression:" << ' ' << shortcut_to_find;
throw Py::RuntimeError(str.str());
}
if (re.match(action->shortcut().toString().remove(spc).toUpper()).hasMatch()) {
matches.emplace_back(c->getName());
}
if (re.match(action->shortcut().toString().remove(spc).toUpper()).hasMatch()) {
matches.emplace_back(c->getName());
}
}
else if (action->shortcut().toString().remove(spc).toUpper() ==
QString::fromLatin1(shortcut_to_find).remove(spc).toUpper()) {
else if (action->shortcut().toString().remove(spc).toUpper()
== QString::fromLatin1(shortcut_to_find).remove(spc).toUpper()) {
matches.emplace_back(c->getName());
}
}
}
PyObject* pyList = PyList_New(matches.size());
int i=0;
int i = 0;
for (const std::string& match : matches) {
PyObject* str = PyUnicode_FromString(match.c_str());
PyList_SetItem(pyList, i++, str);
@@ -126,11 +133,12 @@ PyObject* CommandPy::listByShortcut(PyObject *args)
return pyList;
}
PyObject* CommandPy::run(PyObject *args)
PyObject* CommandPy::run(PyObject* args)
{
int item = 0;
if (!PyArg_ParseTuple(args, "|i", &item))
if (!PyArg_ParseTuple(args, "|i", &item)) {
return nullptr;
}
Gui::Command::LogDisabler d1;
Gui::SelectionLogDisabler d2;
@@ -146,14 +154,16 @@ PyObject* CommandPy::run(PyObject *args)
}
}
PyObject* CommandPy::isActive(PyObject *args) const
PyObject* CommandPy::isActive(PyObject* args) const
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Command* cmd = this->getCommandPtr();
if (cmd) {
PY_TRY {
PY_TRY
{
return Py::new_reference_to(Py::Boolean(cmd->isActive()));
}
PY_CATCH;
@@ -164,14 +174,17 @@ PyObject* CommandPy::isActive(PyObject *args) const
}
}
PyObject* CommandPy::getShortcut(PyObject *args)
PyObject* CommandPy::getShortcut(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Command* cmd = this->getCommandPtr();
if (cmd) {
PyObject* str = PyUnicode_FromString(cmd->getAction() ? cmd->getAction()->shortcut().toString().toStdString().c_str() : "");
PyObject* str = PyUnicode_FromString(
cmd->getAction() ? cmd->getAction()->shortcut().toString().toStdString().c_str() : ""
);
return str;
}
else {
@@ -180,11 +193,12 @@ PyObject* CommandPy::getShortcut(PyObject *args)
}
}
PyObject* CommandPy::setShortcut(PyObject *args)
PyObject* CommandPy::setShortcut(PyObject* args)
{
char* pShortcut;
if (!PyArg_ParseTuple(args, "s", &pShortcut))
if (!PyArg_ParseTuple(args, "s", &pShortcut)) {
return nullptr;
}
Command* cmd = this->getCommandPtr();
if (cmd) {
@@ -197,26 +211,29 @@ PyObject* CommandPy::setShortcut(PyObject *args)
}
}
PyObject* CommandPy::resetShortcut(PyObject *args)
PyObject* CommandPy::resetShortcut(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Command* cmd = this->getCommandPtr();
if (cmd) {
ShortcutManager::instance()->reset(cmd->getName());
return Py::new_reference_to(Py::Boolean(true));
} else {
}
else {
PyErr_Format(Base::PyExc_FC_GeneralError, "No such command");
return nullptr;
}
}
PyObject* CommandPy::getInfo(PyObject *args)
PyObject* CommandPy::getInfo(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Command* cmd = this->getCommandPtr();
if (cmd) {
@@ -229,8 +246,9 @@ PyObject* CommandPy::getInfo(PyObject *args)
const char* statustipTxt = cmd->getStatusTip();
const char* pixMapTxt = cmd->getPixmap();
std::string shortcutTxt;
if (action)
if (action) {
shortcutTxt = action->shortcut().toString().toStdString();
}
PyObject* strCmdName = PyUnicode_FromString(cmdName);
PyObject* strMenuTxt = PyUnicode_FromString(menuTxt ? menuTxt : "");
@@ -238,7 +256,9 @@ PyObject* CommandPy::getInfo(PyObject *args)
PyObject* strWhatsThisTxt = PyUnicode_FromString(whatsThisTxt ? whatsThisTxt : "");
PyObject* strStatustipTxt = PyUnicode_FromString(statustipTxt ? statustipTxt : "");
PyObject* strPixMapTxt = PyUnicode_FromString(pixMapTxt ? pixMapTxt : "");
PyObject* strShortcutTxt = PyUnicode_FromString(!shortcutTxt.empty() ? shortcutTxt.c_str() : "");
PyObject* strShortcutTxt = PyUnicode_FromString(
!shortcutTxt.empty() ? shortcutTxt.c_str() : ""
);
PyDict_SetItemString(pyDict, "name", strCmdName);
PyDict_SetItemString(pyDict, "menuText", strMenuTxt);
PyDict_SetItemString(pyDict, "toolTip", strTooltipTxt);
@@ -254,10 +274,11 @@ PyObject* CommandPy::getInfo(PyObject *args)
}
}
PyObject* CommandPy::getAction(PyObject *args)
PyObject* CommandPy::getAction(PyObject* args)
{
if (!PyArg_ParseTuple(args, ""))
if (!PyArg_ParseTuple(args, "")) {
return nullptr;
}
Command* cmd = this->getCommandPtr();
if (cmd) {
@@ -270,8 +291,9 @@ PyObject* CommandPy::getAction(PyObject *args)
Py::List list;
if (group) {
const auto actions = group->actions();
for (auto a : actions)
for (auto a : actions) {
list.append(wrap.fromQAction(a));
}
}
else if (action) {
list.append(wrap.fromQAction(action->action()));
@@ -295,10 +317,29 @@ PyObject* CommandPy::createCustomCommand(PyObject* args, PyObject* kw)
const char* statustipTxt = nullptr;
const char* pixmapTxt = nullptr;
const char* shortcutTxt = nullptr;
static std::array<const char *, 8> kwlist {"macroFile", "menuText", "toolTip", "whatsThis",
"statusTip", "pixmap", "shortcut", nullptr};
if (!Base::Wrapped_ParseTupleAndKeywords(args, kw, "s|zzzzzz", kwlist, &macroFile, &menuTxt,
&tooltipTxt, &whatsthisTxt, &statustipTxt, &pixmapTxt, &shortcutTxt)) {
static std::array<const char*, 8> kwlist {
"macroFile",
"menuText",
"toolTip",
"whatsThis",
"statusTip",
"pixmap",
"shortcut",
nullptr
};
if (!Base::Wrapped_ParseTupleAndKeywords(
args,
kw,
"s|zzzzzz",
kwlist,
&macroFile,
&menuTxt,
&tooltipTxt,
&whatsthisTxt,
&statustipTxt,
&pixmapTxt,
&shortcutTxt
)) {
return nullptr;
}
@@ -309,23 +350,29 @@ PyObject* CommandPy::createCustomCommand(PyObject* args, PyObject* kw)
macro->setScriptName(macroFile);
if (menuTxt)
if (menuTxt) {
macro->setMenuText(menuTxt);
}
if (tooltipTxt)
if (tooltipTxt) {
macro->setToolTipText(tooltipTxt);
}
if (whatsthisTxt)
if (whatsthisTxt) {
macro->setWhatsThis(whatsthisTxt);
}
if (statustipTxt)
if (statustipTxt) {
macro->setStatusTip(statustipTxt);
}
if (pixmapTxt)
if (pixmapTxt) {
macro->setPixmap(pixmapTxt);
}
if (shortcutTxt)
if (shortcutTxt) {
macro->setAccel(shortcutTxt);
}
return PyUnicode_FromString(name.c_str());
}
@@ -333,8 +380,9 @@ PyObject* CommandPy::createCustomCommand(PyObject* args, PyObject* kw)
PyObject* CommandPy::removeCustomCommand(PyObject* args)
{
const char* actionName = nullptr;
if (!PyArg_ParseTuple(args, "s", &actionName))
if (!PyArg_ParseTuple(args, "s", &actionName)) {
return nullptr;
}
CommandManager& commandManager = Application::Instance->commandManager();
std::vector<Command*> macros = commandManager.getGroupCommands("Macros");
@@ -355,26 +403,31 @@ PyObject* CommandPy::removeCustomCommand(PyObject* args)
PyObject* CommandPy::findCustomCommand(PyObject* args)
{
const char* macroScriptName = nullptr;
if (!PyArg_ParseTuple(args, "s", &macroScriptName))
if (!PyArg_ParseTuple(args, "s", &macroScriptName)) {
return nullptr;
}
CommandManager& commandManager = Application::Instance->commandManager();
std::vector<Command*> macros = commandManager.getGroupCommands("Macros");
auto action = std::find_if(macros.begin(), macros.end(), [macroScriptName](const Command* c) {
if (auto mc = dynamic_cast<const MacroCommand*>(c))
if (std::string(mc->getScriptName()) == std::string(macroScriptName))
if (auto mc = dynamic_cast<const MacroCommand*>(c)) {
if (std::string(mc->getScriptName()) == std::string(macroScriptName)) {
return true;
}
}
return false;
});
});
if (action != macros.end())
if (action != macros.end()) {
return PyUnicode_FromString((*action)->getName());
else
}
else {
Py_Return;
}
}
PyObject *CommandPy::getCustomAttributes(const char* /*attr*/) const
PyObject* CommandPy::getCustomAttributes(const char* /*attr*/) const
{
return nullptr;
}