In other GUI's (Tkinter and Java Swing) there are Notebook classes that
allow pages without a Tab - this is very handy when you want the same screen
real estate to be used for completely different purposes i.e. selection of
different pages can occur through button events, "hot keys" or under
programmatic control such as selection on one page leading to display of
another page etc.
Since wxPython (wxWindows) doesn't seem to allow the creation of such a
Notebook (without Tabs that is), I am trying to simulate the same behaviour
in wxPython by placing a sizer in the main frame and then removing and
adding Panel instances at appropriate times (my understanding and reading of
the sizer commands implies this is possible?).
My problem seems to be that the wxSizer.Remove method doesn't/isn't actually
"removing" a Panel instance from the display even though it is obviously
being removed from the sizer (subsequent .Remove calls "fails" - indicating
that the sizer nolonger "contains" the Panel instance). This results in both
Panels (the "removed" Panel instance and the "added" Panel instance) both
being displayed in the main frame at the same time.
The code I am using (snippet only) to switch the Panels looks like this:
def OnClick(self, event):
....
# If Panel_1 is displayed then remove it and replace with Panel_2
if self.mainsizer.Remove(self.Panel_1):
self.mainsizer.Add(self.Panel_2, 1, wx.EXPAND, 0)
elif self.mainsizer.Remove(self.Panel_2):
# Otherwise remove Panel_2 and replace with Panel_1
self.mainsizer.Add(self.Panel_1, 1, wx.EXPAND, 0)
else:
print "There is something wrong!"
# update the layout "on screen" after removing the childfrom the sizer
self.mainsizer.Layout()
I have tried various combinations of placing the .Layout() command after
.Remove's but to no avail.
It is very obvious from my debugging that the Panel instance is in fact
being removed from the sizer (well, that is what I believe :-))- but it is
not being deleted/removed from the display when I invoke "refresh" commands
on the sizer and the Frame that contains the sizer. So when the second Panel
is "switched in" they are both in evidence on the main Frame - controls such
as buttons, are "active" on both Panel instances are visible and active.
I have tried various methods on the main Frame to get it to "update" (and
hopefully remove the "removed" panel instance) but I can't quite get it i.e.
I have tried .Layout, .Update, .Refresh and even a .Show(0)/.Show(1)
combination but the display always seems to have the two Panels on display.
Has anyone done something like this? What is it that I am missing? Is there
an alternative way of achieving my objective? Is this somehow a "bug" of
wxPython?
Thanks
Peter
Peter Milliken
Software Engineer
ResMed
Phone: +61 2 9886-5059
Fax: +61 2 9878-5564
Warning: Copyright ResMed. Where the contents of this email and/or attachment includes materials prepared by ResMed, the use of those materials is subject exclusively to the conditions of engagement between ResMed and the intended recipient.
This communication is confidential and may contain legally privileged information. By the use of email over the Internet or other communication systems, ResMed is not waiving either confidentiality of, or legal privilege in,the content of the email and of any attachments.
If the recipient of this message is not the intended addressee, please call ResMed immediately on +61 2 9886 5000 Sydney, Australia.