Can't get wx SizedPanel to align children vertically

I’m using a the SizedPanel class from
wx.lib.sized_controls on macOS (Sierra 10.12) and can’t seem to
get children objects to align vertically.

  The code snippet below has 3 panes in a vertical sized panel. 

header and footer pane are fixed in size (i.e. do not expand), but
the header pane does. I can get the static text object to align
horizontally (e.g. center) but I can’t get it to align vertically
(e.g. center). The text always remains at the top of the pane.

  Am I doing something wrong?

  Or is there a problem with vertical alignment on macOS perhaps?

  Thanks, Brendan.
···

`import wx``

      ``import wx.lib.sized_controls as wxSC``

      ``

      ``##============================================================================``

      ``

      ``class wxServicePanel(wxSC.SizedPanel):``

      ``    def __init__(self, parent):``

      ``        super().__init__(parent)``

      ``

      ``        pane = self``

      ``        pane.SetSizerType("vertical")``

      ``        #pane.SetSizerType("horizontal")``

      ``        #pane.SetBackgroundColour("grey")``

      ``        self.pane = pane``

      ``

      ``        ## Row 1``

      ``                    header_pane = self.header_pane =

wxSC.SizedPanel(pane)``

      ``                    wx.StaticText(header_pane,

label=“header_pane”)``

      ``        header_pane.Fit()``

      ``        header_pane.SetMinSize(header_pane.GetSize())``

      ``

      ``        ## Row 2``

      ``                    main_pane = self.main_pane =

wxSC.SizedPanel(pane)``

      ``        main_pane.SetBackgroundColour("white")``

      ``                    st = wx.StaticText(main_pane,

label=“main_pane”)``

      ``        st.SetSizerProps(align='center')``

      ``        #st.SetSizerProps(valign='bottom')``

      ``                    #st.SetSizerProps(valign='center',

halign=‘center’)``

      ``                    #st.SetSizerProps(align='center',

expand=True, proportion=1)``

      ``        main_pane.SetSizerProps(align='center')``

      ``                    #main_pane.SetSizerProps(align='center',

expand=True)``

      ``                    #main_pane.SetSizerProps(expand=True,

proportion=1)``

      ``                    #main_pane.SetSizerProps(align='center',

expand=True, proportion=1)``

      ``        main_pane.Fit()``

      ``        main_pane.SetMinSize(main_pane.GetSize())``

      ``

      ``        ## Row 3``

      ``                    footer_pane = self.footer_pane =

wxSC.SizedPanel(pane)``

      ``                    st = wx.StaticText(footer_pane,

label=“footer_pane”)``

      ``        #st.SetSizerProps(halign='right')``

      ``        footer_pane.Fit()``

      ``        footer_pane.SetMinSize(footer_pane.GetSize())``

      ``        footer_pane.SetSizerProps(halign='right')``

      ``

      ``                    ## ensure can't resize dialog to less screen

space than the controls need``

      ``        self.Fit()``

      ``        self.SetMinSize(self.GetSize())``

      ``

      ``##============================================================================`

Yes, although it’s subtle. The code is doing what you asked, but
what you asked is not what you wanted. The StaticText control is
the only thing in the main_pane, so it expands to fill the pane.
The control IS vertically centered, occupying the entire space in
the pane. (You can see that because it is colored white.) The
issue is that a static text control does not have the ability to
vertically center its own text within its window. The control is
centered, but the text is not.
What you need are spacers, above and below the static text, to suck
up all the extra space. That’s normal and easy when you are using
sizers directly, but it’s kind of hidden with
wx.lib.sized_controls. Something like this seems to work:
## Row 2
main_pane = self.main_pane = wxSC.SizedPanel(pane)
main_pane.SetBackgroundColour(“white”)
spacer = wxSC.SizedPanel(main_pane,-1)
spacer.SetSizerProps(proportion=1)
st = wx.StaticText(main_pane, label=“main_pane”)
st.SetSizerProps(align=‘center’)
spacer = wxSC.SizedPanel(main_pane,-1)
spacer.SetSizerProps(proportion=1)

···

Brendan Simon (eTRIX) wrote:

    I'm using a the SizedPanel class from

wx.lib.sized_controls on macOS (Sierra 10.12) and can’t seem to
get children objects to align vertically.

    The code snippet below has 3 panes in a vertical sized panel. 

header and footer pane are fixed in size (i.e. do not expand),
but the header pane does. I can get the static text object to
align horizontally (e.g. center) but I can’t get it to align
vertically (e.g. center). The text always remains at the top of
the pane.

    Am I doing something wrong?
-- Tim Roberts, Providenza & Boekelheide, Inc.

timr@probo.com