how to center the toolbar in a wx.ToolBook?

In my app I have a wx.ToolBook with the ToolBar at the top. The total
width of the buttons in the ToolBar is less than the width of the
window (Frame). Currently the buttons are left-justified, the default.
I'd like the group of buttons to be centered horizontally, with equal
space on either end.

Does anyone know how to visually center the ToolBar in a wx.ToolBook?

···

--
David Goodger <http://python.net/~goodger>

David Goodger wrote:

In my app I have a wx.ToolBook with the ToolBar at the top. The total
width of the buttons in the ToolBar is less than the width of the
window (Frame). Currently the buttons are left-justified, the default.
I'd like the group of buttons to be centered horizontally, with equal
space on either end.

Does anyone know how to visually center the ToolBar in a wx.ToolBook?

In 2.9 you can add stretchable space to toolbars, so you might be able to center the other tools by adding a stretchable space item to the beginning and the end, although it might also confuse the toolbook if it has any code that is dependent on the order or index of the items it is managing.

···

--
Robin Dunn
Software Craftsman

Thanks for your answer, Robin. It goes most of the way to getting what I want.

I also want to eliminate the spaces around the toolbar. It seems that
there is a default internal border between the ToolBar and the
ToolBook content, which can be eliminated with:

    toolbook.InternalBorder = 0

But there's still a space between the ToolBar and the right edge of
the window (when the ToolBar is positioned at the top). How can I get
rid of that gap?

I can add a corresponding empty control, but it's an ugly kludge:

        toolbar = toolbook.ToolBar
        toolbar.InsertStretchableSpace(0)
        # !!! kludge here (compensates for space on the right):
        toolbar.InsertControl(0, wx.StaticText(toolbar, -1, '', size=(12,0)))
        toolbar.AddStretchableSpace()

The specific size is probably platform-dependent. How can I avoid this?

···

--
David Goodger <http://python.net/~goodger>

David Goodger wrote:

Thanks for your answer, Robin. It goes most of the way to getting what I want.

I also want to eliminate the spaces around the toolbar. It seems that
there is a default internal border between the ToolBar and the
ToolBook content, which can be eliminated with:

     toolbook.InternalBorder = 0

But there's still a space between the ToolBar and the right edge of
the window (when the ToolBar is positioned at the top). How can I get
rid of that gap?

I can add a corresponding empty control, but it's an ugly kludge:

         toolbar = toolbook.ToolBar
         toolbar.InsertStretchableSpace(0)
         # !!! kludge here (compensates for space on the right):
         toolbar.InsertControl(0, wx.StaticText(toolbar, -1, '', size=(12,0)))
         toolbar.AddStretchableSpace()

The specific size is probably platform-dependent. How can I avoid this?

There really shouldn't be any kind of gap there, the code is sizing it to fit the parent. Perhaps it is a separator being drawn by the toolbar? What platform are you seeing this on?

···

--
Robin Dunn
Software Craftsman

There really shouldn't be any kind of gap there, the code is sizing it
to fit the parent. Perhaps it is a separator being drawn by the
toolbar? What platform are you seeing this on?

It's Windows XP SP3 (ancient, I know, but still in use in many
businesses), Python 2.7.3, wxPython 2.9.4.0 (wxMSW/Unicode).

Attached are two images of the ToolBook page in the wxPython demo app.
One (toolbook toolbar left-default.png) shows the lack of a gap on the
left edge (there is a small white gap, but I believe that's the
underlying demo app; there's no gap on the light gray). The other
(toolbook toolbar right.png) shows the gap on the right. The only
difference in the code are these two lines added after the end of the
"for colour in colourList:" loop, at line 54:

        self.InternalBorder = 0
        self.ToolBar.InsertStretchableSpace(0)

···

--
David Goodger <http://python.net/~goodger&gt;