I found this question when searching on the web. I realize it is very old, but I figure other people might find it too and might benefit from a more modern answer: In the latest version of wx Python, one can use wx.lib.mixins.gridlabelrenderer to render column labels with a sorting indicator with little work. One possibility would be to set the grid column label renderer to the following custom renderer:
''' Column Label Renderer that optionally draws a sorting indicator '''
def __init__(self, sorting_ascending_fn):
checked_fn: Function with signature, (grid, col) that returns either
None, True or False, depending on whether a sorting indicator should be drawn in
the given col and if so whether it should point downward or upwards '''
self.sorting_ascending_fn = sorting_ascending_fn
def Draw(self, grid, dc, rect, col):
self.DrawBorder(grid, dc, rect)
sortAscending = self.sorting_ascending_fn(grid, col)
if sortAscending is not None:
width = wx.RendererNative.Get().DrawHeaderButtonContents(grid, dc, rect,
sortArrow=wx.HDR_SORT_ICON_DOWN if sortAscending else wx.HDR_SORT_ICON_UP)
rect.width -= width
self.DrawText(grid, dc, rect, grid.GetColLabelValue(col), *grid.GetColLabelAlignment())