Gui: Fix comparison of argument of clicked() with StandardButton

Fixes #14639: Comparison between integers and StandardButton fails for Python task dialogs with PySide6
This commit is contained in:
wmayer
2024-06-13 15:44:18 +02:00
committed by Chris Hennes
parent 2b52bed558
commit 32830c0680
3 changed files with 23 additions and 1 deletions

View File

@@ -619,6 +619,25 @@ qsizetype PythonWrapper::toEnum(const Py::Object& pyobject)
return toEnum(pyobject.ptr());
}
Py::Object PythonWrapper::tryToStandardButton(qsizetype value)
{
std::stringstream cmd;
cmd << "from PySide import QtWidgets\n";
cmd << "btn = QtWidgets.QDialogButtonBox.StandardButton(" << value << ")";
return Py::asObject(Base::Interpreter().getValue(cmd.str().c_str(), "btn"));
}
Py::Object PythonWrapper::toStandardButton(qsizetype value)
{
try {
return tryToStandardButton(value);
}
catch (Py::Exception& e) {
e.clear();
return Py::Long(value);
}
}
QGraphicsItem* PythonWrapper::toQGraphicsItem(PyObject* pyPtr)
{
return qt_getCppType<QGraphicsItem>(pyPtr);

View File

@@ -56,6 +56,7 @@ public:
QObject* toQObject(const Py::Object&);
qsizetype toEnum(PyObject* pyPtr);
qsizetype toEnum(const Py::Object& pyobject);
Py::Object toStandardButton(qsizetype);
QGraphicsItem* toQGraphicsItem(PyObject* ptr);
QGraphicsItem* toQGraphicsItem(const Py::Object& pyObject);
QGraphicsObject* toQGraphicsObject(PyObject* pyPtr);
@@ -82,6 +83,7 @@ public:
private:
qsizetype tryEnum(PyObject* pyPtr);
Py::Object tryToStandardButton(qsizetype value);
};
} // namespace Gui

View File

@@ -641,8 +641,9 @@ void TaskDialogPython::clicked(int i)
try {
if (dlg.hasAttr(std::string("clicked"))) {
Py::Callable method(dlg.getAttr(std::string("clicked")));
PythonWrapper wrap;
Py::Tuple args(1);
args.setItem(0, Py::Int(i));
args.setItem(0, wrap.toStandardButton(i));
method.apply(args);
}
}