[wxPython-users] Parent catching child's event

Christopher Barker Chris.Barker at noaa.gov
Fri Jul 20 15:16:56 PDT 2007


Ryan Krauss wrote:
> I think this should be easy, but I am not making it work correctly.
> In the same application I mentioned a few minutes ago, I need to have
> my main frame respond to a button event on a child panel.  I also need
> the child panel to handle the event first.  The child's event handles
> includes Skip(), but the event is not being picked up by the parent.

You may need a Skip() in the parent too. It depends which one gets bound =

first.

> The line to bind the event in the parent's __init__ method is:
> =

> self.Bind(wx.EVT_BUTTON, self.OnMainDirChange, =

> self.MainDirChooser.BrowseButton)

Which could be:
self.MainDirChooser.BrowseButton.Bind(wx.EVT_BUTTON, self.OnMainDirChange)

Which I think is a bit cleaner,b ut it should do the same thing.

However, this code violates the Law of Demeter:

"http://www.ccs.neu.edu/home/lieber/LoD.html"

i.e. now the Frame needs to know that the MainDirChooser Panel has an =

attribute named BrowseButton that is a wx.Button.

Style aside, what you describe works for me. See enclosed sample.

-Chris



-- =

Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R            (206) 526-6959   voice
7600 Sand Point Way NE   (206) 526-6329   fax
Seattle, WA  98115       (206) 526-6317   main reception

Chris.Barker at noaa.gov
-------------- next part --------------
A non-text attachment was scrubbed...
Name: junk.py
Type: text/x-python
Size: 805 bytes
Desc: not available
Url : http://lists.wxwidgets.org/pipermail/wxpython-users/attachments/20070=
720/c12d7617/junk.py


More information about the wxpython-users mailing list