Bug: wx.FlexGridSizer bugs?

I forgot to post the environment for previous posts: wxPython 2.7,
wxWidgets 2.6.3, XP, all upgrades installed.

Leo users two wx.SplitterWindow's to lay out an outline log and body panes.
The main splitter contains the secondary splitter and the body pane. The
secondary splitter contains the outline pane and the log pane. The log pane
contains a wx.NoteBook.

In this complex environment, there appears to be a bug in wx.FlexGridSizer.
The following code works:

# Sizer 1 lays out the find/change areas.
sizer1 = wx.FlexGridSizer(2, 2, vgap=10,hgap=5)
sizer1.Add(self.find_ctrl,1,wx.EXPAND)
sizer1.Add(self.fLabel,0,wx.EXPAND)
sizer1.Add(self.change_ctrl,1,wx.EXPAND)
sizer1.Add(self.cLabel,0,wx.EXPAND)

find_ctrl and change_ctrl are wx.TextCtrl's. fLabel and cLabel are
wx.StaticText's. This code puts the labels to the *right* of the
wx.TextCtrl's. However, the following acts strangely (on XP at least).

sizer1 = wx.FlexGridSizer(2, 2, vgap=10,hgap=5)
sizer1.Add(self.fLabel,0,wx.EXPAND)
sizer1.Add(self.find_ctrl,1,wx.EXPAND)
sizer1.Add(self.cLabel,0,wx.EXPAND)
sizer1.Add(self.change_ctrl,1,wx.EXPAND)

This should (and does) add the labels to the *left* of the wx.TextCtrl's.
However, clicking on the find_ctrl widget causes the size of that widget to
expand so it covers the label (!) BTW, the change_ctrl widget does not
display this strange behavior.

You can see the entire source code at:
http://leo.tigris.org/source/browse/leo/plugins/__wx_gui.py?rev=1.32&view=log

There are also focus problems relating to the sizers just mentioned.
Clicking in the find/change areas can clear the text in those areas. Very
weird.

Edward

···

--------------------------------------------------------------------
Edward K. Ream email: edreamleo@charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------

Hi Edward,

Edward K. Ream wrote:

I forgot to post the environment for previous posts: wxPython 2.7,
wxWidgets 2.6.3, XP, all upgrades installed.

Leo users two wx.SplitterWindow's to lay out an outline log and body panes.
The main splitter contains the secondary splitter and the body pane. The
secondary splitter contains the outline pane and the log pane. The log pane
contains a wx.NoteBook.

In this complex environment, there appears to be a bug in wx.FlexGridSizer.
The following code works:

# Sizer 1 lays out the find/change areas.
sizer1 = wx.FlexGridSizer(2, 2, vgap=10,hgap=5)
sizer1.Add(self.find_ctrl,1,wx.EXPAND)
sizer1.Add(self.fLabel,0,wx.EXPAND)
sizer1.Add(self.change_ctrl,1,wx.EXPAND)
sizer1.Add(self.cLabel,0,wx.EXPAND)

find_ctrl and change_ctrl are wx.TextCtrl's. fLabel and cLabel are
wx.StaticText's. This code puts the labels to the *right* of the
wx.TextCtrl's. However, the following acts strangely (on XP at least).

sizer1 = wx.FlexGridSizer(2, 2, vgap=10,hgap=5)
sizer1.Add(self.fLabel,0,wx.EXPAND)
sizer1.Add(self.find_ctrl,1,wx.EXPAND)
sizer1.Add(self.cLabel,0,wx.EXPAND)
sizer1.Add(self.change_ctrl,1,wx.EXPAND)

This should (and does) add the labels to the *left* of the wx.TextCtrl's.
However, clicking on the find_ctrl widget causes the size of that widget to
expand so it covers the label (!) BTW, the change_ctrl widget does not
display this strange behavior.

