[wxPython-users] Re: Wait for frame to be closed?
Mike Rooney
mxr at qvii.com
Fri Apr 27 07:27:10 PDT 2007
Grant Edwards wrote:
> On 2007-04-27, Mike Rooney <mxr at qvii.com> wrote:
>
>
>> 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?
>
>
This is the approach I prefer. It is more reusable then and easier to
change. Plus it is very clear as to what is going on when you look at it.
Since you are subclassing, I think it is okay to "know" about the
superclasses behavior. What I would do here is override the EVT_CLOSE
handler and call the superclass's one from yours before or after
depending on what is appropriate; this way you get a guaranteed order.
So if the superclass binds EVT_CLOSE to self.OnClose, all you do is
subclass and create your own OnClose, calling superclass.OnClose(self,
event) where appropriate. If you do this, you won't even need to
override the __init__ since you won't need to change the binding. This
is a pretty elegant solution, I think.
- Mike Rooney
More information about the wxpython-users
mailing list