Size: 2846
Comment: missing edit-log entry for this revision
|
Size: 3033
Comment: missing edit-log entry for this revision
|
Deletions are marked like this. | Additions are marked like this. |
Line 1: | Line 1: |
= wxGridCellRenderer = |
|
Line 19: | Line 17: |
* {{{Clone()}}} -- Create a duplicate renderer, normally you can use {{{return self.__class__()}}} as seen for the cell editor. | Note: a bug in wxPython 2.3.2.1 (and earlier?) required that you return an explicit {{{wxSize}}} object, rather than a two-tuple of {{{(width,height)}}}. The two-tuple doesn't cause an exception, the value was just silently ignored. * {{{Clone()}}} -- Create a duplicate renderer, normally you can use {{{return self.__class__()}}}. |
The cell renderer allows you to customize the display of a particular data type within the grid. For instance, it allows you to display a "colour" data type as a swatch of colour, rather than as a mere plain-text label. The class has a very simple API, using a standard wxDC for drawing into the cell's rectangle. A secondary function of the renderer is the determination of the "best size" for the cell.
void Draw(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool isSelected) -- Draw the given cell on the provided DC inside the given rectangle using the style specified by the attribute and the default or selected state corresponding to the isSelected value. Keep in mind that this method will be called once for every instance of the data type, which may result in hundreds of calls for every display update of the grid. Care should be taken to make this a very fast method.
The default implementation will draw the rectangle with the background colour from attr and set the text colour and font. Not sure what it does if the attribute values are null, or whether any attribute showing up here must be fully specified (in testing, the attribute seems to have all the values available, but I'm not sure if that's guaranteed). The attribute doesn't change the value of attr.GetBackgroundColour() to reflect the selected status, so you'll need to figure out the background colour in those cases regardless (see note below). I'm guessing the default implementation just reverses the text and background colour roles. Note: This method is used for drawing both selected and unselected cells. To make your renderer consistent with the built-in renderers, you will need to use the colours and fonts used by the grid. As far as I can see, these are the normal default values:
font -- wxNORMAL_FONT (I'm guessing that grid.GetFont() would be the real source?)
unselected text -- wxSystemSettings_GetColour( wxSYS_COLOUR_WINDOWTEXT )
unselected background -- wxSystemSettings_GetColour( wxSYS_COLOUR_WINDOW )
selected text -- wxSystemSettings_GetColour( wxSYS_COLOUR_HIGHLIGHTTEXT )
selected background -- wxSystemSettings_GetColour( wxSYS_COLOUR_HIGHLIGHT )
wxSize GetBestSize(wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, int row, int col) -- Get the preferred size of the cell for its contents. Note: this size determines both the viewing and editing size of the cell, so care should be taken to allow enough space for the editing controls for the data type.
Note: a bug in wxPython 2.3.2.1 (and earlier?) required that you return an explicit wxSize object, rather than a two-tuple of (width,height). The two-tuple doesn't cause an exception, the value was just silently ignored.
Clone() -- Create a duplicate renderer, normally you can use return self.__class__().
Back to the ["wxGrid Manual"]