wx.StaticLine not displaying in wx.StaticBoxSizer unless window is resized

I have a a StaticLine separating some buttons in a StaticBoxSizer. For some reason the StaticLine does not initially draw and only shows up when the window is resized (covering the line). When the GridBagSizer that contains the button layout is outside of a StaticBoxSizer, it shows up with no problem. I have created a test GUI to demonstrate the problem. Any help is greatly appreciated.

Python Version: 2.7
wxPython Version: 2.9.4.0 msw (classic)
Platform: Win7

test_gui.py (2.1 KB)

Ian,

   Works here on Slackware-14.1 (see attached screenshot), but the virtual
terminal showed this after I closed the application:

[rshepard@salmo ~]$ python test_gui.py swig/python detected a memory leak of type 'wxPyXmlSubclassFactory *', no
destructor found.

   That should give you a starting point.

   Perhaps it's related to Microsoft no longer supporting win7? :slight_smile:

Rich

···

On Mon, 28 Jul 2014, Ian Abshire wrote:

I have created a test GUI to demonstrate the problem. Any help is greatly
appreciated.

Platform: Win7

I get a similar image here on Win 8.1 with 3.0.0.0 MSW Classic. I also get the PyXmlSubclassFactory * error. It goes away when I comment out the “import wx.xrc” (it still works without that import)

It seems to be a known ‘safe’ bug… https://groups.google.com/d/msg/wxPython-users/984OzOdHQCc/zD_xMtLtgAMJ

···

On Monday, July 28, 2014 5:08:58 PM UTC-7, fuzzydoc wrote:

On Mon, 28 Jul 2014, Ian Abshire wrote:

I have created a test GUI to demonstrate the problem. Any help is greatly

appreciated.

Platform: Win7

Ian,

Works here on Slackware-14.1 (see attached screenshot), but the virtual

terminal showed this after I closed the application:

[rshepard@salmo ~]$ python test_gui.py
swig/python detected a memory leak of type ‘wxPyXmlSubclassFactory *’, no

destructor found.

That should give you a starting point.

Perhaps it’s related to Microsoft no longer supporting win7? :slight_smile:

Rich

Thanks for your responses. That is interesting, I do not get that error on my machine, although commenting “import wx.xrc” out does not change anything, so I don’t really need it. Based on the post Nathan linked to, that does not seem to be the issue. Any other ideas?

···

On Monday, July 28, 2014 5:01:28 PM UTC-7, Ian Abshire wrote:

I have a a StaticLine separating some buttons in a StaticBoxSizer. For some reason the StaticLine does not initially draw and only shows up when the window is resized (covering the line). When the GridBagSizer that contains the button layout is outside of a StaticBoxSizer, it shows up with no problem. I have created a test GUI to demonstrate the problem. Any help is greatly appreciated.

Python Version: 2.7
wxPython Version: 2.9.4.0 msw (classic)
Platform: Win7

try self.Refresh() after self.Centre(wx.BOTH )

···

On Tuesday, July 29, 2014 8:40:30 AM UTC-7, Ian Abshire wrote:

Thanks for your responses. That is interesting, I do not get that error on my machine, although commenting “import wx.xrc” out does not change anything, so I don’t really need it. Based on the post Nathan linked to, that does not seem to be the issue. Any other ideas?

On Monday, July 28, 2014 5:01:28 PM UTC-7, Ian Abshire wrote:

I have a a StaticLine separating some buttons in a StaticBoxSizer. For some reason the StaticLine does not initially draw and only shows up when the window is resized (covering the line). When the GridBagSizer that contains the button layout is outside of a StaticBoxSizer, it shows up with no problem. I have created a test GUI to demonstrate the problem. Any help is greatly appreciated.

Python Version: 2.7
wxPython Version: 2.9.4.0 msw (classic)
Platform: Win7

I tried that, but no luck.

···

On Tuesday, July 29, 2014 9:19:22 AM UTC-7, Nathan McCorkle wrote:

try self.Refresh() after self.Centre(wx.BOTH )

On Tuesday, July 29, 2014 8:40:30 AM UTC-7, Ian Abshire wrote:

