> I hope you know what you are doing making a Frame a modal! 
Hopefully I will soon. 
>> The question is how do I then wait for the frame to be closed
>> so I can call f.MakeModal(False) after the frame has been
>> closed?
>>
>> The frame is created using a Frame subclass provided by an
>> imported module, so is it kosher for the importing module to
>> bind something to the frame's EVT_CLOSE event?
>
> I think this is kosher. If the frame isn't already created you
> could import the class, subclass, and just define an __init__
> which calls the supers init and binds to a handler which you
> also add to your subclass.
Good point -- I hadn't thought of that approach. What happens
if the superclass also binds an EVT_CLOSE handler?
> Otherwise I think you are fine binding to the already-created
> frame's EVT_CLOSE.
That appears to be quite a bit simpler, but I'm not sure
exactly what is going to happen if the imported frame class
already has an EVT_CLOSE handler. When I tried it, my "extra"
EVT_CLOSE handler that is bound by the imporing module gets
called first, but I can't find any documentation staing that
ordering is guaranteed.
Event handlers are called in reverse order of binding. It gets a
little more complicated with
the way it walks up through superclasses and then parent windows. I
think theres an document in the wxwidgets docs explaining it in some
detail.
If the imported frame's handler gets
called first (and it doesn't call evt.Skip()), then my handler
won't get called, and the application is dead in the water.
But the same could happen when subclassing, so I guess either
method has the same problem.
You don't have to subclass for this. Trivial sample code attached:
import wx
class BaseFrame(wx.Frame):
def __init__(self, parent):
wx.Frame.__init__(self, parent)
self.Bind(wx.EVT_CLOSE, self.OnClose)
def OnClose(self, evt):
print "base class OnClose called"
evt.Skip()
def main():
app = wx.App(False)
g = wx.Frame(None)
g.Show()
f = BaseFrame(g)
def MyOnClose(evt):
print "My onclose called"
f.MakeModal(False)
evt.Skip()
f.Bind(wx.EVT_CLOSE, MyOnClose)
f.MakeModal()
f.Show()
app.MainLoop()
if __name__ == '__main__':
main()
···
On 4/27/07, Grant Edwards <grante@visi.com> wrote:
On 2007-04-27, Mike Rooney <mxr@qvii.com> wrote: