Sizer.Remove question

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? :slight_smile: 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.

Peter Milliken wrote:

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? :slight_smile: Is this somehow a "bug" of
wxPython?

If you are using wxPython 2.4.1.x, try the sizer's Hide method. If not, I think you have to Hide the window *and* Remove it from the sizer.

David

"David C. Fox" wrote:

Peter Milliken wrote:
> 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?).
>

If you are using wxPython 2.4.1.x, try the sizer's Hide method.

Cool, I havn't tried that yet.

If not,
I think you have to Hide the window *and* Remove it from the sizer.

Yup. you hide it with this call:

MyWindow.Show(False)
MySizer.Remove(MyWindow)

I did exactly this for an app of mine. It's a simpel unit converter.
I've enclosed it for everyones viewing pleasure. I did it because only
GTK support the wxNB_LEFT style well, and that is exactly what I needed.
Take a look at my app, I'm pretty sure it works under Windows, Linux and
OS-X, with the last few released version od wxPython.

The code of interest is in the OnButtonPress method in the
ConverterFrame class.

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

If you are using wxPython 2.4.1.x, try the sizer's Hide method. If not,
I think you have to Hide the window *and* Remove it from the sizer.

David

It should work also for 2.4.0.x, just use Show(..., False) instead.

Alberto

OOPS, I forgot the enclosure...again!

Converter.py (10.8 KB)

···

--
Christopher Barker, Ph.D.
Oceanographer
                                        
NOAA/OR&R/HAZMAT (206) 526-6959 voice
7600 Sand Point Way NE (206) 526-6329 fax
Seattle, WA 98115 (206) 526-6317 main reception

Chris.Barker@noaa.gov

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?).

I believe I have the same situation: a frame can have a variety of panels in
it that are switched by user selections.

I solved it by just hiding and showing the various panels. The frame has a
"thePanel" member set to the current panel that is used to handle all menu
commands. I didn't bother with a sizer because the default frame behavior is
to resize an only child automatically.

I hope this helps.
-Rick King
Southfield MI