Window shutdown/destruction order

Leo Breebaart wrote:

Hi all,

Despite reading all the relevant on-line material I could find,
as well as diving into the sample code, I still have some
difficulty coming to grips with exactly what happens in what
order in what way when you try to close frames in wxPython 2.4.

My application has one main wx.Frame, from which the user can
start an arbitrary number of other wx.Frame windows (which will
all have the main frame as a parent), each of which will be
running an animation that *has* to be explicitly shut down before
the sub frame should be allowed to destroy itself.

If I install an EVT_CLOSE handler in the animation frame class
and close an animation window by clicking on the system close box
in its titlebar, there's absolutely no problem.

However, if I click on the *main* window's close box (i.e. exit
the entire application), I also need this close handler for all
existing animation frames to be called.

Use a EVT_CLOSE handler on the main frame and from there call Close on each of the child frames.

As far as I can tell, this does not happen automatically, nor
does it work if I override the Close or Destroy methods in the
animation frames.

The C++ Close and Destroy methods are not overridable from Python.

The only way I can make it work is by adding the following to the
close handler of the main frame:

        for i in self.GetChildren():
            if isinstance(i, AnimationFrame):
                i.OnClose(event)

I suppose I have two big questions here. The first is: is this an
acceptable way of achieving what I want, or am I missing a more
idiomatic way, or am I perhaps just making some kind of mistake,
period?

That is fine. It should be equivallent to equivallent to what I said above, just avoiding the event system.

The second question: in the absence of explicit handlers, if you
close a main frame, all its children frames *do* get closed as
well. How is that done? As far as I can tell it's not through a
CloseEvent, not through Close() not through Destroy... -- what
*does* get called in those circumstances to remove a child frame?

The Window's destructor calls DeleteChildren, which loops through all child windows and deletes them immediately. There is no calls to Close nor Destroy because then there woudl be the possibility of cancelling the close or delaying the destroy, and that would then leave those windows parentless when the current window is finished being destructed, which could be a bad thing.

ยทยทยท

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