Phoenix icon indicating copy to clipboard operation
Phoenix copied to clipboard

Using the native header for wx.Grid causes InsertCols() and AppendCols() to break

Open AuroranAI opened this issue 4 years ago • 3 comments

Operating system: Windows 10 wxPython version & source: Pypi, ver.4.1.0, earliest version it was an issue: 4.0.6 Python version & source: Stock python 3.7.2

Description of the problem: If a wx.Grid is using a native header and AutoResize() has been called, InsertCols() will throw the following C++ error:

wx._core.wxAssertionError: C++ assertion "idx < m_size" failed at C:\PROJECTS\bb2\dist-win64-py37\build\ext\wxWidgets\include\wx/vector.h(482) in wxVector<int>::at(): 

A workaround for this is to disable the native header before Inserting a new column, then re-enabling the native header.

Similarly, AppendCols() is prone to break with native headers. To cause the issue, call self.grid.SetColPos() once, and subsequently call AppendCols(), which produces the following C++ error:

wx._core.wxAssertionError: C++ assertion "order >= 0 && order <= GetShownColumnsCount()" failed at ..\..\src\msw\headerctrl.cpp(634) in wxMSWHeaderCtrl::MSWToNativeOrder(): logic error

Like the last issue, disabling the native header before calling AppendCols() and SetColPos() causes correct functioning.

While both of these require another function being called before they break, both InsertCols() and AppendCols() break only while the grid uses a native header. The issue seems to be that AutoResize() and SetColPos() have incorrect/different side effects when called with a native header, leading to idx and order being set incorrectly.

Attached is a .py file demonstration. error.zip

AuroranAI avatar Aug 26 '20 19:08 AuroranAI

This is certainly a wxWidgets bug. I see it also in the wxWidgets grid demo when I use your settings (auto resize and native header).

DietmarSchwertberger avatar Apr 10 '22 13:04 DietmarSchwertberger

Actually, it would always trigger if the column widths are set individually. I have created a wxWidgets PR to fix this.

DietmarSchwertberger avatar Apr 10 '22 13:04 DietmarSchwertberger

The PR has been merged. At some time, it should find its way into wxPython as well...

DietmarSchwertberger avatar Apr 10 '22 14:04 DietmarSchwertberger