wxEvtHandler headache...

Hello NG,

    I am subclassing wx.EvtHandler to handle some events, and surely I
am doing something wrong. This is what I do:

class MyEvtHandler(wx.EvtHandler):

    def __init__(self, myInput):

        self._myInput = myInput

        wx.EvtHandler.__init__(self)

        self.Bind(wx.EVT_SCROLL, self.ProcessEvent)
        self.Bind(wx.EVT_PAINT, self.ProcessEvent)
        self.Bind(wx.EVT_SIZE, self.ProcessEvent)
        self.Bind(wx.EVT_MOUSEWHEEL, self.ProcessEvent)
        self.Bind(wx.EVT_CHAR, self.ProcessEvent)
        self.Bind(wx.EVT_ENTER_WINDOW, self.ProcessEvent)
        self.Bind(wx.EVT_LEAVE_WINDOW, self.ProcessEvent)

    def ProcessEvent(self, event):

        evType = event.GetEventType()

        # pass it on to the real handler
        processed = wx.EvtHandler.ProcessEvent(self, event)

This last line is there because I would like to know if some other
class has overridden that particular event (returning processed =
True) or not.
Well, as soon as this last line is executed, I get a bunch of:

"RuntimeError: maximum recursion depth exceeded"

Uhm... Does anyone know what I may be doing wrong?

Thank you for every pointer...

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/

Andrea Gavana wrote:

Hello NG,

   I am subclassing wx.EvtHandler to handle some events, and surely I
am doing something wrong. This is what I do:

class MyEvtHandler(wx.EvtHandler):

   def __init__(self, myInput):

       self._myInput = myInput

       wx.EvtHandler.__init__(self)

       self.Bind(wx.EVT_SCROLL, self.ProcessEvent)
       self.Bind(wx.EVT_PAINT, self.ProcessEvent)
       self.Bind(wx.EVT_SIZE, self.ProcessEvent)
       self.Bind(wx.EVT_MOUSEWHEEL, self.ProcessEvent)
       self.Bind(wx.EVT_CHAR, self.ProcessEvent)
       self.Bind(wx.EVT_ENTER_WINDOW, self.ProcessEvent)
       self.Bind(wx.EVT_LEAVE_WINDOW, self.ProcessEvent)

   def ProcessEvent(self, event):

       evType = event.GetEventType()

       # pass it on to the real handler
       processed = wx.EvtHandler.ProcessEvent(self, event)

This last line is there because I would like to know if some other
class has overridden that particular event (returning processed =
True) or not.
Well, as soon as this last line is executed, I get a bunch of:

"RuntimeError: maximum recursion depth exceeded"

Uhm... Does anyone know what I may be doing wrong?

Your event handlers are bound to ProcessEvent, so when the event happens it will be called. Then you call the base class ProcessEvent, which looks for an event binding and if one is found (it will be) it calls the handler (which is this ProcessEvent again.)

So basically you want to have it *not* look in this evthandler for a binding when you call ProcessEvent. Assuming you are pushing instances of these onto window objects, you can probably do it something like getting the next handler in the chain (GetNextHandler) and then calling its ProcessEvent.

···

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

Your event handlers are bound to ProcessEvent, so when the event happens
it will be called. Then you call the base class ProcessEvent, which
looks for an event binding and if one is found (it will be) it calls the
handler (which is this ProcessEvent again.)

So basically you want to have it *not* look in this evthandler for a
binding when you call ProcessEvent. Assuming you are pushing instances
of these onto window objects, you can probably do it something like
getting the next handler in the chain (GetNextHandler) and then calling
its ProcessEvent.

Thanks Robin, at the end I found the problem and hopefully corrected it :wink:

Andrea.

"Imagination Is The Only Weapon In The War Against Reality."
http://xoomer.virgilio.it/infinity77/