Thanks for your responses. That is interesting, I do not get that error on my machine, although commenting “import wx.xrc” out does not change anything, so I don’t really need it. Based on the post Nathan linked to, that does not seem to be the issue. Any other ideas?

On Monday, July 28, 2014 5:01:28 PM UTC-7, Ian Abshire wrote:

I have a a StaticLine separating some buttons in a StaticBoxSizer. For some reason the StaticLine does not initially draw and only shows up when the window is resized (covering the line). When the GridBagSizer that contains the button layout is outside of a StaticBoxSizer, it shows up with no problem. I have created a test GUI to demonstrate the problem. Any help is greatly appreciated.

Python Version: 2.7
wxPython Version: 2.9.4.0 msw (classic)
Platform: Win7

I have a a StaticLine separating some buttons in a StaticBoxSizer. For
some reason the StaticLine does not initially draw and only shows up when
the window is resized (covering the line). When the GridBagSizer that
contains the button layout is outside of a StaticBoxSizer, it shows up with
no problem. I have created a test GUI to demonstrate the problem. Any help
is greatly appreciated.

This works on wxPython 2.8.12, but that's besides the point.

I tried it with 2.9.4, got the error, and then re-did it with one change:
you are adding everything directly to the frame. Try placing a wxPanel as
the first object (and setting the sizer on that instead of the frame
itself) and then adding the various widgets to that panel, including the
staticLine. I partially tested it (didn't bother to deal with the sizers),
and the line showed up.

Che

···

On Mon, Jul 28, 2014 at 8:01 PM, Ian Abshire <ianabshire@gmail.com> wrote:

Python Version: 2.7
wxPython Version: 2.9.4.0 msw (classic)
Platform: Win7

--
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 wxpython-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Great catch, I have a feeling that is the issue!

P.S. in case Che wasn’t clear enough, you’re creating your widgets with self as the parent, Che is saying to make a Panel and use that as the parent for all the widgets. You don’t need to set the Panel to the Frame, since you pass self (the Frame) to the Panel when you construct it.

···

On Tuesday, July 29, 2014 12:29:35 PM UTC-7, Che M wrote:

you are adding everything directly to the frame. Try placing a wxPanel as the first object (and setting the sizer on that instead of the frame itself) and then adding the various widgets to that panel, including the staticLine.

Thank you for your suggestions, they made a lot of sense, but I still can’t seem to get it working. I added the panel with:

panel = wx.Panel(self, -1)

I then changed the object constructors to use panel instead of self, i.e.:

self.m_staticline1 = wx.StaticLine( panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )

I then laid out the panel as such:

panel.SetSizer( gbSizer_outer )
gbSizer_outer.Fit( panel )
panel.Layout()

Have I missed something? I’m not sure if I implemented your suggestion incorrectly, or if it didn’t work. Thanks for the help!

···

On Tuesday, July 29, 2014 1:18:55 PM UTC-7, Nathan McCorkle wrote:

On Tuesday, July 29, 2014 12:29:35 PM UTC-7, Che M wrote:

you are adding everything directly to the frame. Try placing a wxPanel as the first object (and setting the sizer on that instead of the frame itself) and then adding the various widgets to that panel, including the staticLine.

Great catch, I have a feeling that is the issue!

P.S. in case Che wasn’t clear enough, you’re creating your widgets with self as the parent, Che is saying to make a Panel and use that as the parent for all the widgets. You don’t need to set the Panel to the Frame, since you pass self (the Frame) to the Panel when you construct it.

works for me, even just doing self=wx.Panel(self) after the wx.Frame.__init works

see the more-sane looking code (which works for me)

I did notice that the self.SetSizeHintsSz didn’t seem to be working to make the min size such that the widgets won’t be hidden (frame can’t be sized too small)… but I fixed that with gbSizer_outer.SetSizeHints(self) after setting the sizer

test_gui.py (2.16 KB)

···

On Tuesday, July 29, 2014 2:26:28 PM UTC-7, Ian Abshire wrote:

Thank you for your suggestions, they made a lot of sense, but I still can’t seem to get it working. I added the panel with:

panel = wx.Panel(self, -1)

I then changed the object constructors to use panel instead of self, i.e.:

self.m_staticline1 = wx.StaticLine( panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )

I then laid out the panel as such:

panel.SetSizer( gbSizer_outer )
gbSizer_outer.Fit( panel )
panel.Layout()

Have I missed something? I’m not sure if I implemented your suggestion incorrectly, or if it didn’t work. Thanks for the help!

On Tuesday, July 29, 2014 1:18:55 PM UTC-7, Nathan McCorkle wrote:

On Tuesday, July 29, 2014 12:29:35 PM UTC-7, Che M wrote:

you are adding everything directly to the frame. Try placing a wxPanel as the first object (and setting the sizer on that instead of the frame itself) and then adding the various widgets to that panel, including the staticLine.

Great catch, I have a feeling that is the issue!

P.S. in case Che wasn’t clear enough, you’re creating your widgets with self as the parent, Che is saying to make a Panel and use that as the parent for all the widgets. You don’t need to set the Panel to the Frame, since you pass self (the Frame) to the Panel when you construct it.

I made the changes you suggested to the sample app, and they work. I then tried to do the same thing to my actual application, and the problem persisted. I then realized in my actual application I am changing the color with:

self.SetBackgroundColour( wx.Colour( 197, 206, 209 ) )

When I add this to the sample app, the lines disappear again. Any ideas why? Thanks!

test_gui.py (2.28 KB)

···

On Tuesday, July 29, 2014 2:56:09 PM UTC-7, Nathan McCorkle wrote:

works for me, even just doing self=wx.Panel(self) after the wx.Frame.__init works

see the more-sane looking code (which works for me)

Thank you for your suggestions, they made a lot of sense, but I still can’t seem to get it working. I added the panel with:

panel = wx.Panel(self, -1)

I then changed the object constructors to use panel instead of self, i.e.:

self.m_staticline1 = wx.StaticLine( panel, wx.ID_ANY, wx.DefaultPosition, wx.DefaultSize, wx.LI_HORIZONTAL )

I then laid out the panel as such:

panel.SetSizer( gbSizer_outer )
gbSizer_outer.Fit( panel )
panel.Layout()

Have I missed something? I’m not sure if I implemented your suggestion incorrectly, or if it didn’t work. Thanks for the help!

On Tuesday, July 29, 2014 1:18:55 PM UTC-7, Nathan McCorkle wrote:

On Tuesday, July 29, 2014 12:29:35 PM UTC-7, Che M wrote:

you are adding everything directly to the frame. Try placing a wxPanel as the first object (and setting the sizer on that instead of the frame itself) and then adding the various widgets to that panel, including the staticLine.

Great catch, I have a feeling that is the issue!

P.S. in case Che wasn’t clear enough, you’re creating your widgets with self as the parent, Che is saying to make a Panel and use that as the parent for all the widgets. You don’t need to set the Panel to the Frame, since you pass self (the Frame) to the Panel when you construct it.

I did notice that the self.SetSizeHintsSz didn’t seem to be working to make the min size such that the widgets won’t be hidden (frame can’t be sized too small)… but I fixed that with gbSizer_outer.SetSizeHints(self) after setting the sizer

On Tuesday, July 29, 2014 2:26:28 PM UTC-7, Ian Abshire wrote:

Using your sample code, with the set colour, on my machine:
of course it is entirely possible that you are setting the
background colour to too near your themes line colour to easily see
the line…
Gadget/Steve

···

On 30/07/14 00:29, Ian Abshire wrote:

    I made the changes you suggested to the sample app,

and they work. I then tried to do the same thing to my actual
application, and the problem persisted. I then realized in my
actual application I am changing the color with:

    self.SetBackgroundColour( wx.Colour( 197, 206, 209 ) )



    When I add this to the sample app, the lines disappear again.

Any ideas why? Thanks!

Hm that’s strange. I wonder why it wouldn’t work on my machine. The color isn’t the issue, because resize (hiding the line, and then unhiding the line) makes the line show up, and it is visible.

···

On Tuesday, July 29, 2014 9:59:09 PM UTC-7, Gadget Steve wrote:

On 30/07/14 00:29, Ian Abshire wrote:

    I made the changes you suggested to the sample app,

and they work. I then tried to do the same thing to my actual
application, and the problem persisted. I then realized in my
actual application I am changing the color with:

    self.SetBackgroundColour( wx.Colour( 197, 206, 209 ) )



    When I add this to the sample app, the lines disappear again.

Any ideas why? Thanks!

Using your sample code, with the set colour, on my machine:

<img src="https://groups.google.com/group/wxpython-users/attach/3c1434ff94ca76f0/eagiedhd.png?part=0.1.1&amp;authuser=0" alt="">



of course it is entirely possible that you are setting the

background colour to too near your themes line colour to easily see
the line…

Gadget/Steve

Here is when I start the application:

Here is after I minimize and then bring back up:

···

On Wednesday, July 30, 2014 8:42:37 AM UTC-7, Ian Abshire wrote:

Hm that’s strange. I wonder why it wouldn’t work on my machine. The color isn’t the issue, because resize (hiding the line, and then unhiding the line) makes the line show up, and it is visible.

On Tuesday, July 29, 2014 9:59:09 PM UTC-7, Gadget Steve wrote:

On 30/07/14 00:29, Ian Abshire wrote:

    I made the changes you suggested to the sample app,

and they work. I then tried to do the same thing to my actual
application, and the problem persisted. I then realized in my
actual application I am changing the color with:

    self.SetBackgroundColour( wx.Colour( 197, 206, 209 ) )



    When I add this to the sample app, the lines disappear again.

Any ideas why? Thanks!

Using your sample code, with the set colour, on my machine:

<img src="https://groups.google.com/group/wxpython-users/attach/3c1434ff94ca76f0/eagiedhd.png?part=0.1.1&amp;authuser=0" alt="">



of course it is entirely possible that you are setting the

background colour to too near your themes line colour to easily see
the line…

Gadget/Steve

Hello all,

I tried the sample app on Win7 (64Bit), Python 2.7.8, wxPython 2.9.5 and have the same effect: The static line is only shown after minimizing.

Adding wx.CallLater(0, frame.Refresh) just before app.MainLoop() solves it. But i think this is just a workaround.

···

Torsten

Odd. Two things I could suggest trying (I haven't tried):

1) Try calling the SetBackgroundColour() on the panel. Currently, you're
calling it on the Frame. If this works, I don't understand why yet.

2) Try reparenting things such that the StaticBox is the parent of the
widgets, NOT the panel. To quote Robin Dunn from this list: "The
recommendation is now [wx2.9 +] to use a parent/child relationship between
the staticbox and the widgets contained in it,".

