Possible to auto resize Frame holding Notebook based on Page/Tab content?

Hi All,

More in my semi-occasional series of questions on wxPython. :slight_smile:

Please assume I'm a newbie and give as much detail as you can.

Windows XP
wxPython2.8-win32-unicode-2.8.10.1-py25
Python 2.5.4

As I mentioned in an earlier thread, one of the things I'd like to be
able to do is construct a Notebook with Tabs that will automagically
resize the Frame to fit the content on that Panel/Tab. My
understanding is that the sizers that control a Notebook's layout look
at all of the content in the Notebook and adjust the size based on the
largest Panel rather than doing it on a per-Panel (aka per-Tab) basis.
That certainly seems to be the way it acts.

Please find attached a wxGlade mockup of what I'm talking about, built
with wxGlade in Stani's SPE 0.8.4.d. It's a Notebook with 3 Tabs.
Rather than the way it acts at present, I would like it to act as
indicated in the 3 attached .jpegs (GladePlay_2-Tab1.jpg,
GladePlay_2-Tab2.jpg, GladePlay_2-Tab3.jpg) - I want the Frame to
automatically resize to the best size of the selected Tab. (I
constructed the .jpgs by manually resizing the Frame when the program
was running.) If that's not possible, I would like to manually tell
the Frame how big to be for each Tab.

I assume that on selecting a Tab and getting a
EVT_NOTEBOOK_PAGE_CHANGED event, I would have to somehow get the
BestSize of the selected Tab/Panel, and somehow send that size to the
Parent Frame and tell it to Resize. Unfortunately, I don't know how
to do that and haven't been able to find a similar example.

Is this a solvable problem? If so, can someone fill me in on the
missing steps? If not, should I be using a different Notebook instead
to get the functionality I want? Is this an application where Sizers
are not an appropriate solution?

Any pointers would be greatly appreciated. Thanks very much.

Cheers,
Scott.

GladePlay_2.zip (88.5 KB)

Hello,

Hi All,

I assume that on selecting a Tab and getting a
EVT_NOTEBOOK_PAGE_CHANGED event, I would have to somehow get the
BestSize of the selected Tab/Panel, and somehow send that size to the
Parent Frame and tell it to Resize. Unfortunately, I don't know how
to do that and haven't been able to find a similar example.

Is this a solvable problem? If so, can someone fill me in on the
missing steps? If not, should I be using a different Notebook instead
to get the functionality I want? Is this an application where Sizers
are not an appropriate solution?

Note, I did not look at your sample be cause there was just way too
much stuff there. But I do something similar to this in Editra's
preference dialog.

In your EVT_NOTEBOOK_PAGE_CHANGED handler you should be able to do
something like the following:

page = self.GetSelection(self.GetSelection()) # Get the current page
page.SetInitialSize() # This will set the pages 'BestSize'
frame = page.GetTopLevelParent()
frame.SetClientSize(page.GetSize())
frame.SendSizeEvent()

Also note that if you have a Toolbar in the frame you may have to do
some additional calculations to account for it when resizing the frame
window.

Cody

路路路

On Mon, Feb 15, 2010 at 2:44 PM, grunculus <grunculus@gmail.com> wrote:

Hi Cody and All,

Hello,

Note, I did not look at your sample be cause there was just way too
much stuff there.

I'm sorry about that. I tried to keep it simple but real-world enough
so that I could see how to extend it. wxGlade does create rather
opaque code using the default labels, etc. :-/ The code itself is
only one screen here; most of the space in the .Zip file is bitmaps.
Thanks for taking the time in spite of that.

But I do something similar to this in Editra's
preference dialog.

In your EVT_NOTEBOOK_PAGE_CHANGED handler you should be able to do
something like the following:

page = self.GetSelection(self.GetSelection()) # Get the current page
page.SetInitialSize() # This will set the pages 'BestSize'
frame = page.GetTopLevelParent()
frame.SetClientSize(page.GetSize())
frame.SendSizeEvent()

Also note that if you have a Toolbar in the frame you may have to do
some additional calculations to account for it when resizing the frame
window.

Excellent. Thanks very much.

I was able to take your pointers and modify them and get the attached
code to work about the way I was hoping. (I wasn't able to just drop
that code in and tweak it, for some reason.) I had to add some
fudge-offsets, and do some non-OO (and non-Pythonic) calculating that
needs to be refactored, but it works and gives me a much better idea
of what's going on.

If you or anyone else has any additional suggestions on how to clean
up the code, I would certainly appreciate it. Thanks again. I
appreciate it.

Cody

Cheers,
Scott.

100215-GladePlay-4.py (4.63 KB)

路路路

On Mon, Feb 15, 2010 at 4:18 PM, Cody Precord <codyprecord@gmail.com> wrote: