Event Handling Order for Multiple Handlers of the Same Event at the Same Event Propagation Level

Usually, the current behaviour is what you want. The subclass does
its custom stuff first, then it lets the base class finish its
processing, and so on until the default processing gets done last.
Will there ever be any actual windows of the base class, or will all
the windows be subclasses? If not, you could change the base
classes event handler to just be a helper function, and have the
subclasses call that instead.
Alternatively, you can have the base class fire a custom event in
its handler, and have the subclasses catch that event instead of
OnKeyText.

···

bejam1n wrote:

    The function "OnKeyText2" gets

executed first, so I figure the behavior for the “event stack”
(Is there a proper terminology for this part of wxPython instead
of “event stack”?) for this control is: Each new handler bound
to the same event at the same level of propagation goes to the
top of the stack (executed first) and not the bottom (executed
second).

    Even though I understand this, it

has become a real pain in my application because I have
subclasses of a class where the base class functions bind some
events, then the subclasses bind their additional events
afterwords.

    I feel like the events get put into

the “event stack” backwards (bind the event you want to have
happen last first). Is there a way to have the events append to the
“event stack” and not be inserted in the beginning?

-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com

Tim:

Essentially I have a bunch of forms that have common headers. Each form is a subclass of a common form/header which never gets used by itself.

My initial philosophy was to always have the base class (panel in this case) build all the common controls(with event bindings)/set all common variables and then have the sub class make it’s addition controls, variables, and in some cases additional event handlers for the common controls. Since I wanted the common controls at the “top” of the panel (location and in tab order) I set it up this way. Other than the event handler order problem, I thought this was an efficient way to do it.

To fix the issue I did something similar to your “helper function” suggestion: I simply created two functions BindCommonControls() and BindSubControls() and I just call them both from the subclass after it has initialized the parent class. Depending on how I call those two functions I can change the order of the events depending on each situation.

Thanks for the help!

Ben

···

On Thursday, August 30, 2012 2:52:23 PM UTC-4, Tim Roberts wrote:

bejam1n wrote:

    The function "OnKeyText2" gets

executed first, so I figure the behavior for the “event stack”
(Is there a proper terminology for this part of wxPython instead
of “event stack”?) for this control is: Each new handler bound
to the same event at the same level of propagation goes to the
top of the stack (executed first) and not the bottom (executed
second).

    Even though I understand this, it

has become a real pain in my application because I have
subclasses of a class where the base class functions bind some
events, then the subclasses bind their additional events
afterwords.

Usually, the current behaviour is what you want.  The subclass does

its custom stuff first, then it lets the base class finish its
processing, and so on until the default processing gets done last.

    I feel like the events get put into

the “event stack” backwards (bind the event you want to have
happen last first). Is there a way to have the events append to the
“event stack” and not be inserted in the beginning?

Will there ever be any actual windows of the base class, or will all

the windows be subclasses? If not, you could change the base
classes event handler to just be a helper function, and have the
subclasses call that instead.

Alternatively, you can have the base class fire a custom event in

its handler, and have the subclasses catch that event instead of
OnKeyText.

-- Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.