diff --git a/traitsui/wx/toolkit.py b/traitsui/wx/toolkit.py index 2645fb197..69f42c460 100644 --- a/traitsui/wx/toolkit.py +++ b/traitsui/wx/toolkit.py @@ -461,6 +461,7 @@ def skip_event ( self, event ): def destroy_control ( self, control ): """ Destroys a specified GUI toolkit control. """ + _popEventHandlers(control) control.Destroy() #--------------------------------------------------------------------------- @@ -471,6 +472,8 @@ def destroy_children ( self, control ): """ Destroys all of the child controls of a specified GUI toolkit control. """ + for child in control.GetChildren(): + _popEventHandlers(child) control.DestroyChildren() #--------------------------------------------------------------------------- @@ -776,3 +779,13 @@ def _get_tab_hover_edge_bitmap ( self ): return image.create_image().ConvertToBitmap() + +#------------------------------------------------------------------------------- +def _popEventHandlers(ctrl): + """ Pop any event handlers that have been pushed on to a window and its + children. + """ + while ctrl is not ctrl.GetEventHandler(): + ctrl.PopEventHandler(True) + for child in ctrl.GetChildren(): + _popEventHandlers(child)