wx.Grid sort indicator

Hi,

I noticed that wxWidgets has some API managing a sort indicator for
the column header for a wxGrid (SetSortingColumn, UnsetSortingColumn,
as described here: http://docs.wxwidgets.org/trunk/classwx_grid.html).
Is this available from wxPython, or is drawing on the grid column
labels (as described here: http://wiki.wxpython.org/index.cgi/DrawingOnGridColumnLabel)
still the only way to go?

-mxt

Hi,

I noticed that wxWidgets has some API managing a sort indicator for
the column header for a wxGrid (SetSortingColumn, UnsetSortingColumn,
as described here: http://docs.wxwidgets.org/trunk/classwx_grid.html).
Is this available from wxPython,

It will be in 2.9. ("trunk" in the URL above indicates that it is the version of the docs corresponding with the trunk version of wxWidgets, which is the 2.9 branch.)

or is drawing on the grid column
labels (as described here: http://wiki.wxpython.org/index.cgi/DrawingOnGridColumnLabel)
still the only way to go?

Currently, yes.

ยทยทยท

On 4/15/10 12:44 PM, mxt wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

Hi mxt,
I don't have a direct answer to your question, but one cheap way that
I invented (along with many others, I'm sure) to display sort
indicators is with Unicode characters U2206 and U2207. Just add chose
characters to the label text and you have up/down triangles as sort
indicators.

Hope this helps
Philip

ยทยทยท

On Thu, Apr 15, 2010 at 3:44 PM, mxt <mxxtaylor@gmail.com> wrote:

Hi,

I noticed that wxWidgets has some API managing a sort indicator for
the column header for a wxGrid (SetSortingColumn, UnsetSortingColumn,
as described here: http://docs.wxwidgets.org/trunk/classwx_grid.html).
Is this available from wxPython, or is drawing on the grid column
labels (as described here: http://wiki.wxpython.org/index.cgi/DrawingOnGridColumnLabel)
still the only way to go?

--
To unsubscribe, send email to wxPython-users+unsubscribe@googlegroups.com
or visit http://groups.google.com/group/wxPython-users?hl=en

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:

class SortableColumnLabelRenderer(wx.lib.mixins.gridlabelrenderer.GridLabelRenderer):
    ''' Column Label Renderer that optionally draws a sorting indicator '''
    def __init__(self, sorting_ascending_fn):
        ''' Args:
            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())
1 Like