[PyQt] Fwd: Mixin classes and PyQt4

Baz Walter bazwal at ftml.net
Sun Feb 16 22:56:23 GMT 2014


On 16/02/14 13:27, Phil Thompson wrote:
> On 13-02-2014 6:54 pm, Martin Teichmann wrote:
>> Hi Baz, Hi Phil, Hi List,
>>
>>> This actually only relates to multiple-inheritance. It should never
>>> be problem for true mixin classes.
>>
>> There youre certainly right. Its calling super() where I have my
>> issues. Your examples did not call super(), so the MRO doesnt
>> matter.
>>
>>
>>> The one genuine issue with mixins in PyQt, is that you cannot
>>> inherit custom signals.
>>
>> Then it might be interesting for you that with my patch applied, it
>> does work. For example:
>>
>>
>> -----------------------------------------------------------------------
>> from PyQt4.QtGui import QWidget, QLabel, QApplication
>>  from PyQt4.QtCore import pyqtSignal, QObject
>>
>> class A(QObject):
>>     a = pyqtSignal(str)
>>
>> class B(A, QLabel):
>>     b = pyqtSignal(str)
>>
>> class Printer(QObject):
>>     def print(self, a):
>>         print(a)
>>
>> app = QApplication([])
>>
>> b = B()
>> p = Printer()
>> b.a.connect(p.print)
>> b.b.connect(p.print)
>> b.a.emit(a)
>> b.b.emit(b)
>> b.setText(foo)
>>
>> ----------------------------------------------------------------------
>>
>> correctly works with my patch applied. It does not if you let A
>> inherit from object.
>
> At the moment (having just started to think about it again) I'm against
> your original patch as it is too different to the C++ behaviour.
>
> However I do like your other patch which raised an exception when
> inheriting from more than one C++ class.

On the face of it, this seems like an entirely good thing to do.

However, I suppose it's only fair to point out that this will probably 
break code for at least some people, if this blog post is anything to go by:

     http://trevorius.com/scrapbook/python/pyqt-multiple-inheritance/

Of course, you could say that they got what they deserved for trying to 
do something in PyQt that just wouldn't be allowed in Qt itself. But 
whatever the rights and wrongs, there are going to be a few people who 
might hope that this patch is only applied if the issue with custom 
signals can be resolved first.

-- 
Regards
Baz Walter


More information about the PyQt mailing list