I don't see much wrong with above :slight_smile: , I would do the statictext like this:
        parent.AddWindow(self.staticText1, 0, border=2,
              flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
I.e. don't expand and use the align flag so that the text is not "sticking" to the top alignment, you might also want to use borders.

I suspect something with the parenting of the controls is wrong or how the sizer is added to another sizer?

You can see the entire source code at:
http://leo.tigris.org/source/browse/leo/plugins/__wx_gui.py?rev=1.32&view=log

Can you post some code here which is runnable and shows the problem, so one can see it and play around with it.

Werner

In particular, what kind of controls are involved, and if they're
custom subclasses do the have any event handlers that could be
interfering with the sizer process.

As something to check first off, make sure that you call event.Skip()
from your event handlers unless you know why you shouldn't - with size
events in particular you can easily break layout.

···

On 12/15/06, Werner F. Bruhin <werner.bruhin@free.fr> wrote:

Hi Edward,

Edward K. Ream wrote:
> I forgot to post the environment for previous posts: wxPython 2.7,
> wxWidgets 2.6.3, XP, all upgrades installed.
>
> Leo users two wx.SplitterWindow's to lay out an outline log and body
> panes.
> The main splitter contains the secondary splitter and the body pane. The
> secondary splitter contains the outline pane and the log pane. The
> log pane
> contains a wx.NoteBook.
>
> In this complex environment, there appears to be a bug in
> wx.FlexGridSizer.
> The following code works:
>
> # Sizer 1 lays out the find/change areas.
> sizer1 = wx.FlexGridSizer(2, 2, vgap=10,hgap=5)
> sizer1.Add(self.find_ctrl,1,wx.EXPAND)
> sizer1.Add(self.fLabel,0,wx.EXPAND)
> sizer1.Add(self.change_ctrl,1,wx.EXPAND)
> sizer1.Add(self.cLabel,0,wx.EXPAND)
>
> find_ctrl and change_ctrl are wx.TextCtrl's. fLabel and cLabel are
> wx.StaticText's. This code puts the labels to the *right* of the
> wx.TextCtrl's. However, the following acts strangely (on XP at least).
>
> sizer1 = wx.FlexGridSizer(2, 2, vgap=10,hgap=5)
> sizer1.Add(self.fLabel,0,wx.EXPAND)
> sizer1.Add(self.find_ctrl,1,wx.EXPAND)
> sizer1.Add(self.cLabel,0,wx.EXPAND)
> sizer1.Add(self.change_ctrl,1,wx.EXPAND)
>
> This should (and does) add the labels to the *left* of the wx.TextCtrl's.
> However, clicking on the find_ctrl widget causes the size of that
> widget to
> expand so it covers the label (!) BTW, the change_ctrl widget does not
> display this strange behavior.
I don't see much wrong with above :slight_smile: , I would do the statictext like this:
        parent.AddWindow(self.staticText1, 0, border=2,
              flag=wx.ALIGN_CENTER_VERTICAL | wx.ALL)
I.e. don't expand and use the align flag so that the text is not
"sticking" to the top alignment, you might also want to use borders.

I suspect something with the parenting of the controls is wrong or how
the sizer is added to another sizer?
>
> You can see the entire source code at:
> http://leo.tigris.org/source/browse/leo/plugins/__wx_gui.py?rev=1.32&view=log
>
Can you post some code here which is runnable and shows the problem, so
one can see it and play around with it.

BTW, if you just start moving over to wxPython I would suggest to go with the 2.8 series, I don't think you will see fixes to 2.7.

Thanks for this tip. I'll switch to 2.8 immediately.

I am unable to modify the wx.GridBagSizer or wx.Notebook examples in the wxPython demo to show anything like the behavior I reported, so I'll retract, for now, my complaint about wx.FlexGridSizer. OTOH, something truly strange is happening...I'll let you know when I pin this down.

Edward

···

--------------------------------------------------------------------
Edward K. Ream email: edreamleo@charter.net
Leo: http://webpages.charter.net/edreamleo/front.html
--------------------------------------------------------------------