Hi,
I am using virtual grid for displaying data with custom render for auto wrapping the cell content when grid size changes.
I have added auto sizing of row in Custom Cell Render to display complete Cell content whenever Column size is changed. Auto sizing Rows seems to be very expensive when tried with huge data. This causing rendering of grid very slow or lagged.
Is there more efficient way to adjust row size to show complete cell contents? I tried adding logic to track old row height and auto size row only when there is change in it, but wasn’t that effective.
Any pointers are welcomed. Thanks in advance.
Thanks,
Saurabh
Snippet of my CustomGriCellAutoWrapStringRender:
Derived from http://markmail.org/download.xqy?id=6khc4r6w7c43vv3e&number=1
class CustomGridCellAutoWrapStringRenderer(wx.grid.PyGridCellRenderer):
def __init__(self):
wx.grid.PyGridCellRenderer.__init__(self)
self.rowHight = {}
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
text = grid.GetCellValue(row, col)
dc.SetFont(attr.GetFont())
curColSize = grid.GetColSize(col)
text = wordwrap.wordwrap(text, curColSize, dc, breakLongWords=True)
hAlign, vAlign = attr.GetAlignment()
if isSelected:
bg = grid.GetSelectionBackground()
fg = grid.GetSelectionForeground()
else:
bg = attr.GetBackgroundColour()
fg = attr.GetTextColour()
dc.SetTextBackground(bg)
dc.SetTextForeground(fg)
dc.SetBrush(wx.Brush(bg, wx.SOLID))
dc.SetPen(wx.TRANSPARENT_PEN)
dc.DrawRectangleRect(rect)
grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)
wrapped_hight = dc.GetMultiLineTextExtent(text)[1]
if wrapped_hight != self.rowHight.get(row, 0):
grid.AutoSizeRow(row)
self.rowHight[row] = max(wrapped_hight, self.rowHight.get(row, 0))