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>
This commit is contained in:
parent
bd8d5dabb3
commit
f8907f4e4e
3 changed files with 19 additions and 3 deletions
|
|
@ -8,11 +8,10 @@ static bool getReceiver(PyObject *callback, QObject **receiver, PyObject **self)
|
||||||
*self = PyCFunction_GET_SELF(callback);
|
*self = PyCFunction_GET_SELF(callback);
|
||||||
if (*self && SbkQObject_Check(*self))
|
if (*self && SbkQObject_Check(*self))
|
||||||
*receiver = Converter<QObject*>::toCpp(*self);
|
*receiver = Converter<QObject*>::toCpp(*self);
|
||||||
} else if (!PyFunction_Check(callback)) {
|
} else if (PyCallable_Check(callback)) {
|
||||||
|
// Ok, just a callable object
|
||||||
*receiver = 0;
|
*receiver = 0;
|
||||||
*self = 0;
|
*self = 0;
|
||||||
qWarning() << "Invalid callback object.";
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool usingGlobalReceiver = !*receiver;
|
bool usingGlobalReceiver = !*receiver;
|
||||||
|
|
|
||||||
|
|
@ -102,6 +102,8 @@ QString PySide::getCallbackSignature(const char* signal, PyObject* callback, boo
|
||||||
numArgs = -1;
|
numArgs = -1;
|
||||||
else if (flags & METH_NOARGS)
|
else if (flags & METH_NOARGS)
|
||||||
numArgs = 0;
|
numArgs = 0;
|
||||||
|
} else if (PyCallable_Check(callback)) {
|
||||||
|
functionName = "__callback"+QString::number((size_t)callback);
|
||||||
}
|
}
|
||||||
Q_ASSERT(!functionName.isEmpty());
|
Q_ASSERT(!functionName.isEmpty());
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
import unittest
|
import unittest
|
||||||
|
import functools
|
||||||
|
|
||||||
from PySide.QtCore import QObject, SIGNAL, SLOT, QProcess, QTimeLine
|
from PySide.QtCore import QObject, SIGNAL, SLOT, QProcess, QTimeLine
|
||||||
|
|
||||||
|
|
@ -86,6 +87,20 @@ class CppSignalsToCppSlots(UsesQCoreApplication):
|
||||||
else:
|
else:
|
||||||
self.assertEqual(new_dir, QTimeLine.Forward)
|
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__':
|
if __name__ == '__main__':
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue