[PyQt] Multiple inheritance

Florian Bruhin me at the-compiler.org
Thu Aug 7 10:04:59 BST 2014


Hi,

I'm trying to create a subclass of Python's
code.InteractiveInterpreter[1] which emits a pyqtSignal instead of
printing to sys.stderr to output lines. This can be done by overriding
its write method. However I also have to inherit QObject, so I tried
using multiple inheritance.

In this approach, even though I did override write(), output still
gets to sys.stderr:

########
class ConsoleInteractiveInterpreter(InteractiveInterpreter, QObject):

    write_output = pyqtSignal(str)

    def __init__(self, parent=None):
        QObject.__init__(self, parent)
        InteractiveInterpreter.__init__(self)

    def write(self, data):
        self.write_output.emit(data)
########

Example:

########
>>> inter = ConsoleInteractiveInterpreter()
>>> _ = inter.runsource("1+1")
2
########

Why is that? Did I understand something wrong?

Thanks,

Florian

[1] https://docs.python.org/3/library/code.html#interactive-interpreter-objects

-- 
http://www.the-compiler.org | me at the-compiler.org (Mail/XMPP)
             GPG 0xFD55A072 | http://the-compiler.org/pubkey.asc
         I love long mails! | http://email.is-not-s.ms/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 819 bytes
Desc: not available
URL: <http://www.riverbankcomputing.com/pipermail/pyqt/attachments/20140807/a64eef65/attachment.sig>


More information about the PyQt mailing list