diff --git a/IPython/frontend/qt/kernelmanager.py b/IPython/frontend/qt/kernelmanager.py index 810fdbc..0962a91 100644 --- a/IPython/frontend/qt/kernelmanager.py +++ b/IPython/frontend/qt/kernelmanager.py @@ -10,7 +10,13 @@ from IPython.zmq.kernelmanager import KernelManager, SubSocketChannel, \ XReqSocketChannel, RepSocketChannel from util import MetaQObjectHasTraits - +# When doing multiple inheritance from QtCore.QObject and other classes +# the calling of the parent __init__'s is a subtle issue: +# * QtCore.QObject does not call super so you can't use super and put +# QObject first in the inheritance list. +# * QtCore.QObject.__init__ takes 1 argument, the parent. So if you are going +# to use super, any class that comes before QObject must pass it something +# reasonable. class QtSubSocketChannel(SubSocketChannel, QtCore.QObject): @@ -76,7 +82,7 @@ class QtXReqSocketChannel(XReqSocketChannel, QtCore.QObject): """ QtCore.QObject.__init__(self) XReqSocketChannel.__init__(self, *args, **kw) - + #--------------------------------------------------------------------------- # 'XReqSocketChannel' interface #--------------------------------------------------------------------------- @@ -106,7 +112,6 @@ class QtRepSocketChannel(RepSocketChannel, QtCore.QObject): QtCore.QObject.__init__(self) RepSocketChannel.__init__(self, *args, **kw) - class QtKernelManager(KernelManager, QtCore.QObject): """ A KernelManager that provides signals and slots. """ @@ -124,6 +129,10 @@ class QtKernelManager(KernelManager, QtCore.QObject): xreq_channel_class = QtXReqSocketChannel rep_channel_class = QtRepSocketChannel + def __init__(self, *args, **kw): + QtCore.QObject.__init__(self) + KernelManager.__init__(self, *args, **kw) + #--------------------------------------------------------------------------- # 'KernelManager' interface #--------------------------------------------------------------------------- diff --git a/IPython/frontend/qt/util.py b/IPython/frontend/qt/util.py index a1dab85..9e283cf 100644 --- a/IPython/frontend/qt/util.py +++ b/IPython/frontend/qt/util.py @@ -11,6 +11,7 @@ from IPython.utils.traitlets import HasTraits MetaHasTraits = type(HasTraits) MetaQObject = type(QtCore.QObject) +# You can switch the order of the parents here. class MetaQObjectHasTraits(MetaQObject, MetaHasTraits): """ A metaclass that inherits from the metaclasses of both HasTraits and QObject. @@ -18,8 +19,9 @@ class MetaQObjectHasTraits(MetaQObject, MetaHasTraits): Using this metaclass allows a class to inherit from both HasTraits and QObject. See QtKernelManager for an example. """ + # pass + # ???You can get rid of this, but only if the order above is MetaQObject, MetaHasTraits + # def __init__(cls, name, bases, dct): + # MetaQObject.__init__(cls, name, bases, dct) + # MetaHasTraits.__init__(cls, name, bases, dct) - def __init__(cls, name, bases, dct): - MetaQObject.__init__(cls, name, bases, dct) - MetaHasTraits.__init__(cls, name, bases, dct) - diff --git a/IPython/zmq/kernelmanager.py b/IPython/zmq/kernelmanager.py index 5d757df..2236118 100644 --- a/IPython/zmq/kernelmanager.py +++ b/IPython/zmq/kernelmanager.py @@ -385,8 +385,9 @@ class KernelManager(HasTraits): self._rep_address = (LOCALHOST, 0) if rep_address is None else rep_address self.context = zmq.Context() if context is None else context self.session = Session() if session is None else session + super(KernelManager, self).__init__() - #-------------------------------------------------------------------------- + #--------------------------------- ----------------------------------------- # Channel management methods: #--------------------------------------------------------------------------