Using isinstance() on wxPython objects

Hi all. I'm trying to find out if an object is a descendant of wxControl by
the following:

  if isinstance(obj, wxControl):

However, it always returns 0. I suspect this has something to do with
the proxy-object stuff that is happening at the Python layer. Anyone
know a way to make this type of check work?

···

-------------------------------------------------------------------------------------
Jeff Kotula Systems Architecture Manager
Vital Images jkotula@vitalimages.com

Renunciation is not giving up the things of this world,
but accepting that they go away.
    -- Suzuki Roshi

I want to be able to catch motion events in a parent component - specifically I'm containing a StaticBitmap in a Panel, which adds more functionality. I thought I could do this:

class StaticBitmap(wxStaticBitmap):
    def __init__(self, parent, id, bitmap, origin, size):
        wxStaticBitmap.__init__(self, parent, id, bitmap, origin, size)

    def ProcessEvent(event):
        print 'pe'
        return self.GetParent().ProcessEvent(event)

...but the overwritten ProcessEvent is never called. Any ideas, or other ways to accomplish this?

Thanks!
Robb

Jeff Kotula wrote:

Hi all. I'm trying to find out if an object is a descendant of wxControl by
the following:

  if isinstance(obj, wxControl):

However, it always returns 0. I suspect this has something to do with
the proxy-object stuff that is happening at the Python layer. Anyone
know a way to make this type of check work?

Look at the class definitions and you'll see that the shadow classes for the controls derive from the wxControlPtr shadow class, not wxControl. (It's just the this version of SWIG works...)

···

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

Robb Shecter wrote:

I want to be able to catch motion events in a parent component - specifically I'm containing a StaticBitmap in a Panel, which adds more functionality. I thought I could do this:

class StaticBitmap(wxStaticBitmap):
   def __init__(self, parent, id, bitmap, origin, size):
       wxStaticBitmap.__init__(self, parent, id, bitmap, origin, size)

   def ProcessEvent(event):
       print 'pe'
       return self.GetParent().ProcessEvent(event)

...but the overwritten ProcessEvent is never called.

http://wiki.wxpython.org/index.cgi/OverloadingMethods

Any ideas, or other ways to accomplish this?

You'll need to catch the events you are interested in using the normal EVT_ mechanism and then you can pass them on to the parent if that's what you need to do. Also, you should do it like this:

  self.GetParent().GetEventHandler().ProcessEvent(event)

in case the parent has had a new wxEvtHandler pushed on to it.

···

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