Dear,
While working on a larger program, I got somewhat lost in the way events are propagated up the chain.
My use case is the following: in a wx.Frame that represents a document, there is a wx.MenuItem (say, wx.ID_ABOUT), that should not be handled by the document Frame, but rather by its parent Frame (the app main window, if you want). But, for the main Frame, I wanted to use a separate controller object (a wx.EvtHandler subclass) to contain some generic logic, like showing the AboutBox, and add that with wx.Window.PushEventHander. The solution I put together crashes if the controller object tries to handle the menu event, but it works is if the event is handled by the main window.
Suspecting there is something wrong with my understanding of PushEventHandler, I looked into the example on the wiki, and modified it a bit, see attached. And then I got completely lost.
When you run this with line 31 in place, I expect to see first a dialog “in EvtHandler” and then one “in Panel”. But the first one is showing twice, and I don’t see why.
Then, I get an error on closing the app:
python3 test_pusheventhandler.py
test_pusheventhandler.py:12: DeprecationWarning: NewId() is deprecated
ID_FOR_THE_BTN = wx.NewId()
Mouse down at (51, 16) on Button
Button clicked in EvtHandler
Button clicked in EvtHandler
Button clicked in Panel
Traceback (most recent call last):
File “test_pusheventhandler.py”, line 70, in
app.MainLoop()
File “/usr/local/lib/python3.7/site-packages/wx/core.py”, line 2134, in MainLoop
rv = wx.PyApp.MainLoop(self)
wx._core.wxAssertionError: C++ assertion “GetEventHandler() == this” failed at /Users/robind/projects/buildbots/macosx-vm6/dist-osx-py37/Phoenix/ext/wxWidgets/src/common/wincmn.cpp(478) in ~wxWindowBase(): any pushed event handlers must have been removed
Any help with either would be appreciated.
Best regards,
Jan
test_pusheventhandler.py (1.87 KB)