wx.Frame style=SIMPLE_BORDER issues

This forum is reserved for everything you want to talk about. It could be about programming, opinions, open source programs, development in general, or just cool stuff to share!
Post Reply
hamishmb
Knows some wx things
Knows some wx things
Posts: 28
Joined: Mon Jul 08, 2019 8:48 pm
Location: /usr/lib/python3/

wx.Frame style=SIMPLE_BORDER issues

Post by hamishmb » Fri Nov 27, 2020 4:15 pm

I have recently found that when setting the client size of a wx.Frame at the same time as setting the size in the constructor, the windows is created with a size of 1x1 pixels.

It seems a lot of conditions have to be met for this:
  • Running Linux (X11 in my case), though I haven't tested on other platforms.
  • Using SetClientSize() just after setting the size using the constructor.
  • Using wx.SIMPLE_BORDER as the style (or any style with a non-resizable border).
  • Seems to happen more consistently on wxWidgets 3.1.x/wxPython 4.1.x than wxWidgets 3.0.x/wxPython 4.0.x.
  • Commenting the call to SetClientSize immediately results in the expected behaviour.
Please note, I haven't found this in wxWidgets directly, but in wxPython, and originally discussed it here: https://discuss.wxpython.org/t/wx-frame ... -0/35028/2. As such, I don't know if this is a wxWidgets bug, but Robin Dunn appears to think it might be.

I'm also going to note that the only reason I found this is that a while back, on certain platforms (probably macOS), I found it to be more reliable to call SetClientSize as well as setting the window size in the constructor. It may be the case that there is no need for this any more, but I figure I should report this anyway.

Has anyone else had this issue? Attached is a sample wxPython script that hopefully demonstrates the issue for others (uncomment the SetClientSize line to see it).
Attachments
demo.py
(895 Bytes) Downloaded 137 times

User avatar
doublemax@work
Earned some good credits
Earned some good credits
Posts: 131
Joined: Wed Jul 29, 2020 6:06 pm

Re: wx.Frame style=SIMPLE_BORDER issues

Post by doublemax@work » Mon Nov 30, 2020 1:31 pm

Seems to happen more consistently on wxWidgets 3.1.x/wxPython 4.1.x than wxWidgets 3.0.x/wxPython 4.0.x.
Does that mean it doesn't happen every time?
Using SetClientSize() just after setting the size using the constructor.
What happens if you use wxDefaultSize for the constructor? And if that works, why can't you use it?

hamishmb
Knows some wx things
Knows some wx things
Posts: 28
Joined: Mon Jul 08, 2019 8:48 pm
Location: /usr/lib/python3/

Re: wx.Frame style=SIMPLE_BORDER issues

Post by hamishmb » Mon Nov 30, 2020 2:21 pm

doublemax@work wrote:
Mon Nov 30, 2020 1:31 pm
Seems to happen more consistently on wxWidgets 3.1.x/wxPython 4.1.x than wxWidgets 3.0.x/wxPython 4.0.x.
Does that mean it doesn't happen every time?
No, the behaviour is just different on wxPython 4.0.x/wxWidgets 3.0.x - I think this bug was introduced oin wxWidgets 3.1.x or wxPython 4.1.x.
doublemax@work wrote:
Mon Nov 30, 2020 1:31 pm
Using SetClientSize() just after setting the size using the constructor.
What happens if you use wxDefaultSize for the constructor? And if that works, why can't you use it?
I'll have a go and get back to you. IIRC, the reason I don't do this is that the windows display oddly in some cases, but in this particular example it's because I'm using the frame as an advanced splash screen with a background - I need a particular size.

User avatar
doublemax
Moderator
Moderator
Posts: 16384
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: wx.Frame style=SIMPLE_BORDER issues

Post by doublemax » Mon Nov 30, 2020 4:45 pm

I need a particular size.
But SetClientSize does that too. I can't think of any scenario where is makes sense to have both SetClientSize and the size passed to the constructor.
Use the source, Luke!

hamishmb
Knows some wx things
Knows some wx things
Posts: 28
Joined: Mon Jul 08, 2019 8:48 pm
Location: /usr/lib/python3/

Re: wx.Frame style=SIMPLE_BORDER issues

Post by hamishmb » Wed Mar 10, 2021 7:19 pm

The problem is that SetClientSize doesn't do it consistently across X11 and Wayland when resizing is enabled. At any rate, I found a workaround for this issue.

If you want, I'll post it here.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 5310
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: wx.Frame style=SIMPLE_BORDER issues

Post by ONEEYEMAN » Tue Mar 16, 2021 2:33 pm

Please do.
It might be helpful for others.

But if you want a Splash Screen - why does it needs to be resizable? Besides - there is a "splash" sample in the wxWidgets - check it and see if it will do what you want.

It is in C++ though...

Thank you.

hamishmb
Knows some wx things
Knows some wx things
Posts: 28
Joined: Mon Jul 08, 2019 8:48 pm
Location: /usr/lib/python3/

Re: wx.Frame style=SIMPLE_BORDER issues

Post by hamishmb » Sat Apr 17, 2021 7:17 am

Hi,

No resizability needed, it just doesn't display at the right size unless resizing is enabled and then prevented from working. Apart from the workaround I found for that - I'll post that shortly.

I wanted custom chaneable text and a progress bar so I think advanced splash isn't quite enough for that?

Hamish

hamishmb
Knows some wx things
Knows some wx things
Posts: 28
Joined: Mon Jul 08, 2019 8:48 pm
Location: /usr/lib/python3/

Re: wx.Frame style=SIMPLE_BORDER issues

Post by hamishmb » Wed Jun 30, 2021 6:11 pm

Happened back across this and realised I forgot to post the solution I found.

The solution I found was to just either use SetClientSize() or define it in the constructor, but not both.

So the 1x1 pixel window only occurs if:
  • The window isn't resizable.
  • The size is defined in the call to the superclass constructor.
  • The same size is also defined in the constructor with SetClientSize()
I admit that this is a weird corner-case, but it still shouldn't be happening.

Post Reply