Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InformFirstDirection() cannot be overridden in Python but a custom Sizer is not possible without it #2452

Open
ludocode opened this issue Aug 28, 2023 · 2 comments · May be fixed by #2453
Open

Comments

@ludocode
Copy link

Operating system: Ubuntu 20.04, Windows 10
wxPython version & source: 4.2.1
Python version & source: 3.8.10 (Ubuntu), 3.10.0 (Windows)
Description of the problem:

InformFirstDirection() must be overridden by classes that derive from Sizer in order to properly implement any non-trivial sizer, as indicated by this comment:

https://github.com/wxWidgets/wxWidgets/blob/be772c284f20969e7c2a5b62d3d43db56cdc5a6b/include/wx/sizer.h#L636-L642

However, wxPython forbids this method from being overridden in Python classes that derive from Sizer. The only methods that can be overridden are CalcMin() and RepositionChildren():

def fixSizerClass(klass):
"""
Remove all virtuals except for CalcMin and RecalcSizes.
"""
removeVirtuals(klass)
klass.find('CalcMin').isVirtual = True
klass.find('RepositionChildren').isVirtual = True

This means it is not possible to implement a non-trivial custom Sizer in Python. Even the simple BoxSizer and WrapSizer need InformFirstDirection() to properly calculate their size.

I am trying to implement a custom Sizer in Python similar to WrapSizer that uses a box packing algorithm to more efficiently layout its children. Unfortunately, without this method being virtual, it is impossible to make it work properly.

(As a workaround I am having my custom sizer store a reference to its containing ScrolledPanel so it can call GetClientSize() on it during its CalcMin(). This is an ugly hack that should not be necessary.)

swt2c added a commit to swt2c/Phoenix that referenced this issue Aug 29, 2023
It seems this is required in order to implement a non-trivial custom Sizer.

Fixes wxWidgets#2452.
@swt2c swt2c linked a pull request Aug 29, 2023 that will close this issue
@swt2c
Copy link
Collaborator

swt2c commented Aug 29, 2023

Can you confirm that #2453 fixes the issue?

@swt2c
Copy link
Collaborator

swt2c commented Aug 29, 2023

Can you confirm that #2453 fixes the issue?

Whoops. Looks like it's not completely that easy. :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants