diff options
| author | Christian Tismer <tismer@stackless.com> | 2022-11-09 14:21:05 +0100 |
|---|---|---|
| committer | Christian Tismer <tismer@stackless.com> | 2022-11-11 15:52:57 +0100 |
| commit | 1e47cdbd77ed2c95f520aaa8b856bb05f4076a89 (patch) | |
| tree | 6410ac89322bc12e5b9b2390da2cd0c0c36b63ac /sources/pyside6/libpyside/pysidesignal.cpp | |
| parent | 4ac568f20ed5821e34f3c98b7eeea1077f560f6b (diff) | |
signals: Increase compatibility by providing a signatures attribute
[ChangeLog][PySide6] A `signatures` attribute was added to the Signal
type in order to increase compatibility with other implementations.
Task-number: PYSIDE-1113
Change-Id: I7b97e38feaff5a0db8a82a26f52fb6ecadab08d2
Pick-to: 6.4
Fixes: PYSIDE-1713
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
Diffstat (limited to 'sources/pyside6/libpyside/pysidesignal.cpp')
| -rw-r--r-- | sources/pyside6/libpyside/pysidesignal.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/sources/pyside6/libpyside/pysidesignal.cpp b/sources/pyside6/libpyside/pysidesignal.cpp index f87b86a61..d7d38d081 100644 --- a/sources/pyside6/libpyside/pysidesignal.cpp +++ b/sources/pyside6/libpyside/pysidesignal.cpp @@ -106,6 +106,7 @@ static int signalTpInit(PyObject *, PyObject *, PyObject *); static void signalFree(void *); static void signalInstanceFree(void *); static PyObject *signalGetItem(PyObject *self, PyObject *key); +static PyObject *signalGetAttr(PyObject *self, PyObject *name); static PyObject *signalToString(PyObject *self); static PyObject *signalDescrGet(PyObject *self, PyObject *obj, PyObject *type); @@ -153,6 +154,7 @@ static PyTypeObject *PySideMetaSignal_TypeF(void) static PyType_Slot PySideSignalType_slots[] = { {Py_mp_subscript, reinterpret_cast<void *>(signalGetItem)}, + {Py_tp_getattro, reinterpret_cast<void *>(signalGetAttr)}, {Py_tp_descr_get, reinterpret_cast<void *>(signalDescrGet)}, {Py_tp_call, reinterpret_cast<void *>(signalCall)}, {Py_tp_str, reinterpret_cast<void *>(signalToString)}, @@ -301,12 +303,30 @@ static PyObject *signalGetItem(PyObject *obSelf, PyObject *key) return Shiboken::String::fromCString(sig.constData()); } - static PyObject *signalToString(PyObject *self) { return signalGetItem(self, nullptr); } +static PyObject *signalGetAttr(PyObject *obSelf, PyObject *name) +{ + auto self = reinterpret_cast<PySideSignal *>(obSelf); + + if (PyUnicode_CompareWithASCIIString(name, "signatures") != 0) + return PyObject_GenericGetAttr(obSelf, name); + + auto nelems = self->data->signatures.count(); + PyObject *tuple = PyTuple_New(nelems); + + for (Py_ssize_t idx = 0; idx < nelems; ++idx) { + QByteArray sigKey = self->data->signatures.at(idx).signature; + auto sig = PySide::Signal::buildSignature(self->data->signalName, sigKey); + PyObject *entry = Shiboken::String::fromCString(sig.constData()); + PyTuple_SetItem(tuple, idx, entry); + } + return tuple; +} + static void signalInstanceFree(void *vself) { auto pySelf = reinterpret_cast<PyObject *>(vself); |
