[wxPython-users] Re: custom events vs call backs

Robin Dunn robin at alldunn.com
Mon Nov 27 10:28:34 PST 2006


Donn Ingle wrote:
>> Another practical reason is that with CommandEvents (and if you call
>> event.Skip() properly), multiple recipients can be set up for your
>> event, whereas with the callback approach managing that would get clumsy.
> Yeah, I can just about picture that! 
> My controls really only need to tell their parent something, I haven't hit a
> need for an event that keeps on going, so perhaps I should lean towards
> callbacks.

If you ever foresee the need for decoupled lateral notification 
(assuming that child-to-parent is vertical) then you may want to 
consider using wx.lib.pubsub or one of the similar modules available 
such as pydispatcher.  They let you send messages from any part of your 
app and allow any other part of the app to register for, or subscribe to 
that message.  This lets the sender be totally unaware of the receiver, 
or even whether or not there is a receiver (or receivers) of the 
message.  If you start with this model now then if/when the need for 
more complete decoupling comes up in your app then it will be painless 
to do it.

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





More information about the wxpython-users mailing list