Re: Abridged summary of wxpython-users@googlegroups.com - 4 updates in 4 topics

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Re: Abridged summary of wxpython-users@googlegroups.com - 4 updates in 4 topics

Brendan Simon (eTRIX)

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. Am I doing something wrong?
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)
Tim Roberts, <a href="javascript:" target="_blank" gdf-obfuscated-mailto="I9WoQ5RvAwAJ" rel="nofollow" onmousedown="this.href='javascript:';return true;" onclick="this.href='javascript:';return true;">ti...@...
Thanks Tim.  The trick with the spacer does work :) Note: the white area is the background of the middle pane, not of the static text object.  I set the background of the ST object and it's a different region I changed the widget to a generic button to see if that makes any difference (just in case there was something weird with static text.  I know native macOS buttons don't expand vertically). I can always get the generic button to be horizontally centred (with or without spacers, and using vertical or horizontal sized panels), however I can only get the generic button t be vertically centred if I use the spacer "trick". Is this right?  Why does horizontal centring work, but not vertical centring (without spacers)? Is this just a known limitation, quirk or feature or wxWidgets and/or the native GUI framework (macOS cocoa in this case)? I think what I'm wanting to do is have a static text widget, that doesn't expand, but is positioned in the centre of the parent pane (main pane).  As the main pane expands, the static text should get repositioned to the centre.  That's how I think it should work conceptually, but it doesn't (at least for the vertical alignment).  I'm trying to work out whether it is a bug, or whether I've got my wires crossed (or whether it's just a limitation/quirk that's never going to change). Thanks, Brendan.
--
eTRIX pty ltd PO Box 497, Inverloch, VIC 3996, AUSTRALIA. +61-(0)417-380-984 [hidden email]

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Abridged summary of wxpython-users@googlegroups.com - 4 updates in 4 topics

Tim Roberts
Brendan Simon (eTRIX) wrote:

      
        I can always get the generic button to be horizontally centred
        (with or without spacers, and using vertical or horizontal sized
        panels), however I can only get the generic button t be
        vertically centred if I use the spacer "trick".
        Is this right?  Why does horizontal centring work, but not
        vertical centring (without spacers)?
        Is this just a known limitation, quirk or feature or wxWidgets
        and/or the native GUI framework (macOS cocoa in this case)?

It's a subtlety of spacers.  A vertical box sizer can center the items within it horizontally, but the vertical alignment is based on proportionality with the other items in the sizer.  Similarly, a horizontal box sizer can center things the items within it vertically, but not horizontally.  In each case, you need to add a proportional spacer to make that happen.  Again, the fact that you are using the convenient spaced controls hides the sizers, and makes this subtlety much less obvious.


I think what I'm wanting to do is have a static text widget, that doesn't expand, but is positioned in the centre of the parent pane (main pane).  As the main pane expands, the static text should get repositioned to the centre.  That's how I think it should work conceptually, but it doesn't (at least for the vertical alignment).  I'm trying to work out whether it is a bug, or whether I've got my wires crossed (or whether it's just a limitation/quirk that's never going to change).

Spacers are the way to make that happen.
-- 
Tim Roberts, [hidden email]
Providenza & Boekelheide, Inc.

--
You received this message because you are subscribed to the Google Groups "wxPython-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.