Should newbies play with sizers?

Well, whether they should or not, this newbie is playing with sizers.

I'm running wxPython 2.4.0 and Python 2.2.2 on Win32.

I am trying to build a button bar at the bottom of a frame. I want the
buttons to resize, so a conventional toolbar is out, I think. After
looking over the demos that came with wxPython, I decided to implement
my button bar inside a wxSashLayoutWindow. Feel free to steer me in a
different direction, if it's easier!

Code attached. It runs. The buttons are in the sash where they
belong. But the wxBoxSizer doesn't work! All the buttons governed by
the sizer are at their default sizes and are drawn overlapping, at
(0,0). I can see that the sizers for each individual button are
contained within the wxBoxSizer that I defined. But the GetSize()
method for my sizer remains stubbornly at (0,0), even though it
contains those three buttons.

Did I leave out a step somewhere?

By the way, thanks to everyone who helped with the "Hello, world"
crash. I've mostly separated myself from IDLE, and I'm passing
interpreted code straight to python.exe or pythonw.exe. I'm also
tackling Scintilla.

Button bar.py (1.6 KB)

···

--
John J. Ladasky Jr., Ph.D.
Department of Biology
Johns Hopkins University
Baltimore MD 21218
USA
Earth

Since I have not worked with sash windows very much I can't explain
everything or offer much detailed advice, but your problem
interested me, so I took a stab at it. Basically I just put the
buttons on a panel before placing them in the sash window, and it
seems to work. I am also a strong advocate of a more
object-oriented approach to life, so I put the button panel code in
its own class.

Hope this helps,
Donnal Walter
Arkansas Children's Hospital

···

--- JOHN LADASKY LADASKY <john.ladasky@comcast.net> wrote:

Well, whether they should or not, this newbie is playing with
sizers.
<snip>
Code attached. It runs. The buttons are in the sash where they
belong. But the wxBoxSizer doesn't work! All the buttons
governed by the sizer are at their default sizes and are drawn
overlapping, at (0,0). ...

Did I leave out a step somewhere?

#-----------------------------------------------------------
class ButtonPanel(wxPanel):
    
    buttons = ["button one", "and next, we have button two",
               "and a really long button for number three"]

    def __init__(self, parent):
        wxPanel.__init__(self, parent, -1)
        self.sizer = wxBoxSizer(wxHORIZONTAL)
        for name in self.buttons:
            button = wxButton(self, -1, name)
            self.sizer.Add(button, 1, wxALL, 4)
        self.SetSizer(self.sizer)
        self.SetAutoLayout(true)
        self.sizer.Fit(self)

class MyFrame(wxFrame):

    def __init__(self, parent, ID, title):
        wxFrame.__init__(self, parent, ID, title)

        EVT_SIZE(self, self.OnSize)

        self.mainPanel = wxPanel(self, -1)

        win = wxSashLayoutWindow(self, -1,)
        win.SetOrientation(wxLAYOUT_HORIZONTAL)
        win.SetAlignment(wxLAYOUT_BOTTOM)
        win.SetDefaultSize(wxSize(0, 40))
        win.SetBackgroundColour(wxColour(100, 70, 110))
        win.SetSashVisible(wxSASH_BOTTOM, true)
        self.sash = win
        btnPanel = ButtonPanel(win)

    def OnSize(self, event):
        wxLayoutAlgorithm().LayoutWindow(self, self.mainPanel)
        
#-----------------------------------------------------------

class MyApp(wxApp):

    def OnInit(self):
        frame = MyFrame(None, -1, "Basic button bar demo")
        frame.Show(true)
        self.SetTopWindow(frame)
        return true

app = MyApp(0)
app.MainLoop()