Predefined renderers

A grid renderer is an instance of the class wx.grid.GridCellRenderer, which is an abstract parent class. Typically, you would use one of its subclasses. Table 14.4 describes several predefined renderers that you can use in your cells. Each of these classes has a constructor and getter and setter methods.

To get the renderer for a specific cell, use the method GetCellRenderer(row, col), which returns the renderer instance for the given cell coordinates. To set the renderer for a cell, use SetCellRenderer(row, col, renderer), where the renderer

Table 14.4 Predefined grid cell renderers

Renderer class



Prints the textual data with word wrapping at the cell boundaries.


Renders Boolean data by using a checkbox in the middle of the cell—checked for True, unchecked for False.


Allows the cell to display a formatted date and/or time.


Renders a number as a textual equivalent. In other words, the data in the cell is in the list [0,1,2], but the cell would be rendered as one of ["John", "Fred", "Bob"].


Renders numerical floating point data with a specific width and precision. The constructor for this class takes two arguments (width=-1, precision=-1), where the width is the minimum number of digits to show, and the precision is the maximum number of digits displayed after the decimal point. The numbers displayed by this renderer are right justified by default.


Renders numerical data as entered. The numbers displayed by this renderer are right justified by default.


Renders the cell data as a simple string. By default, data rendered by this renderer is left justified. This is the default renderer used by the grid for all cells.

argument is the new renderer for that cell. These methods simply set or get the renderer stored in the cell's attribute object, so you can also deal with the Grid-CellAttr directly if you prefer. You can get and set the default renderer for the entire grid by using the methods GetDefaultRenderer() and SetDefaultRen-derer(renderer) .

You can set the renderer for an entire column at once—the typical use case for this being a spreadsheet application where certain columns always display data of a particular type. The methods for doing this are SetColFormatBool(col), SetCol-FormatNumber(col), and SetColFormatFloat(col, width, precision). Each of these methods sets the column attribute to use the renderer with the same name, and is a shortcut for calling SetColAttr() with a custom attribute object.

Was this article helpful?

0 0

Post a comment