wxPython class(es) and super

Hi list,
after some tries, I see that the wxPython classes don't call its parents
(or child?) with the standard inheritance method (super). Is there a
solution for this or this is an "internal" wxWidgets/wxPython problem?

Little code:

class myClass(object):
  def __init__(self, *args, *kw):
   print "ok, init myClass done"

class myPanel(wx.Panel):
  def __init__(self, *args, *kw):
   super(myPanel, self).__init__(*args, *kw)
   print "ok, init myPanel done"

class last(myPanel, myClass ):
  def __init__(self, *args, *kw):
   super(last, self).__init__(*args, *kw)

f = last()

"ok, init myPanel done"

but not "ok, init myClass done"

Thanks,
Michele

Call the super class __init__ directly:

class myPanel(wx.Panel):
  def __init__(self, *args, *kw):
    wx.Panel.__init__(self, *args, *kw)
    print "ok, init myPanel done"

Michele Petrazzo schreef:

Hi list,
after some tries, I see that the wxPython classes don't call its parents
(or child?) with the standard inheritance method (super). Is there a
solution for this or this is an "internal" wxWidgets/wxPython problem?

wxPython classes are not 'cooperative', as it is called. In addition to Keith's suggestion (calling Superclass.__init__ explicitly) you can also reorder the base classes so that your own classes' methods are invoked first, like this:

import wx

class myClass(object):
     def __init__(self, *args, **kw):
         super(myClass, self).__init__(*args, **kw)
         print "ok, init myClass done"

class myFrame(wx.Frame):
     def __init__(self, *args, **kw):
         super(myFrame, self).__init__(*args, **kw)
         print "ok, init myFrame done"

class last(myClass, myFrame):
     def __init__(self, *args, **kw):
         super(last, self).__init__(*args, **kw)

app = wx.App(0)
last(None)

Cheers, Frank

Michele Petrazzo wrote:

Hi list,
after some tries, I see that the wxPython classes don't call its parents
(or child?) with the standard inheritance method (super).

Because they invoke the C++ class constructor that knows nothing about the Python classes. The Python proxy class hierarchy is pretty much a mirror of the C++ hierarchy, but the real instances and the real hierarchy is still on the C++ side.

Is there a
solution for this or this is an "internal" wxWidgets/wxPython problem?

Little code:

class myClass(object):
def __init__(self, *args, *kw):
  print "ok, init myClass done"

class myPanel(wx.Panel):
def __init__(self, *args, *kw):
  super(myPanel, self).__init__(*args, *kw)
  print "ok, init myPanel done"

class last(myPanel, myClass ):
def __init__(self, *args, *kw):
  super(last, self).__init__(*args, *kw)

Just do it the non-super() way.

  myPanel.__init__(self, *args, *kw)
  myClass.__init__(self, *args, *kw)

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!

Frank Niessink wrote:

Michele Petrazzo schreef:

Hi list, after some tries, I see that the wxPython classes don't
call its parents (or child?) with the standard inheritance method
(super). Is there a solution for this or this is an "internal"
wxWidgets/wxPython problem?

wxPython classes are not 'cooperative', as it is called. In addition
to Keith's suggestion (calling Superclass.__init__ explicitly) you
can also reorder the base classes so that your own classes' methods
are invoked first, like this:

Yes, I think that this is the better solution.

Thanks,
Michele