diff options
author | Renato Filho <renato.filho@openbossa.org> | 2011-08-26 15:38:23 -0300 |
---|---|---|
committer | Hugo Parente Lima <hugo.pl@gmail.com> | 2012-03-08 16:54:47 -0300 |
commit | d5b645d3ab8faa5aa5887e7fecf370f7ef322bba (patch) | |
tree | dd0f50bf04f0dc9345da32a75b97a2f5dc1ecb66 /libpyside/globalreceiverv2.cpp | |
parent | 65d4cf2be4bf6071b03c9ae34368d9cffda597e5 (diff) |
Created utility function to call a python method usign args received in
qt_metacall.
Reviewed by: Hugo Parente <hugo.lima@openbossa.org>
Luciano Wolf <luciano.wolf@openbossa.org>
Diffstat (limited to 'libpyside/globalreceiverv2.cpp')
-rw-r--r-- | libpyside/globalreceiverv2.cpp | 36 |
1 files changed, 8 insertions, 28 deletions
diff --git a/libpyside/globalreceiverv2.cpp b/libpyside/globalreceiverv2.cpp index c31a9d2f6..748332f96 100644 --- a/libpyside/globalreceiverv2.cpp +++ b/libpyside/globalreceiverv2.cpp @@ -52,7 +52,7 @@ class DynamicSlotDataV2 int addSlot(const char* signature); int id(const char* signature) const; - PyObject* call(PyObject* args); + PyObject* callback(); QByteArray hash() const; void notify(); @@ -115,20 +115,17 @@ QByteArray DynamicSlotDataV2::hash(PyObject* callback) return QByteArray::number((qlonglong)PyObject_Hash(callback)); } -PyObject* DynamicSlotDataV2::call(PyObject* args) +PyObject* DynamicSlotDataV2::callback() { PyObject* callback = m_callback; //create a callback based on method data if (m_isMethod) callback = PyMethod_New(m_callback, m_pythonSelf, m_pyClass); + else + Py_INCREF(callback); - PyObject* result = PyObject_CallObject(callback, args); - - if (m_isMethod) - Py_DECREF(callback); - - return result; + return callback; } int DynamicSlotDataV2::id(const char* signature) const @@ -282,26 +279,9 @@ int GlobalReceiverV2::qt_metacall(QMetaObject::Call call, int id, void** args) m_refs.removeAll(obj); // remove all refs to this object decRef(); //remove the safe ref } else { - Shiboken::GilState gil; - PyObject* retval = 0; - - bool isShortCurt = (strstr(slot.signature(), "(") == 0); - if (isShortCurt) { - retval = m_data->call(reinterpret_cast<PyObject*>(args[1])); - } else { - QList<QByteArray> paramTypes = slot.parameterTypes(); - Shiboken::AutoDecRef preparedArgs(PyTuple_New(paramTypes.count())); - for (int i = 0, max = paramTypes.count(); i < max; ++i) { - PyObject* arg = Shiboken::TypeResolver::get(paramTypes[i].constData())->toPython(args[i+1]); // Do not increment the reference - PyTuple_SET_ITEM(preparedArgs.object(), i, arg); - } - retval = m_data->call(preparedArgs); - } - - if (!retval) - PyErr_Print(); - else - Py_DECREF(retval); + bool isShortCuit = (strstr(slot.signature(), "(") == 0); + Shiboken::AutoDecRef callback(m_data->callback()); + SignalManager::callPythonMetaMethod(slot, args, callback, isShortCuit); } return -1; |