Che

···

On Tue, Jul 29, 2014 at 7:29 PM, Ian Abshire <ianabshire@gmail.com> wrote:

I made the changes you suggested to the sample app, and they work. I then
tried to do the same thing to my actual application, and the problem
persisted. I then realized in my actual application I am changing the color
with:

self.SetBackgroundColour( wx.Colour( 197, 206, 209 ) )

When I add this to the sample app, the lines disappear again. Any ideas
why? Thanks!

Torsten, you are correct. Adding the CallAfter does make them display correctly, although it is a work around. I am still curious what the cause is and how to fix it, but at least I now have a way to make it work, so thank you!

Che, I tried #1 with no luck. I may be misunderstanding what you mean for #2, but I tried swapping panel with analyzeImageBox in the widgets, like such:

self.analyzeImage = wx.Button( analyzeImageBox, wx.ID_ANY, u"Analyze Image", wx.DefaultPosition, wx.Size( 170,45 ), 0 )

but got an error saying an argument of type ‘wxWindow *’ was expected. Did I implement your suggestion correctly?

···

On Wednesday, July 30, 2014 11:03:45 AM UTC-7, Che M wrote:

On Tue, Jul 29, 2014 at 7:29 PM, Ian Abshire ianab...@gmail.com wrote:

I made the changes you suggested to the sample app, and they work. I then tried to do the same thing to my actual application, and the problem persisted. I then realized in my actual application I am changing the color with:

