I’m following this example http://wiki.wxpython.org/DrawingOnGridColumnLabel to draw on the column header in a wx.Grid.
I have an application with very wide columns, so I adapted the example to dynamically adjust the location of the column label to try to keep it in the visible window. The paint event handler is shown below.
This works well on OSX, but doesn’t work very well on Linux GTK where it appears that the modified areas are not rendered to the display.
I’m running this on Ubunut 14.04 (Trusty) using python-wxgtk2.8.
I found that if I insert a RefreshRect() call at the end of the EVT_PAINT handler, the I see the newly rendered areas, but performance
is abysmal due to the overwhelming number of paint events.
I’d appreciate any suggestions as to how I can correct this behaviour.
Earl
def __onColumnHeaderPaint(self, evt):
labelWindow = self.GetGridColLabelWindow()
labelCanvas = wx.PaintDC(labelWindow)
labelRect = labelWindow.GetClientRect()
labelFont = self.GetLabelFont()
labelBackground = self.GetLabelBackgroundColour()
scrollXPixels, scrollYPixels = self.GetScrollPixelsPerUnit()
viewX, viewY = self.GetViewStart()
sizeX, sizeY = self.GetGridWindow().ClientSize
leftX = viewX * scrollXPixels
rightX = viewX * scrollXPixels + sizeX - 1
headerWidth = 0 - leftX
labelCanvas.SetBackground(wx.Brush(labelBackground))
labelCanvas.SetBrush(labelCanvas.GetBackground())
for col in range(self.GetNumberCols()):
colView = self.CellToRect(0, col)
colWidth = self.GetColSize(col)
colRect = wx.Rect(headerWidth, 0, colWidth, self.GetColLabelSize())
headerWidth += colWidth
if leftX <= colView.Right and colView.Left <= rightX:
labelCanvas.SetPen(
wx.Pen(wx.SystemSettings.GetColour(wx.SYS_COLOUR_3DSHADOW)))
labelCanvas.DrawLinePoint(
colRect.TopRight, colRect.TopLeft)
labelCanvas.DrawLinePoint(
colRect.BottomRight, colRect.BottomLeft)
colRect.SetHeight(colRect.Height -1)
labelCanvas.DrawLinePoint(colRect.TopRight, colRect.BottomRight)
colRect.SetHeight(colRect.Height + 2)
labelCanvas.SetPen(wx.WHITE_PEN)
labelCanvas.DrawLinePoint(colRect.BottomLeft, colRect.TopLeft)
labelCanvas.DrawLinePoint(colRect.TopLeft, colRect.TopRight)
colRect.SetHeight(colRect.Height - 1)
colLabelText = self.__columnLabel[col]
colLabelWidth = self.__columnLabelWidth[col]
# If the column is only partially visible, move the
# column label so that it is centred in the region
# that is visible, without overflowing into adjacent
# columns.
leftSide = max(colRect.Left,
min(0, colRect.Right - colLabelWidth))
rightSide = min(colRect.Right + 1,
max(sizeX, colRect.Left + colLabelWidth))
labelRect = wx.Rect(
leftSide, colRect.Y,
rightSide - leftSide, colRect.Height)
labelRect = colRect
labelCanvas.SetFont(labelFont)
labelCanvas.DrawLabel(colLabelText, labelRect, wx.ALIGN_CENTER)
labelWindow.RefreshRect(colRect)
pass
pass
``