forcing a sizer to resize

The code below is from a PythonCard app, which is why it references
self.components, but this problem will apply to any wxPython app. I've got a
wxFrame that contains a single wxPanel and on that panel are a wxButton
(comp.btnRun) and a custom control based on a wxWindow (comp.bufOff). When
the app opens, it runs the initSizers method below and the window looks
fine. What I would like to do is be able to manually change the size of
comp.bufOff in response to certain user actions and have the window resize
appropriately.

I've been able to do that with simpler windows using SetClientSize, but the
extra control (btnRun) or the status bar or menu or something is throwing
off the calculation. Or perhaps I'm simply calling the wrong method(s). I've
tried various combinations of Fit() and Layout()... but can't seem to get
the window to resize correctly.

Anyway, what is the general way of setting the new size of a control sitting
on a panel within a frame and then fitting the the frame (window) to the new
minimum best size?

Perhaps the complication is that comp.bufOff is set to wxEXPAND and so it is
getting fit to the window rather than having the window fit to its new size
when I try to resize it manually?

ka

···

---

    def initSizers(self):
        sizer1 = wx.wxBoxSizer(wx.wxVERTICAL)
        comp = self.components
        flags = wx.wxLEFT | wx.wxRIGHT | wx.wxBOTTOM | wx.wxALIGN_BOTTOM
        sizer1.Add(comp.btnRun, 0, flags, 5)
        sizer1.Add(comp.bufOff, 1, wx.wxEXPAND)

        sizer1.Fit(self)
        sizer1.SetSizeHints(self)
        self.sizer = sizer1
        self.panel.SetSizer(sizer1)
        self.panel.SetAutoLayout(1)
        self.panel.Layout()

Kevin Altis wrote:

I've got a
wxFrame that contains a single wxPanel and on that panel are a wxButton
(comp.btnRun) and a custom control based on a wxWindow (comp.bufOff). When
the app opens, it runs the initSizers method below and the window looks
fine. What I would like to do is be able to manually change the size of
comp.bufOff in response to certain user actions and have the window resize
appropriately.

If you mean the wxFrame to re-size, then what you are looking for is:

wxFrame.Fit()

Perhaps the complication is that comp.bufOff is set to wxEXPAND and so it is
getting fit to the window rather than having the window fit to its new size
when I try to resize it manually?

It's possible, the world of sizers is pretty complicated, but I think if
you call Fit() on the Frame it should do it.

    def initSizers(self):
        sizer1 = wx.wxBoxSizer(wx.wxVERTICAL)
        comp = self.components
        flags = wx.wxLEFT | wx.wxRIGHT | wx.wxBOTTOM | wx.wxALIGN_BOTTOM
        sizer1.Add(comp.btnRun, 0, flags, 5)
        sizer1.Add(comp.bufOff, 1, wx.wxEXPAND)

        sizer1.Fit(self)
        sizer1.SetSizeHints(self)
        self.sizer = sizer1
        self.panel.SetSizer(sizer1)
        self.panel.SetAutoLayout(1)
        self.panel.Layout()

What is self in this example? if it is the wxFrame, I think you want
self.Fit(). See this note form the Wiki:

3.Often sizer.Fit(frame) is NOT what you want. It will use the minimum
size of all the contained windows and sub-sizers and resize the frame so
it just
     barely fits those minimums.

Hmm. this implies that your sizer1.fit(self) call should have done it.
If you still havn't got it, post a complete small app, and I'll try
again.

-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

Thanks Chris. The problem is not with the initSizers method but rather
trying to manually resize bufOff manually later in the program. After some
more experimenting I found that I could do:

    self.sizer.SetItemMinSize(self.components.bufOff, 400, 600)
    self.sizer.SetSizeHints(self)

self is the wxFrame. That seems to force the resize correctly. The downside
is that it also sets the minimum size. Pondering the docs I don't see a
SetItemSize with a follow-up method to resize the whole window to the new
size, but I'm still hoping there is a way. Since sizers are really designed
around fitting the minimum size of the items contained within them this
might be the best I can do.

ka

···

-----Original Message-----
From: cbarker [mailto:cbarker]On Behalf Of Chris Barker
Sent: Friday, December 06, 2002 1:14 PM
To: wxPython-users@lists.wxwindows.org
Subject: Re: [wxPython-users] forcing a sizer to resize

Kevin Altis wrote:

> I've got a
> wxFrame that contains a single wxPanel and on that panel are a wxButton
> (comp.btnRun) and a custom control based on a wxWindow
(comp.bufOff). When
> the app opens, it runs the initSizers method below and the window looks
> fine. What I would like to do is be able to manually change the size of
> comp.bufOff in response to certain user actions and have the
window resize
> appropriately.

If you mean the wxFrame to re-size, then what you are looking for is:

wxFrame.Fit()

> Perhaps the complication is that comp.bufOff is set to wxEXPAND
and so it is
> getting fit to the window rather than having the window fit to
its new size
> when I try to resize it manually?

It's possible, the world of sizers is pretty complicated, but I think if
you call Fit() on the Frame it should do it.

> def initSizers(self):
> sizer1 = wx.wxBoxSizer(wx.wxVERTICAL)
> comp = self.components
> flags = wx.wxLEFT | wx.wxRIGHT | wx.wxBOTTOM | wx.wxALIGN_BOTTOM
> sizer1.Add(comp.btnRun, 0, flags, 5)
> sizer1.Add(comp.bufOff, 1, wx.wxEXPAND)
>
> sizer1.Fit(self)
> sizer1.SetSizeHints(self)
> self.sizer = sizer1
> self.panel.SetSizer(sizer1)
> self.panel.SetAutoLayout(1)
> self.panel.Layout()

What is self in this example? if it is the wxFrame, I think you want
self.Fit(). See this note form the Wiki:

3.Often sizer.Fit(frame) is NOT what you want. It will use the minimum
size of all the contained windows and sub-sizers and resize the frame so
it just
     barely fits those minimums.

Hmm. this implies that your sizer1.fit(self) call should have done it.
If you still havn't got it, post a complete small app, and I'll try
again.

-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