self.SetBackgroundColour( wx.Colour( 197, 206, 209 ) )

When I add this to the sample app, the lines disappear again. Any ideas why? Thanks!

Odd. Two things I could suggest trying (I haven’t tried):

  1. Try calling the SetBackgroundColour() on the panel. Currently, you’re calling it on the Frame. If this works, I don’t understand why yet.
  1. Try reparenting things such that the StaticBox is the parent of the widgets, NOT the panel. To quote Robin Dunn from this list: “The recommendation is now [wx2.9 +] to use a parent/child relationship between the staticbox and the widgets contained in it,”.

Che

I believe the problem with #2 above is that you aren’t saving the StaticBox, which is what the parent should be, not the StaticBoxSizer. Split that line into two, and use the StaticBox object for the StaticBoxSizer constructor as well as for the other widgets.

···

On Wednesday, July 30, 2014 11:31:50 AM UTC-7, Ian Abshire wrote:

Torsten, you are correct. Adding the CallAfter does make them display correctly, although it is a work around. I am still curious what the cause is and how to fix it, but at least I now have a way to make it work, so thank you!

Che, I tried #1 with no luck. I may be misunderstanding what you mean for #2, but I tried swapping panel with analyzeImageBox in the widgets, like such:

self.analyzeImage = wx.Button( analyzeImageBox, wx.ID_ANY, u"Analyze Image", wx.DefaultPosition, wx.Size( 170,45 ), 0 )

