More direct sizer question

I have a panel with a horizontal boxsizer. I set the dimensions of the sizer to that of the panel. I then add two buttons to the sizer telling them not to grow horizontally or veritcally. I tell them to align in the center of the sizer using
wxALIGN_CENTER. So it looks like this:

X, Y = self.GetSize()

self.bsStaticBox = wxStaticBox(id=wxNewId(),
                                                             label='Port Information:', name='stSpineLBLabel', parent=self, pos=wxPoint(6,
                                                             0), size=wxSize(X, Y), style=0)
sizer = wxStaticBoxSizer(self.bsStaticBox, wxHORIZONTAL)

self.SetAutoLayout(true)
self.SetSizer(sizer)

sizer.SetDimension(0,0,X, Y)

sizer.Add(pButton, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 5)
                    sizer.Layout()

The buttons do center vertically in the sizer but they don't center horizontally. I have tried wxALIGN_CENTER_HORIZONTAL. I also tried wxRIGHT and they won't leave the left side. Please any suggestions would be helpful, its driving me insane.

Thanks

Christopher Regan
Factory Applications Programmer
(845) 902-1313

"Move like a jellyfish. Rhythm is nothing. You go with the flow. You don't stop." ~ Jack Johnson

I have a panel with a horizontal boxsizer. I set the dimensions of the sizer to that of the panel. I then add two buttons to the sizer telling them not to grow horizontally or veritcally. I tell them to align in the center of the sizer using
wxALIGN_CENTER. So it looks like this:

X, Y = self.GetSize()

self.bsStaticBox = wxStaticBox(id=wxNewId(),
                                                             label='Port Information:', name='stSpineLBLabel', parent=self, pos=wxPoint(6,
                                                             0), size=wxSize(X, Y), style=0)
sizer = wxStaticBoxSizer(self.bsStaticBox, wxHORIZONTAL)

self.SetAutoLayout(true)
self.SetSizer(sizer)

sizer.SetDimension(0,0,X, Y)

There is no need to do this or to set the size of the static box, as the sizer will automatically be given all the client area of self to play with and will resize the controlled windows as appropriate.

sizer.Add(pButton, 0, wxALIGN_CENTRE | wxLEFT | wxRIGHT, 5)
                    sizer.Layout()

The buttons do center vertically in the sizer but they don't center horizontally. I have tried wxALIGN_CENTER_HORIZONTAL. I also tried wxRIGHT and they won't leave the left side. Please any suggestions would be helpful, its driving me insane.

Something like this perhaps?

from wxPython.wx import *

class TestPanel(wxPanel):
     def __init__(self, parent):
         wxPanel.__init__(self, parent, -1)

         sb = wxStaticBox(self, -1, "SB Label")
         b1 = wxButton(self, -1, "Button One")
         b2 = wxButton(self, -1, "Button Two")
         sizer = wxStaticBoxSizer(sb, wxHORIZONTAL)

         sizer.Add(10,10, 1)
         sizer.Add(b1, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5)
         sizer.Add(b2, 0, wxALIGN_CENTER|wxLEFT|wxRIGHT, 5)
         sizer.Add(10,10, 1)

         self.SetSizer(sizer)

app = wxPySimpleApp()
f = wxFrame(None, -1, "Just Testing", size=(350,250))
p = TestPanel(f)
f.Show()
app.MainLoop()

Notice that I add spacers before and after the buttons, and allow them to grow, so they fill the space on either side of the buttons.

···

christopher.j.regan@philips.com wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!