reverse event handling?

Eric Ongerth ericongerth at gmail.com
Fri Jun 1 14:02:44 PDT 2007


Hello,
I've had good luck so far with the wxWidgets/wxPython event handling
framework.  Most of the time I'm using it as intended and it's really
helpful compared to what I remember dealing with in Motiv during my previous
run at GUI programming circa 1992.  Custom events and their binding have
been working just fine and doing what I intend.

In my current project, however, I need to send some command events in
reverse.  In other words I want a certain type of custom event to travel
down the containment hierarchy rather than upward.  Is there already a
built-in ability to do this that I'm missing?  Have others worked out a
general way to do this?

In a way, one might think that asking for reverse event handling might
perhaps be a sign of poor program organization or bad code factoring.  I've
definitely been examining that possibility, but my application is looking
pretty clean from that perspective up until now.

Let's say I have windows A, B, and C, with children A1, A2, and A3; B1..B3,
etc..  Let's say each of these children have children A1a, A1b, A1c; B1a,
B1b, B1c... etc.

Now some of these children happen to generate database inserts and, as a
result of these inserts, some of the text fields (and, as it happens,
TextCtrlAutoComplete controls) in children *on another branch of this
hierarchy* need to re-query the database in order to present themselves in
accordance with the UI i'm trying to present.

To be even more explicit, let's say window B1c inserts data into a database
table, and window A1a happens to depend on that table and is supposed to
update its view whenever that table changes.  So I can make B1c send a
table-changed event, and that travels upward to B1, then assuming B1 skips
it onward, it travels upward to B.  But A and its children will never see
that event since they're downward in another branch of the containment
hierarchy.

The way I'm handling this so far is that I do use a normal
upward-propagating event to signal all the way up to A that one of its
children changed a table (and event.GetValue() returns which table has
changed, etc).  Then I have a method on A that tells A1..A3 what's
happening, and they each have methods that tell their own children, and so
on.  Fortunately they are all instances of the same window subclass, so at
least the code is reused and I didn't have to copy that "tell the kids what
I just heard" method in multiple places.

So I feel my current approach is messy, error-prone, and it's not "real"
signaling.  I wish to straighten this out, and I suspect several persistent
bugs in my updating and viewing code will thereafter become much easier to
locate and fix.  If there were an established way to propagate events
downward, then rather than have A start telling its children to tell their
children to...etc... I would just have A, upon receiving the upward-bound
event from one of its branches, sent it downward along its other branches.
Problem (potentially) solved, if that could be done.

Any advice greatly appreciated.
- Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/200706=
01/d9b9a4fe/attachment.htm


More information about the wxpython-users mailing list