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:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user