[PyQt] How to determine identity of bound PyQt signals
Marius Shekow
marius.shekow at fit.fraunhofer.de
Wed Jul 13 17:33:22 BST 2016
Hi,
I'm trying to extend the functionality of the pytest plugin "pytest-qt" to be able to have pytests that check that some QObject emits a list of signals with optional parameter checking. However, I'm having trouble discerning signals that are given to my wait-method as parameter.
For example, consider this (somewhere a class "SomeQObject" is defined which defines a signal "some_signal" - omitted here for brevity), using PyQt5:
>>> obj = SomeQObject()
>>> obj.some_signal == obj.some_signal
False <- I would have suspected this to be True, but it's False....
>>> id(obj.some_signal) == id(obj.some_signal)
True
Also:
>>> x = obj.some_signal
>>> y = obj.some_signal
>>> x is y
False
>>> x == y
False
>>> id(x) == id(y)
False
Now, suppose I have a method "wait_for_signals(signals: list)", then this method's code won't be able to reliably find out which of the variables inside the list "signals" actually point to the SAME signal. The code would think that in the call wait_for_signals([x, y]) two different signals were provided, which is incorrect. This would break the evaluation logic, which connects to x and y, effectly connecting to ONE signal (obj.some_signal) twice.
My question is: is there a better way for PyQt4 and PyQt5 to find out which variables in the "signals" list correspond to the same signal? So far the only solution that works is:
>>> str(obj.some_signal) == str(obj.some_signal)
True
>>> str(x) == str(y)
True
But I guess that's a very hacky solution!
You can find more information about my issue here: https://github.com/pytest-dev/pytest-qt/issues/118
Cheers!
Marius
More information about the PyQt
mailing list