size matters

I have a fairly straight forward question about adding a wx.flatnotebook and a wx.button to a wx.Panel (and then to the parent wx.Frame). At present all these bits and pieces are working beautifully individually, but when I add them to the panel the sizing is all off. I am basically setting it up as follows:

class ControlFrame( wx.MiniFrame ):
def init( xxxx ):
wx.MiniFrame.init( xxxx, size=(450, 525) )
self.mainPanel = wx.Panel( self, -1 )
self.book = fnb.FlatNotebook(self.mainPanel, wx.ID_ANY, size=(450, 490),style=fnb.FNB_NODRAG|fnb.FNB_VC8|fnb.FNB_NO_NAV_BUTTONS|fnb.FNB_NO_X_BUTTON)
self.button = ( xxxx )

    sizer = wx.BoxSizer(wx.VERTICAL)
    sizer.Add(self.book, 1, wx.EXPAND)
    sizer.Add(self.save_button, 1, wx.EXPAND)
    self.mainPanel.SetSizer(sizer)

…and what I get is a panel split exactly in the middle with a MASSIVE button on the bottom. I just want a little button withe the balance of the space for my notebook. Any advice?

-Andy

···

Andrew Kelly wrote:

class ControlFrame( wx.MiniFrame ):
    def __init__( xxxx ):
        wx.MiniFrame.__init__( xxxx, size=(450, 525) )
        self.mainPanel = wx.Panel( self, -1 )
        self.book = fnb.FlatNotebook(self.mainPanel, wx.ID_ANY, size=(450, 490),style=fnb.FNB_NODRAG|fnb.FNB_VC8|fnb.FNB_NO_NAV_BUTTONS|fnb.FNB_NO_X_BUTTON)
        self.button = ( xxxx )

        sizer = wx.BoxSizer(wx.VERTICAL)
        sizer.Add(self.book, 1, wx.EXPAND)
        sizer.Add(self.save_button, 1, wx.EXPAND)
        self.mainPanel.SetSizer(sizer)

....and what I get is a panel split exactly in the middle with a MASSIVE button on the bottom.

that's because:

> sizer.Add(self.save_button, 1, wx.EXPAND)
the "1" is telling the sizer to stretch the button the same amount as the book.

the wx.EXPAND is telling it to expand the button to fit the width.

Try:

          sizer.Add(self.save_button, 0, wx.ALL, 5)

the wx.ALL and 5 tell it to put a 5 pixel space on all sides. Not required, but it will probably look cramped without that.

HTH,
-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (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

Andrew Kelly wrote:

Works - thank you Chris. I have been using this wx stuff for some time now and the sizers still get me.

They do take a bit of work to wrap your brain around, but I do like them. Have you seen this page:

http://wiki.wxpython.org/UsingSizers

I keep that graphic pinned up above my desk...

-Chris

···

--
Christopher Barker, Ph.D.
Oceanographer

Emergency Response Division
NOAA/NOS/OR&R (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