TextCtrl in nested StaticBoxSizer does not show control until redrawn

Python version=2.7.5 final 0
wxPython version=2.9.5.0 msw (classic)
wxDesigner version=2.14

I have a Horizontal StaticBoxSizer which contains different type widgets.
One of them is another StaticBoxSizer (but Vertical) which also contains
different type widgets. None of the TextCtrl widgets in the inner nested
Vertical StaticBoxSizer show their borders until the frame is resized, the
focus changes to each of the TextCtrl widgets, or the frame gets redrawn due
to switching back from overlapping windows (only the portion of the text
control(s) border that was covered by the overlapping window gets redrawn.

TextCtrl widgets contained in the outer Horizontal StaticBoxSizer, but
before or after the inner Vertical StaticBoxSizer, appear normal. Only the
TextCtrl widgets contained in the inner Vertical StaticBoxSizer are
affected. If EITHER outer OR inner StaticBoxSizer is changed to a simple
BoxSizer, the text controls are correct.

Is there a way to programmatically force the whole frame to get redrawn? I
tried Refresh(), Update(), and other things that did not work. Putting a
value into the TextCtrl (.SetLabel) will show the value but still not the
border.

I have a simple program which shows this issue. It has the Widget Inspection
Tool on the Admin menu. The population of the menubar and the frame's
widgets is code generated by wxDesigner 2.14.
simple.py
<http://wxpython-users.1045709.n5.nabble.com/file/n5718907/simple.py>

···

-----
Done is better than perfect -
but it is not done if it is not right.
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/TextCtrl-in-nested-StaticBoxSizer-does-not-show-control-until-redrawn-tp5718907.html
Sent from the wxPython-users mailing list archive at Nabble.com.

This is also affecting my ListCtrl and TreeCtrl borders in a StaticBoxSizer
that is in another StaticBoxSizer. With my frame full of widgets and sizers,
it is processing slower so sometimes I can see when the frame first comes up
(shows), it appears that the borders do display at one point then
immediately get "covered up".

···

-----
Done is better than perfect -
but it is not done if it is not right.
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/TextCtrl-in-nested-StaticBoxSizer-does-not-show-control-until-redrawn-tp5718907p5718916.html
Sent from the wxPython-users mailing list archive at Nabble.com.

All of your controls on the panel are siblings.But in the documents, it mentioned:
… since wxWidgets 2.9.1 you are encouraged to create the windows which are added to StaticBoxSizer as children of StaticBox itself…

Mark

Mark

I can see that each StaticBox as well as the other windows are all

children of the same panel and each of those added to the associated
StaticBoxSizer. So, for instance, the first part of the code that
looks like this:

def wdr_mainframe( **parent**, call_fit = True, set_sizer = True ):
    item0 = wx.BoxSizer( wx.VERTICAL )

    **item2** = wx.StaticBox( **parent**, -1, "Section 1" )
    item2.SetFont( wx.Font( 12, wx.ROMAN, wx.NORMAL, wx.BOLD ) )
    item1 = wx.StaticBoxSizer( item2, wx.HORIZONTAL )

    item3 = wx.StaticText( **parent**, ID_TEXT, "Before", wx.DefaultPosition, wx.DefaultSize, 0 )
    item1.Add( item3, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
    item4 = wx.TextCtrl( **parent**, ID_TEXTCTRL, "", wx.DefaultPosition, [80,-1], 0 )
    item1.Add( item4, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
    item5 = wx.TextCtrl( **parent**, ID_TEXTCTRL, "", wx.DefaultPosition, [80,-1], 0 )
    item1.Add( item5, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
    **item7** = wx.StaticBox( **parent**, -1, "Widgets" )
    item6 = wx.StaticBoxSizer( item7, wx.VERTICAL )

    item8 = wx.BoxSizer( wx.HORIZONTAL )

    item9 = wx.TextCtrl( **parent**, ID_TEXTCTRL_SECTION1, "", wx.DefaultPosition, [80,40], wx.TE_MULTILINE )
    item9.SetName( "Section1Text" )
    item8.Add( item9, 1, wx.GROW|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5 )

should look like this?

def wdr_mainframe( parent, call_fit = True, set_sizer = True ):
    item0 = wx.BoxSizer( wx.VERTICAL )

    **item2** = wx.StaticBox( **parent**, -1, "Section 1" )
    item2.SetFont( wx.Font( 12, wx.ROMAN, wx.NORMAL, wx.BOLD ) )
    item1 = wx.StaticBoxSizer( item2, wx.HORIZONTAL )

    item3 = wx.StaticText( **item2**, ID_TEXT, "Before", wx.DefaultPosition, wx.DefaultSize, 0 )
    item1.Add( item3, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
    item4 = wx.TextCtrl( **item2**, ID_TEXTCTRL, "", wx.DefaultPosition, [80,-1], 0 )
    item1.Add( item4, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
    item5 = wx.TextCtrl( **item2**, ID_TEXTCTRL, "", wx.DefaultPosition, [80,-1], 0 )
    item1.Add( item5, 0, wx.ALIGN_CENTER|wx.ALL, 5 )
And does that also mean that a nested StaticBox should have the

previous one as the parent or would it still use the original panel
as the parent?

    **item7** = wx.StaticBox( **item2**, -1, "Widgets" )
    item6 = wx.StaticBoxSizer( item7, wx.VERTICAL )

    item8 = wx.BoxSizer( wx.HORIZONTAL )

    item9 = wx.TextCtrl( **item7**, ID_TEXTCTRL_SECTION1, "", wx.DefaultPosition, [80,40], wx.TE_MULTILINE )
    item9.SetName( "Section1Text" )
    item8.Add( item9, 1, wx.GROW|wx.ALIGN_CENTER_HORIZONTAL|wx.ALL, 5 )
This will be a problem since almost all of my screens are generated

using wxDesigner, that generates the (now problem) code above, and I
use a StaticBoxSizer quite a bit to describe sections of controls
using a minimum of real estate.

So far, the only issue I have seen with this is when the frame is

shown initially. After the whole frame gets overlaid by another
application’s window, and Windows marks the whole area dirty, and it
is brought to the top again, or when resizing the frame, it repaints
properly.

Thanks Mark
···

On 10/14/2013 11:46 PM, Mark Weng
wrote:

    All

of your controls on the panel are siblings.But in the documents,
it mentioned:

    ... since wxWidgets 2.9.1 you are encouraged to create the

windows which are added to StaticBoxSizer as
children of StaticBox itself…

    Mark
  --

  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 .
For more options, visit .

wxpython-users+unsubscribe@googlegroups.com
https://groups.google.com/groups/opt_out

Mark,

I made the changes as per your suggestion below and it works. I guess that
means in 2.9.1+, it is much more than a simple "encouragement". :wink:

Aside all the work of having to manually change the parent relationships
every time I make changes to the layout using wxDesigner, this presents
another problem. I set the font on the StaticBox so its label stands out
from the other text in the panel, which was fine, but with all the windows
now being children of that StaticBox, it sets the font for all of them! That
means that every window that has associated text literals and/or text input
- which is almost all of them, their fonts have to be set manually to the
default. I have not found a way around that.

At this point I am more interested in getting the old screen programatically
repainted but cannot find a way to do that. Whatever portion of the frame
that gets overlapped by another application's frame will automatically get
repainted properly when the frame moves back to the top. I would like to
mark the whole frame as "dirty" and have it repainted properly as if it had
been overlapped and brought back to the foreground. I tried
main_frame.Refresh() and even wx.CallAfter(main_frame.Refresh), both in the
wxApp() after the main frame had been shown, and that makes no difference.
Any other suggestions?

According to the docs:

*Refresh(self, eraseBackground=True, rect=None)

    Mark the specified rectangle (or the whole window) as "dirty" so it will
be repainted. Causes an EVT_PAINT event to be generated and sent to the
window.

···

*

Mark wrote

All of your controls on the panel are siblings.But in the documents, it
mentioned:

... since wxWidgets 2.9.1 you are encouraged to create the windows which
are added to StaticBoxSizer as children of StaticBox itself...

Mark

-----
Done is better than perfect -
but it is not done if it is not right.
--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/TextCtrl-in-nested-StaticBoxSizer-does-not-show-control-until-redrawn-tp5718907p5719340.html
Sent from the wxPython-users mailing list archive at Nabble.com.