Ok, I have the beginning of a solution, detailed below, but with this the labels do not refresh properly.
How can I ensure the labels are always visible, as for frozen labels or any grid cell?
Anyway here is the idea, within the Draw method of my custom column label renderer:
- for the extra label I do not want, I simply pass the drawing
- for the non-frozen ones I want to keep, I draw them shifted by the total width of frozen columns
self.grid = MyGrid(self.sbox_grid, size=(1000, 800))
self.grid.CreateGrid(self.row_number, self.col_number)
self.grid.SetTable(self.table, takeOwnership=True)
self.grid.FreezeTo(0, self.vector_length)
offset = self._freeze_x_shit() # total width of frozen columns
[self.grid.SetColLabelRenderer(col, MyReportLabelRenderer(self.vector_length, offset)) for col in range(self.grid.GetNumberCols())]
class MyGrid(wx.grid.Grid, glr.GridWithLabelRenderersMixin):
def __init__(self, *args, **kw):
wx.grid.Grid.__init__(self, *args, **kw)
glr.GridWithLabelRenderersMixin.__init__(self)
class MyReportLabelRenderer(glr.GridLabelRenderer):
def __init__(self, vector_length, x_shift):
self.vector_length = vector_length
self.offset = -1 * x_shift
def Draw(self, grid, dc, rect, col):
if col >= self.vector_length:
rect.Offset(self.offset, 0)
hAlign, vAlign = grid.GetColLabelAlignment()
text = grid.GetColLabelValue(col)
self.DrawBorder(grid, dc, rect)
self.DrawText(grid, dc, rect, text, hAlign, vAlign)
else:
# rect.SetSize((0, 0))
pass
The drawing by itself, with the offset, seems to work properly, but only some labels are visible at a time, and when I move the horizontal scrollbar, some of them appears/disappears.
Basically, only the first one or two in the visible grid area are visible.
Hiding the window and putting it in front again does a partial redraw.
But at no time I have all labels always visible (and stable).
A ForcedRefresh() of the grid do not change anything.
Here some screenshoots of what I have done.
Horizontal scrollbar full left:
Horizontal scrollbar somewhere in the middle:
I can also have no label visible.
Is it possible that the pass in Draw method causing issues?