but got an error saying an argument of type ‘wxWindow *’ was expected. Did I implement your suggestion correctly?

On Wednesday, July 30, 2014 11:03:45 AM UTC-7, Che M wrote:

On Tue, Jul 29, 2014 at 7:29 PM, Ian Abshire ianab...@gmail.com wrote:

I made the changes you suggested to the sample app, and they work. I then tried to do the same thing to my actual application, and the problem persisted. I then realized in my actual application I am changing the color with:

self.SetBackgroundColour( wx.Colour( 197, 206, 209 ) )

When I add this to the sample app, the lines disappear again. Any ideas why? Thanks!

Odd. Two things I could suggest trying (I haven’t tried):

  1. Try calling the SetBackgroundColour() on the panel. Currently, you’re calling it on the Frame. If this works, I don’t understand why yet.
  1. Try reparenting things such that the StaticBox is the parent of the widgets, NOT the panel. To quote Robin Dunn from this list: “The recommendation is now [wx2.9 +] to use a parent/child relationship between the staticbox and the widgets contained in it,”.

Che

Nathan, you are correct, that was the issue. It is working now. Thank you everyone for your help!

···

On Wednesday, July 30, 2014 12:06:22 PM UTC-7, Nathan McCorkle wrote:

I believe the problem with #2 above is that you aren’t saving the StaticBox, which is what the parent should be, not the StaticBoxSizer. Split that line into two, and use the StaticBox object for the StaticBoxSizer constructor as well as for the other widgets.

On Wednesday, July 30, 2014 11:31:50 AM UTC-7, Ian Abshire wrote:

Torsten, you are correct. Adding the CallAfter does make them display correctly, although it is a work around. I am still curious what the cause is and how to fix it, but at least I now have a way to make it work, so thank you!

Che, I tried #1 with no luck. I may be misunderstanding what you mean for #2, but I tried swapping panel with analyzeImageBox in the widgets, like such:

self.analyzeImage = wx.Button( analyzeImageBox, wx.ID_ANY, u"Analyze Image", wx.DefaultPosition, wx.Size( 170,45 ), 0 )

but got an error saying an argument of type ‘wxWindow *’ was expected. Did I implement your suggestion correctly?

On Wednesday, July 30, 2014 11:03:45 AM UTC-7, Che M wrote:

On Tue, Jul 29, 2014 at 7:29 PM, Ian Abshire ianab...@gmail.com wrote:

I made the changes you suggested to the sample app, and they work. I then tried to do the same thing to my actual application, and the problem persisted. I then realized in my actual application I am changing the color with:

self.SetBackgroundColour( wx.Colour( 197, 206, 209 ) )

When I add this to the sample app, the lines disappear again. Any ideas why? Thanks!

Odd. Two things I could suggest trying (I haven’t tried):

  1. Try calling the SetBackgroundColour() on the panel. Currently, you’re calling it on the Frame. If this works, I don’t understand why yet.
  1. Try reparenting things such that the StaticBox is the parent of the widgets, NOT the panel. To quote Robin Dunn from this list: “The recommendation is now [wx2.9 +] to use a parent/child relationship between the staticbox and the widgets contained in it,”.

Che