aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHugo Parente Lima <hugo.lima@openbossa.org>2010-04-08 16:34:52 -0300
committerHugo Parente Lima <hugo.lima@openbossa.org>2010-04-08 17:14:14 -0300
commitf8907f4e4ed306f07c28d285d2d46bd2b43ea19b (patch)
tree530d34003e29a3d21d638ed2bb8118f33499da6f
parentbd8d5dabb334d16ccfdb76fe0fb8d083be2c0219 (diff)
Fix bug#210, "Can't connect generic callable objects as a slot".
Reviewer: Bruno Araújo <bruno.araujo@openbossa.org> Reviewer: Lauro Moura <lauro.neto@openbossa.org>
-rw-r--r--PySide/QtCore/glue/qobject_connect.cpp5
-rw-r--r--libpyside/signalmanager.cpp2
-rw-r--r--tests/signals/signal_emission_test.py15
3 files changed, 19 insertions, 3 deletions
diff --git a/PySide/QtCore/glue/qobject_connect.cpp b/PySide/QtCore/glue/qobject_connect.cpp
index 16842a0a3..deeaa6a56 100644
--- a/PySide/QtCore/glue/qobject_connect.cpp
+++ b/PySide/QtCore/glue/qobject_connect.cpp
@@ -8,11 +8,10 @@ static bool getReceiver(PyObject *callback, QObject **receiver, PyObject **self)
*self = PyCFunction_GET_SELF(callback);
if (*self && SbkQObject_Check(*self))
*receiver = Converter<QObject*>::toCpp(*self);
- } else if (!PyFunction_Check(callback)) {
+ } else if (PyCallable_Check(callback)) {
+ // Ok, just a callable object
*receiver = 0;
*self = 0;
- qWarning() << "Invalid callback object.";
- return false;
}
bool usingGlobalReceiver = !*receiver;
diff --git a/libpyside/signalmanager.cpp b/libpyside/signalmanager.cpp
index c2ece922d..4884b4912 100644
--- a/libpyside/signalmanager.cpp
+++ b/libpyside/signalmanager.cpp
@@ -102,6 +102,8 @@ QString PySide::getCallbackSignature(const char* signal, PyObject* callback, boo
numArgs = -1;
else if (flags & METH_NOARGS)
numArgs = 0;
+ } else if (PyCallable_Check(callback)) {
+ functionName = "__callback"+QString::number((size_t)callback);
}
Q_ASSERT(!functionName.isEmpty());
diff --git a/tests/signals/signal_emission_test.py b/tests/signals/signal_emission_test.py
index 4fcdbe1e4..5692b073c 100644
--- a/tests/signals/signal_emission_test.py
+++ b/tests/signals/signal_emission_test.py
@@ -4,6 +4,7 @@
import sys
import unittest
+import functools
from PySide.QtCore import QObject, SIGNAL, SLOT, QProcess, QTimeLine
@@ -86,6 +87,20 @@ class CppSignalsToCppSlots(UsesQCoreApplication):
else:
self.assertEqual(new_dir, QTimeLine.Forward)
+called = False
+def someSlot(args=None):
+ global called
+ called = True
+
+class DynamicSignalsToFuncPartial(UsesQCoreApplication):
+
+ def testIt(self):
+ global called
+ called = False
+ o = QObject()
+ o.connect(o, SIGNAL("ASignal"), functools.partial(someSlot, "partial .."))
+ o.emit(SIGNAL("ASignal"))
+ self.assertTrue(called)
if __name__ == '__main__':
unittest.main()