|check if a child frame exists?||Che M||7/9/09 11:07 PM|
I have a main frame that can launch another frame, its child.
I don't want to launch a second instance of it if it has already
been launched, so I need to know if it already exists.
So, what's the best way to check to see if a child exists?
I would think I would use .GetChildren(), but I am not sure
how to do something like
children = mainframe.GetChildren()
if childframe in children:
pass #don't launch it again.
because I don't know how to match the childframe to
the list returned from GetChildren().
|Re: [wxPython-users] check if a child frame exists?||Cody Precord||7/10/09 4:34 AM|
The above code will work fine if the 'childframe' variable is an
2) Another way is if the child frame is a unique subclass that will
3) And another way would be to make the child frame class a singleton
4) Yet another way is to keep reference to the instance of the child
|Re: [wxPython-users] check if a child frame exists?||Ross||7/10/09 7:56 AM|
There's also the hasattr() function that I've recently learned about
thru this forum if you create the child frame with a specific name
self.new_child = MyChildFrameClass(frame)
I'd think you could simply test to see if you've created that yet:
if hasattr(self, "new_child")
... or something along those lines. Don't quote me on my syntax as
I'm a novice but I've been using 'hasattr' successfully in such
|Re: check if a child frame exists?||Hong Yuan||7/9/09 11:28 PM|
You can put any attribute on your child frame as you like to
distinguish them from each other. For example if you app opens
multiple documents, each in a child frame. Then simply put a filename
attribute on the frame. And if the same file is to be open again,
iterate through your child frames and see if any frame with the same
name is already there.
In a word, how to identify and keep track of the child frames is your
application's work, not the work of the wx framework.
|Re: [wxPython-users] Re: check if a child frame exists?||Che M||7/10/09 5:41 PM|
Thank you, Cody, for all those suggestions! Very helpful!
|Re: [wxPython-users] Re: check if a child frame exists?||Che M||7/10/09 5:42 PM|
That does seem simpler than I'd thought, thank you!
|Re: [wxPython-users] Re: check if a child frame exists?||Che M||7/10/09 5:43 PM|
On Fri, Jul 10, 2009 at 10:56 AM, Ross <ros...@gmail.com> wrote:
Yes, I had wondered if hasattr would help here, but I had not yet used
it; it will work for any objects then, I guess. Good idea. Thanks.