wx.grid.Grid and its related classes are used for displaying and editing tabular data.
They provide a rich set of features for display, editing, and interacting with a variety of data sources. For simple applications, and to help you get started, wx.grid.Grid is the only class you need to refer to directly. It will set up default instances of the other classes and manage them for you. For more complex applications you can derive your own classes for custom grid views, grid data tables, cell editors and renderers. The Grid Overview has examples of simple and more complex applications, explains the relationship between the various grid classes and has a summary of the keyboard shortcuts and mouse functions provided by wx.grid.Grid.
A wx.grid.GridTableBase class holds the actual data to be displayed by a wx.grid.Grid class. One or more wx.grid.Grid classes may act as a view for one table class. The default table class is called wx.grid.GridStringTable and holds an array of strings. An instance of such a class is created by CreateGrid
.
wx.grid.GridCellRenderer is the abstract base class for rendering contents in a cell. The following renderers are predefined:
The look of a cell can be further defined using wx.grid.GridCellAttr. An object of this type may be returned by wx.grid.GridTableBase.GetAttr
.
wx.grid.GridCellEditor is the abstract base class for editing the value of a cell. The following editors are predefined:
Please see wx.grid.GridEvent, wx.grid.GridSizeEvent, wx.grid.GridRangeSelectEvent, and wx.grid.GridEditorCreatedEvent for the documentation of all event types you can use with wx.grid.Grid.
See also
Grid Overview, wx.grid.GridUpdateLocker
Default constructor. |
|
Appends one or more new columns to the right of the grid. |
|
Appends one or more new rows to the bottom of the grid. |
|
Return |
|
Return |
|
Assigns a pointer to a custom grid table to be used by the grid. |
|
Automatically sets the height and width of all rows and columns to fit their contents. |
|
Automatically adjusts width of the column to fit its label. |
|
Automatically sizes the column to fit its contents. |
|
Automatically sizes all columns to fit their contents. |
|
Automatically sizes the row to fit its contents. |
|
Automatically adjusts height of the row to fit its label. |
|
Automatically sizes all rows to fit their contents. |
|
Increments the grid’s batch count. |
|
Convert grid cell coordinates to grid window pixel coordinates. |
|
Returns an array of (visible) cells within the given region. |
|
Returns an array of column labels within the given region. |
|
Translates the logical coordinates to the device ones, taking into account the grid window type. |
|
Translates the device coordinates to the logical ones, taking into account the grid window type. |
|
Returns an array of row labels within the given region. |
|
Return |
|
Returns |
|
Returns |
|
Return |
|
Return |
|
Return |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns the grid window that contains the cell. |
|
Return the rectangle corresponding to the grid cell’s size and position in logical coordinates. |
|
Clears all data in the underlying grid table and repaints the grid. |
|
Deselects all cells that are currently selected. |
|
Change whether the horizontal grid lines are clipped by the end of the last column. |
|
Change whether the vertical grid lines are clipped by the end of the last row. |
|
Creates the grid window for an object initialized using the default constructor. |
|
Creates a grid with the specified initial number of rows and columns. |
|
Deletes one or more columns from a grid starting at the specified position. |
|
Deletes one or more rows from a grid starting at the specified position. |
|
Deselects a cell. |
|
Deselects a column of cells. |
|
Deselects a row of cells. |
|
Returns the grid window that includes the input coordinates. |
|
Disables in-place editing of grid cells. |
|
Disable interactive resizing of the specified column. |
|
Disables column moving by dragging with the mouse. |
|
Disables column sizing by dragging with the mouse. |
|
Disable mouse dragging of grid lines to resize rows and columns. |
|
Disables row moving by dragging with the mouse. |
|
Disables row sizing by dragging with the mouse. |
|
Disables column hiding from the header popup menu. |
|
Disable interactive resizing of the specified row. |
|
Enables or disables in-place editing of grid cell data. |
|
Enables or disables cell dragging with the mouse. |
|
Enables or disables column moving by dragging with the mouse. |
|
Enables or disables column sizing by dragging with the mouse. |
|
Enables or disables row and column resizing by dragging gridlines with the mouse. |
|
Enables or disables row moving by dragging with the mouse. |
|
Enables or disables row sizing by dragging with the mouse. |
|
Makes the grid globally editable or read-only. |
|
Turns the drawing of grid lines on or off. |
|
Enables or disables column hiding from the header popup menu. |
|
Decrements the grid’s batch count. |
|
Overridden wx.Window method. |
|
Causes immediate repainting of the grid. |
|
Sets or resets the frozen columns and rows. |
|
Returns the number of times that |
|
Sets the arguments to the horizontal and vertical text alignment values for the grid cell at the specified location. |
|
Returns the background colour of the cell at the specified location. |
|
Returns a pointer to the editor for the cell at the specified location. |
|
Returns the cell fitting mode. |
|
Returns the font for text in the grid cell at the specified location. |
|
Returns |
|
Returns a pointer to the renderer for the grid cell at the specified location. |
|
Get the size of the cell in number of cells covered by it. |
|
Returns the text colour for the grid cell at the specified location. |
|
Returns the string contained in the cell at the specified location. |
|
Returns the column |
|
Returns the pen used for vertical grid lines. |
|
Sets the arguments to the current column label alignment values. |
|
Returns the current height of the column labels. |
|
Returns the orientation of the column labels (either |
|
Returns the specified column label. |
|
Returns the coordinate of the left border specified column. |
|
Returns the minimal width to which a column may be resized. |
|
Get the minimal width of the given column/row. |
|
Returns the position of the specified column. |
|
Returns the coordinate of the right border specified column. |
|
Returns the width of the specified column. |
|
Get size information for all columns at once. |
|
Sets the arguments to the current corner label alignment values. |
|
Returns the orientation of the corner label (either |
|
Returns the (top-left) corner label. |
|
Returns the default cell alignment. |
|
Returns the current default background colour for grid cells. |
|
Returns the default cell fitting mode. |
|
Returns the current default font for grid cell text. |
|
Returns |
|
Returns the current default colour for grid cell text. |
|
Returns the default height for column labels. |
|
Returns the current default width for grid columns. |
|
Returns a pointer to the current default grid cell editor. |
|
Returns the default editor for the specified cell. |
|
Returns the default editor for the cells containing values of the given type. |
|
Returns the pen used for grid lines. |
|
Returns a pointer to the current default grid cell renderer. |
|
Returns the default renderer for the given cell. |
|
Returns the default renderer for the cell containing values of the given type. |
|
Returns the default width for the row labels. |
|
Returns the current default height for grid rows. |
|
Returns the leftmost column of the current visible area. |
|
Returns the topmost row of the current visible area. |
|
Return the columns grid window containing column frozen cells. |
|
Return the corner grid window containing frozen cells. |
|
Return the rows grid window containing row frozen cells. |
|
Return the header control used for column labels display. |
|
Return the column labels window. |
|
Return the window in the top left grid corner. |
|
Returns the current grid cell column position. |
|
Returns the current grid cursor position. |
|
Returns the current grid cell row position. |
|
Returns the colour used for grid lines. |
|
Return the row labels window. |
|
Return the main grid window containing the grid cells. |
|
Returns the colour used for the background of row and column labels. |
|
Returns the font used for row and column labels. |
|
Returns the colour used for row and column label text. |
|
Returns the total number of grid columns. |
|
Returns the number of frozen grid columns. |
|
Returns the number of frozen grid rows. |
|
Returns the total number of grid rows. |
|
Returns the attribute for the given cell creating one if necessary. |
|
Returns the attribute for the given cell creating one if necessary. |
|
Returns the row |
|
Returns the pen used for horizontal grid lines. |
|
Returns the alignment used for row labels. |
|
Returns the current width of the row labels. |
|
Returns the specified row label. |
|
Returns the minimal size to which rows can be resized. |
|
Returns the minimal size for the given column. |
|
Returns the position of the specified row. |
|
Returns the height of the specified row. |
|
Get size information for all row at once. |
|
Returns the number of pixels per horizontal scroll increment. |
|
Returns the number of pixels per vertical scroll increment. |
|
Returns a range of grid selection blocks. |
|
Returns an array of individually selected cells. |
|
Returns an ordered range of non-overlapping selected columns. |
|
Returns an array of selected columns. |
|
Returns an ordered range of non-overlapping selected rows. |
|
Returns an array of selected rows. |
|
Returns the colour used for drawing the selection background. |
|
Returns an array of the bottom right corners of blocks of selected cells. |
|
Returns an array of the top left corners of blocks of selected cells. |
|
Returns the colour used for drawing the selection foreground. |
|
Returns the current selection mode. |
|
Return the column in which the sorting indicator is currently displayed. |
|
Returns a base pointer to the current table object. |
|
Make the given cell current and ensure it is visible. |
|
Returns |
|
Hides the in-place cell edit control. |
|
Hides the specified column. |
|
Hides the column labels by calling |
|
Hides the specified row. |
|
Hides the row labels by calling |
|
Inserts one or more new columns into a grid with the first new column at the specified position. |
|
Inserts one or more new rows into a grid with the first new row at the specified position. |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Returns |
|
Return |
|
Return |
|
Return |
|
Returns |
|
Brings the specified cell into the visible grid cell area with minimal scrolling. |
|
Moves the grid cursor down by one row. |
|
Moves the grid cursor down in the current column such that it skips to the beginning or end of a block of non-empty cells. |
|
Moves the grid cursor left by one column. |
|
Moves the grid cursor left in the current row such that it skips to the beginning or end of a block of non-empty cells. |
|
Moves the grid cursor right by one column. |
|
Moves the grid cursor right in the current row such that it skips to the beginning or end of a block of non-empty cells. |
|
Moves the grid cursor up by one row. |
|
Moves the grid cursor up in the current column such that it skips to the beginning or end of a block of non-empty cells. |
|
Moves the grid cursor down by some number of rows so that the previous bottom visible row becomes the top visible row. |
|
Moves the grid cursor up by some number of rows so that the previous top visible row becomes the bottom visible row. |
|
Receive and handle a message from the table. |
|
Invalidates the cached attribute for the given cell. |
|
Redraw all the cells in the given block. |
|
Register a new data type. |
|
Draws part or all of a wx.grid.Grid on a wx.DC for printing or display. |
|
Resets the position of the columns to the default. |
|
Resets the position of the rows to the default. |
|
Sets the value of the current grid cell to the current in-place edit control value. |
|
Selects all cells in the grid. |
|
Selects a rectangular block of cells. |
|
Selects the specified column. |
|
Selects the specified row. |
|
Sets the cell attributes for the specified cell. |
|
Sets the horizontal and vertical alignment for grid cell text at the specified location. |
|
Set the background colour for the given cell or all cells by default. |
|
Sets the editor for the grid cell at the specified location. |
|
Specifies the behaviour of the cell contents if it doesn’t fit into the available space. |
|
Sets the font for text in the grid cell at the specified location. |
|
Sets the overflow permission of the cell. |
|
Sets the renderer for the grid cell at the specified location. |
|
Set the size of the cell. |
|
Sets the text colour for the given cell. |
|
Sets the string value for the cell at the specified location. |
|
Sets the cell attributes for all cells in the specified column. |
|
Sets the specified column to display boolean values. |
|
Sets the specified column to display data in a custom format. |
|
Sets the specified column to display date values. |
|
Sets the specified column to display floating point values with the given width and precision. |
|
Sets the specified column to display integer values. |
|
Sets the horizontal and vertical alignment of column label text. |
|
Sets the height of the column labels. |
|
Sets the orientation of the column labels (either |
|
Set the value for the given column label. |
|
Sets the minimal width to which the user can resize columns. |
|
Sets the minimal width for the specified column col. |
|
Sets the position of the specified column. |
|
Sets the width of the specified column. |
|
Restore all columns sizes. |
|
Sets the positions of all columns at once. |
|
Sets the horizontal and vertical alignment of the (top-left) corner label text. |
|
Sets the orientation of the (top-left) corner label (either |
|
Set the value for the (top-left) corner label. |
|
Sets the default horizontal and vertical alignment for grid cell text. |
|
Sets the default background colour for grid cells. |
|
Specifies the default behaviour of the cell contents if it doesn’t fit into the available space. |
|
Sets the default font to be used for grid cell text. |
|
Sets the default overflow permission of the cells. |
|
Sets the current default colour for grid cell text. |
|
Sets the default width for columns in the grid. |
|
Sets the default editor for grid cells. |
|
Sets the default renderer for grid cells. |
|
Sets the default height for rows in the grid. |
|
Set the grid cursor to the specified cell. |
|
Sets the colour used to draw grid lines. |
|
Sets the background colour for row and column labels. |
|
Sets the font for row and column labels. |
|
Sets the colour for row and column label text. |
|
Sets the extra margins used around the grid area. |
|
Makes the cell at the specified location read-only or editable. |
|
Sets the cell attributes for all cells in the specified row. |
|
Sets the horizontal and vertical alignment of row label text. |
|
Sets the width of the row labels. |
|
Sets the value for the given row label. |
|
Sets the minimal row height used by default. |
|
Sets the minimal height for the specified row. |
|
Sets the position of the specified row. |
|
Sets the height of the specified row. |
|
Restore all rows sizes. |
|
Sets the positions of all rows at once. |
|
Sets the number of pixels per horizontal scroll increment. |
|
Sets the number of pixels per vertical scroll increment. |
|
Set the colour to be used for drawing the selection background. |
|
Set the colour to be used for drawing the selection foreground. |
|
Set the selection behaviour of the grid. |
|
Set the column to display the sorting indicator in and its direction. |
|
Set the grid’s behaviour when the user presses the |
|
Passes a pointer to a custom grid table to be used by the grid. |
|
Set the Grid Table to be used by this grid. |
|
Call this in order to make the column labels use a native look by using |
|
Displays the active in-place cell edit control for the current cell after it was hidden. |
|
Shows the previously hidden column by resizing it to non-0 size. |
|
Shows the previously hidden row. |
|
Remove any currently shown sorting indicator. |
|
Enable the use of native header window for column labels. |
|
Returns the column at the given pixel position depending on the window. |
|
Returns the column whose right hand edge is close to the given logical x position. |
|
Translates logical pixel coordinates to the grid cell coordinates. |
|
Returns the row whose bottom edge is close to the given logical y position. |
|
Returns the grid row that corresponds to the logical y coordinate. |
wx.grid.
Grid
(ScrolledCanvas)¶Possible constructors:
Grid()
Grid(parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize,
style=WANTS_CHARS, name=GridNameStr)
Grid and its related classes are used for displaying and editing tabular data.
__init__
(self, *args, **kw)¶__init__ (self)
Default constructor.
You must call Create
to really create the grid window and also call CreateGrid
or SetTable
or AssignTable
to initialize its contents.
__init__ (self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=WANTS_CHARS, name=GridNameStr)
Constructor creating the grid window.
You must call either CreateGrid
or SetTable
or AssignTable
to initialize the grid contents before using it.
AppendCols
(self, numCols=1, updateLabels=True)¶Appends one or more new columns to the right of the grid.
The updateLabels argument is not used at present. If you are using a derived grid table class you will need to override wx.grid.GridTableBase.AppendCols
. See InsertCols
for further information.
numCols (int) –
updateLabels (bool) –
bool
True
on success or False
if appending columns failed.
AppendRows
(self, numRows=1, updateLabels=True)¶Appends one or more new rows to the bottom of the grid.
The updateLabels argument is not used at present. If you are using a derived grid table class you will need to override wx.grid.GridTableBase.AppendRows
. See InsertRows
for further information.
numRows (int) –
updateLabels (bool) –
bool
True
on success or False
if appending rows failed.
AreHorzGridLinesClipped
(self)¶Return True
if the horizontal grid lines stop at the last column boundary or False
if they continue to the end of the window.
The default is to clip grid lines.
bool
See also
AreVertGridLinesClipped
(self)¶Return True
if the vertical grid lines stop at the last row boundary or False
if they continue to the end of the window.
The default is to clip grid lines.
bool
See also
AssignTable
(self, table, selmode=GridSelectCells)¶Assigns a pointer to a custom grid table to be used by the grid.
This function is identical to SetTable
with takeOwnership
parameter set to True
, i.e. it simply always takes the ownership of the passed in pointer. This makes it simpler to use than SetTable
in the common case when the table should be owned by the grid object.
Note that this function should be called at most once and can’t be used to change the table used by the grid later on or reset it: if such extra flexibility is needed, use SetTable
directly.
table (wx.grid.GridTableBase) – The heap-allocated pointer to the table.
selmode (GridSelectionModes) – Selection mode to use.
New in version 4.1/wxWidgets-3.1.4.
AutoSize
(self)¶Automatically sets the height and width of all rows and columns to fit their contents.
AutoSizeColLabelSize
(self, col)¶Automatically adjusts width of the column to fit its label.
col (int) –
AutoSizeColumn
(self, col, setAsMin=True)¶Automatically sizes the column to fit its contents.
If setAsMin is True
the calculated width will also be set as the minimal width for the column.
col (int) –
setAsMin (bool) –
AutoSizeColumns
(self, setAsMin=True)¶Automatically sizes all columns to fit their contents.
If setAsMin is True
the calculated widths will also be set as the minimal widths for the columns.
setAsMin (bool) –
AutoSizeRow
(self, row, setAsMin=True)¶Automatically sizes the row to fit its contents.
If setAsMin is True
the calculated height will also be set as the minimal height for the row.
row (int) –
setAsMin (bool) –
AutoSizeRowLabelSize
(self, col)¶Automatically adjusts height of the row to fit its label.
col (int) –
AutoSizeRows
(self, setAsMin=True)¶Automatically sizes all rows to fit their contents.
If setAsMin is True
the calculated heights will also be set as the minimal heights for the rows.
setAsMin (bool) –
BeginBatch
(self)¶Increments the grid’s batch count.
When the count is greater than zero repainting of the grid is suppressed. Each call to BeginBatch must be matched by a later call to EndBatch
. Code that does a lot of grid modification can be enclosed between BeginBatch
and EndBatch
calls to avoid screen flicker. The final EndBatch
call will cause the grid to be repainted.
Notice that you should use wx.grid.GridUpdateLocker which ensures that there is always a matching EndBatch
call for this BeginBatch
if possible instead of calling this method directly.
BlockToDeviceRect
(self, topLeft, bottomRight, gridWindow=None)¶Convert grid cell coordinates to grid window pixel coordinates.
This function returns the rectangle that encloses the block of cells limited by topLeft and bottomRight cell in device coords and clipped to the client size of the grid window.
topLeft (wx.grid.GridCellCoords) –
bottomRight (wx.grid.GridCellCoords) –
gridWindow (wx.grid.GridWindow) –
Rect
New in version 4.1/wxWidgets-3.1.3: Parameter gridWindow has been added.
See also
CalcCellsExposed
(self, reg, gridWindow=None)¶Returns an array of (visible) cells within the given region.
reg (wx.Region) –
gridWindow (wx.grid.GridWindow) –
GridCellCoordsArray
CalcColLabelsExposed
(self, reg, gridWindow=None)¶Returns an array of column labels within the given region.
reg (wx.Region) –
gridWindow (wx.grid.GridWindow) –
list of integers
CalcGridWindowScrolledPosition
(self, *args, **kw)¶CalcGridWindowScrolledPosition (self, x, y, xx, yy, gridWindow)
Translates the logical coordinates to the device ones, taking into account the grid window type.
x (int) –
y (int) –
xx (int) –
yy (int) –
gridWindow (wx.grid.GridWindow) –
New in version 4.1/wxWidgets-3.1.3.
See also
wx.Scrolled.CalcScrolledPosition
CalcGridWindowScrolledPosition (self, pt, gridWindow)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
pt (wx.Point) –
gridWindow (wx.grid.GridWindow) –
Point
CalcGridWindowUnscrolledPosition
(self, *args, **kw)¶CalcGridWindowUnscrolledPosition (self, x, y, xx, yy, gridWindow)
Translates the device coordinates to the logical ones, taking into account the grid window type.
x (int) –
y (int) –
xx (int) –
yy (int) –
gridWindow (wx.grid.GridWindow) –
New in version 4.1/wxWidgets-3.1.3.
See also
wx.Scrolled.CalcUnscrolledPosition
CalcGridWindowUnscrolledPosition (self, pt, gridWindow)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
pt (wx.Point) –
gridWindow (wx.grid.GridWindow) –
Point
CalcRowLabelsExposed
(self, reg, gridWindow=None)¶Returns an array of row labels within the given region.
reg (wx.Region) –
gridWindow (wx.grid.GridWindow) –
list of integers
CanDragCell
(self)¶Return True
if the dragging of cells is enabled or False
otherwise.
bool
CanDragColMove
(self)¶Returns True
if columns can be moved by dragging with the mouse.
Columns can be moved by dragging on their labels.
bool
CanDragColSize
(self, col)¶Returns True
if the given column can be resized by dragging with the mouse.
This function returns True
if resizing the columns interactively is globally enabled, i.e. if DisableDragColSize
hadn’t been called, and if this column wasn’t explicitly marked as non-resizable with DisableColResize
.
col (int) –
bool
CanDragGridColEdges
(self)¶Return True
if column edges inside the grid can be dragged to resize the rows.
bool
New in version 4.1/wxWidgets-3.1.4.
See also
CanDragGridRowEdges
(self)¶Return True
if row edges inside the grid can be dragged to resize the rows.
bool
New in version 4.1/wxWidgets-3.1.4.
See also
CanDragGridSize
(self)¶Return True
if the dragging of grid lines to resize rows and columns is enabled or False
otherwise.
bool
CanDragRowMove
(self)¶Returns True
if rows can be moved by dragging with the mouse.
Rows can be moved by dragging on their labels.
bool
New in version 4.1/wxWidgets-3.1.7.
CanDragRowSize
(self, row)¶Returns True
if the given row can be resized by dragging with the mouse.
This is the same as CanDragColSize
but for rows.
row (int) –
bool
CanEnableCellControl
(self)¶Returns True
if the in-place edit control for the current grid cell can be used and False
otherwise.
This function always returns False
for the read-only cells.
bool
CanHaveAttributes
(self)¶Returns True
if this grid has support for cell attributes.
The grid supports attributes if it has the associated table which, in turn, has attributes support, i.e. wx.grid.GridTableBase.CanHaveAttributes
returns True
.
bool
CanHideColumns
(self)¶Returns True
if columns can be hidden from the popup menu of the native header.
bool
New in version 4.1/wxWidgets-3.1.3.
CellToGridWindow
(self, *args, **kw)¶CellToGridWindow (self, row, col)
Returns the grid window that contains the cell.
In a grid without frozen rows or columns (see FreezeTo
), this will always return the same window as GetGridWindow
, however if some parts of the grid are frozen, this function returns the window containing the given cell.
row (int) –
col (int) –
wx.grid.GridWindow
New in version 4.1/wxWidgets-3.1.3.
CellToGridWindow (self, coords)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
coords (wx.grid.GridCellCoords) –
wx.grid.GridWindow
CellToRect
(self, *args, **kw)¶Return the rectangle corresponding to the grid cell’s size and position in logical coordinates.
See also
CellToRect (self, row, col)
row (int) –
col (int) –
Rect
CellToRect (self, coords)
coords (wx.grid.GridCellCoords) –
Rect
ClearGrid
(self)¶Clears all data in the underlying grid table and repaints the grid.
The table is not deleted by this function. If you are using a derived table class then you need to override wx.grid.GridTableBase.Clear
for this function to have any effect.
ClearSelection
(self)¶Deselects all cells that are currently selected.
ClipHorzGridLines
(self, clip)¶Change whether the horizontal grid lines are clipped by the end of the last column.
By default the grid lines are not drawn beyond the end of the last column but after calling this function with clip set to False
they will be drawn across the entire grid window.
clip (bool) –
See also
ClipVertGridLines
(self, clip)¶Change whether the vertical grid lines are clipped by the end of the last row.
By default the grid lines are not drawn beyond the end of the last row but after calling this function with clip set to False
they will be drawn across the entire grid window.
clip (bool) –
See also
Create
(self, parent, id=ID_ANY, pos=DefaultPosition, size=DefaultSize, style=WANTS_CHARS, name=GridNameStr)¶Creates the grid window for an object initialized using the default constructor.
You must call either CreateGrid
or SetTable
or AssignTable
to initialize the grid contents before using it.
CreateGrid
(self, numRows, numCols, selmode=GridSelectCells)¶Creates a grid with the specified initial number of rows and columns.
Call this directly after the grid constructor. When you use this function wx.grid.Grid will create and manage a simple table of string values for you. All of the grid data will be stored in memory.
For applications with more complex data types or relationships, or for dealing with very large datasets, you should derive your own grid table class and pass a table object to the grid with SetTable
or AssignTable
.
numRows (int) –
numCols (int) –
selmode (GridSelectionModes) –
bool
DeleteCols
(self, pos=0, numCols=1, updateLabels=True)¶Deletes one or more columns from a grid starting at the specified position.
The updateLabels argument is not used at present. If you are using a derived grid table class you will need to override wx.grid.GridTableBase.DeleteCols
. See InsertCols
for further information.
pos (int) –
numCols (int) –
updateLabels (bool) –
bool
True
on success or False
if deleting columns failed.
DeleteRows
(self, pos=0, numRows=1, updateLabels=True)¶Deletes one or more rows from a grid starting at the specified position.
The updateLabels argument is not used at present. If you are using a derived grid table class you will need to override wx.grid.GridTableBase.DeleteRows
. See InsertRows
for further information.
pos (int) –
numRows (int) –
updateLabels (bool) –
bool
True
on success or False
if deleting rows failed.
DeselectCell
(self, row, col)¶Deselects a cell.
row (int) –
col (int) –
DeselectCol
(self, col)¶Deselects a column of cells.
col (int) –
DeselectRow
(self, row)¶Deselects a row of cells.
row (int) –
DevicePosToGridWindow
(self, *args, **kw)¶DevicePosToGridWindow (self, pos)
Returns the grid window that includes the input coordinates.
pos (wx.Point) –
wx.grid.GridWindow
New in version 4.1/wxWidgets-3.1.3.
DevicePosToGridWindow (self, x, y)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
x (int) –
y (int) –
wx.grid.GridWindow
DisableCellEditControl
(self)¶Disables in-place editing of grid cells.
Equivalent to calling EnableCellEditControl(false).
DisableColResize
(self, col)¶Disable interactive resizing of the specified column.
This method allows one to disable resizing of an individual column in a grid where the columns are otherwise resizable (which is the case by default).
Notice that currently there is no way to make some columns resizable in a grid where columns can’t be resized by default as there doesn’t seem to be any need for this in practice. There is also no way to make the column marked as fixed using this method resizable again because it is supposed that fixed columns are used for static parts of the grid and so should remain fixed during the entire grid lifetime.
Also notice that disabling interactive column resizing will not prevent the program from changing the column size.
col (int) –
See also
DisableDragColMove
(self)¶Disables column moving by dragging with the mouse.
Equivalent to passing False
to EnableDragColMove
.
DisableDragColSize
(self)¶Disables column sizing by dragging with the mouse.
Equivalent to passing False
to EnableDragColSize
.
DisableDragGridSize
(self)¶Disable mouse dragging of grid lines to resize rows and columns.
Equivalent to passing False
to EnableDragGridSize
DisableDragRowMove
(self)¶Disables row moving by dragging with the mouse.
Equivalent to passing False
to EnableDragRowMove
.
New in version 4.1/wxWidgets-3.1.7.
DisableDragRowSize
(self)¶Disables row sizing by dragging with the mouse.
Equivalent to passing False
to EnableDragRowSize
.
DisableHidingColumns
(self)¶Disables column hiding from the header popup menu.
Equivalent to passing False
to EnableHidingColumns
.
New in version 4.1/wxWidgets-3.1.3.
DisableRowResize
(self, row)¶Disable interactive resizing of the specified row.
This is the same as DisableColResize
but for rows.
row (int) –
See also
DrawCellHighlight
(self, dc, attr)¶dc (wx.DC) –
attr (wx.grid.GridCellAttr) –
DrawTextRectangle
(self, *args, **kw)¶DrawTextRectangle (self, dc, text, rect, horizontalAlignment=ALIGN_LEFT, verticalAlignment=ALIGN_TOP, textOrientation=HORIZONTAL)
DrawTextRectangle (self, dc, lines, rect, horizontalAlignment=ALIGN_LEFT, verticalAlignment=ALIGN_TOP, textOrientation=HORIZONTAL)
EnableCellEditControl
(self, enable=True)¶Enables or disables in-place editing of grid cell data.
Enabling in-place editing generates wxEVT_GRID_EDITOR_SHOWN
and, if it isn’t vetoed by the application, shows the in-place editor which allows the user to change the cell value.
Disabling in-place editing does nothing if the in-place editor isn’t currently shown, otherwise the wxEVT_GRID_EDITOR_HIDDEN
event is generated but, unlike the “shown” event, it can’t be vetoed and the in-place editor is dismissed unconditionally.
Note that it is an error to call this function if the current cell is read-only, use CanEnableCellControl
to check for this precondition.
enable (bool) –
EnableDragCell
(self, enable=True)¶Enables or disables cell dragging with the mouse.
enable (bool) –
EnableDragColMove
(self, enable=True)¶Enables or disables column moving by dragging with the mouse.
Note that reordering columns by dragging them is currently not supported when the grid has any frozen columns (see FreezeTo
) and if this method is called with enable equal to True
in this situation, it returns False
without doing anything. Otherwise it returns True
to indicate that it was successful.
enable (bool) –
bool
EnableDragColSize
(self, enable=True)¶Enables or disables column sizing by dragging with the mouse.
enable (bool) –
See also
EnableDragGridSize
(self, enable=True)¶Enables or disables row and column resizing by dragging gridlines with the mouse.
enable (bool) –
EnableDragRowMove
(self, enable=True)¶Enables or disables row moving by dragging with the mouse.
Note that reordering rows by dragging them is currently not supported when the grid has any frozen columns (see FreezeTo
) and if this method is called with enable equal to True
in this situation, it returns False
without doing anything. Otherwise it returns True
to indicate that it was successful.
enable (bool) –
bool
New in version 4.1/wxWidgets-3.1.7.
EnableDragRowSize
(self, enable=True)¶Enables or disables row sizing by dragging with the mouse.
enable (bool) –
See also
EnableEditing
(self, edit)¶Makes the grid globally editable or read-only.
If the edit argument is False
this function sets the whole grid as read-only. If the argument is True
the grid is set to the default state where cells may be editable. In the default state you can set single grid cells and whole rows and columns to be editable or read-only via wx.grid.GridCellAttr.SetReadOnly
. For single cells you can also use the shortcut function SetReadOnly
.
For more information about controlling grid cell attributes see the wx.grid.GridCellAttr class and the Grid Overview.
edit (bool) –
EnableGridLines
(self, enable=True)¶Turns the drawing of grid lines on or off.
enable (bool) –
EnableHidingColumns
(self, enable=True)¶Enables or disables column hiding from the header popup menu.
Note that currently the popup menu can only be shown when using wx.HeaderCtrl, i.e. if UseNativeColHeader
had been called.
If the native header is not used, this method always simply returns False
without doing anything, as hiding columns is not supported anyhow. If enable value is the same as CanHideColumns
, it also returns False
to indicate that nothing was done. Otherwise, it returns True
to indicate that the value of this option was successfully changed.
The main use case for this method is to disallow hiding the columns interactively when using the native header.
enable (bool) –
bool
New in version 4.1/wxWidgets-3.1.3.
See also
EndBatch
(self)¶Decrements the grid’s batch count.
When the count is greater than zero repainting of the grid is suppressed. Each previous call to BeginBatch
must be matched by a later call to EndBatch
. Code that does a lot of grid modification can be enclosed between BeginBatch
and EndBatch
calls to avoid screen flicker. The final EndBatch
will cause the grid to be repainted.
See also
ForceRefresh
(self)¶Causes immediate repainting of the grid.
Use this instead of the usual wx.Window.Refresh
.
FreezeTo
(self, *args, **kw)¶FreezeTo (self, row, col)
Sets or resets the frozen columns and rows.
row – The number of rows to freeze, 0 means to unfreeze all rows.
col – The number of columns to freeze, 0 means to unfreeze all columns.
bool
Note that this method doesn’t do anything, and returns False
, if any of the following conditions are True
:
Either row or col are out of range
Size of the frozen area would be bigger than the current viewing area
There are any merged cells in the area to be frozen
Grid uses a native header control (see UseNativeColHeader
)
(some of these limitations could be lifted in the future).
True
on success or False
if it failed.
New in version 4.1/wxWidgets-3.1.3.
FreezeTo (self, coords)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
coords (wx.grid.GridCellCoords) –
bool
GetBatchCount
(self)¶Returns the number of times that BeginBatch
has been called without (yet) matching calls to EndBatch
.
While the grid’s batch count is greater than zero the display will not be updated.
int
GetCellAlignment
(self, row, col)¶Sets the arguments to the horizontal and vertical text alignment values for the grid cell at the specified location.
Horizontal alignment will be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
.
Vertical alignment will be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
row (int) –
col (int) –
tuple
( horiz, vert )
GetCellBackgroundColour
(self, row, col)¶Returns the background colour of the cell at the specified location.
row (int) –
col (int) –
Colour
GetCellEditor
(self, row, col)¶Returns a pointer to the editor for the cell at the specified location.
See wx.grid.GridCellEditor and the Grid Overview for more information about cell editors and renderers.
The caller must call DecRef() on the returned pointer.
row (int) –
col (int) –
GetCellFitMode
(self, row, col)¶Returns the cell fitting mode.
row (int) –
col (int) –
New in version 4.1/wxWidgets-3.1.4.
See also
GetCellFont
(self, row, col)¶Returns the font for text in the grid cell at the specified location.
row (int) –
col (int) –
Font
GetCellHighlightColour
(self)¶Colour
GetCellHighlightPenWidth
(self)¶int
GetCellHighlightROPenWidth
(self)¶int
GetCellOverflow
(self, row, col)¶Returns True
if the cell value can overflow.
This is identical to calling GetCellFitMode
and using wx.grid.GridFitMode.IsOverflow
on the returned value.
Prefer using GetCellFitMode
directly in the new code.
row (int) –
col (int) –
bool
GetCellRenderer
(self, row, col)¶Returns a pointer to the renderer for the grid cell at the specified location.
See wx.grid.GridCellRenderer and the Grid Overview for more information about cell editors and renderers.
The caller must call DecRef() on the returned pointer.
row (int) –
col (int) –
GetCellSize
(self, *args, **kw)¶GetCellSize (self, row, col, num_rows, num_cols)
Get the size of the cell in number of cells covered by it.
For normal cells, the function fills both num_rows and num_cols with 1 and returns CellSpan_None. For cells which span multiple cells, i.e. for which SetCellSize
had been called, the returned values are the same ones as were passed to SetCellSize
call and the function return value is CellSpan_Main.
More unexpectedly, perhaps, the returned values may be negative for the cells which are inside a span covered by a cell occupying multiple rows or columns. They correspond to the offset of the main cell of the span from the cell passed to this functions and the function returns CellSpan_Inside value to indicate this.
As an example, consider a 3x3 grid with the cell (1, 1) (the one in the middle) having a span of 2 rows and 2 columns, i.e. the grid looks like
+----+----+----+
| | | |
+----+----+----+
| | |
+----+ |
| | |
+----+----+----+
Then the function returns 2 and 2 in num_rows and num_cols for the cell (1, 1) itself and -1 and -1 for the cell (2, 2) as well as -1 and 0 for the cell (2, 1).
row (int) – The row of the cell.
col (int) – The column of the cell.
num_rows (int) – Pointer to variable receiving the number of rows, must not be None
.
num_cols (int) – Pointer to variable receiving the number of columns, must not be None
.
The kind of this cell span (the return value is new in wxWidgets 2.9.1, this function was in previous wxWidgets versions).
GetCellSize (self, coords)
Get the number of rows and columns allocated for this cell.
This overload doesn’t return a CellSpan value but the values returned may still be negative, see GetCellSize(int, int, int, int ) for details.
coords (wx.grid.GridCellCoords) –
Size
GetCellTextColour
(self, row, col)¶Returns the text colour for the grid cell at the specified location.
row (int) –
col (int) –
Colour
GetCellValue
(self, *args, **kw)¶Returns the string contained in the cell at the specified location.
For simple applications where a grid object automatically uses a default grid table of string values you use this function together with SetCellValue
to access cell values. For more complex applications where you have derived your own grid table class that contains various data types (e.g. numeric, boolean or user-defined custom types) then you only use this function for those cells that contain string values.
See wx.grid.GridTableBase.CanGetValueAs
and the Grid Overview for more information.
GetCellValue (self, row, col)
row (int) –
col (int) –
string
GetCellValue (self, coords)
coords (wx.grid.GridCellCoords) –
string
GetClassDefaultAttributes
(variant=WINDOW_VARIANT_NORMAL)¶variant (WindowVariant) –
VisualAttributes
GetColAt
(self, colPos)¶Returns the column ID
of the specified column position.
colPos (int) –
int
GetColGridLinePen
(self, col)¶Returns the pen used for vertical grid lines.
This virtual function may be overridden in derived classes in order to change the appearance of individual grid lines for the given column col.
See GetRowGridLinePen
for an example.
col (int) –
Pen
GetColLabelAlignment
(self)¶Sets the arguments to the current column label alignment values.
Horizontal alignment will be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
.
Vertical alignment will be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
tuple
( horiz, vert )
GetColLabelSize
(self)¶Returns the current height of the column labels.
int
GetColLabelTextOrientation
(self)¶Returns the orientation of the column labels (either HORIZONTAL
or VERTICAL
).
int
GetColLabelValue
(self, col)¶Returns the specified column label.
The default grid table class provides column labels of the form A,B…Z,AA,AB…ZZ,AAA… If you are using a custom grid table you can override wx.grid.GridTableBase.GetColLabelValue
to provide your own labels.
col (int) –
string
GetColLeft
(self, col)¶Returns the coordinate of the left border specified column.
col (int) –
int
GetColMinimalAcceptableWidth
(self)¶Returns the minimal width to which a column may be resized.
Use SetColMinimalAcceptableWidth
to change this value globally or SetColMinimalWidth
to do it for individual columns.
int
See also
GetColMinimalWidth
(self, col)¶Get the minimal width of the given column/row.
The value returned by this function may be different from that returned by GetColMinimalAcceptableWidth
if SetColMinimalWidth
had been called for this column.
col (int) –
int
GetColPos
(self, colID)¶Returns the position of the specified column.
colID (int) –
int
GetColRight
(self, col)¶Returns the coordinate of the right border specified column.
col (int) –
int
GetColSize
(self, col)¶Returns the width of the specified column.
col (int) –
int
GetColSizes
(self)¶Get size information for all columns at once.
This method is useful when the information about all column widths needs to be saved. The widths can be later restored using SetColSizes
.
See also
GetCornerLabelAlignment
(self, horiz, vert)¶Sets the arguments to the current corner label alignment values.
Horizontal alignment will be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
.
Vertical alignment will be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
horiz (int) –
vert (int) –
New in version 4.1/wxWidgets-3.1.2.
GetCornerLabelTextOrientation
(self)¶Returns the orientation of the corner label (either HORIZONTAL
or VERTICAL
).
int
New in version 4.1/wxWidgets-3.1.2.
GetCornerLabelValue
(self)¶Returns the (top-left) corner label.
string
New in version 4.1/wxWidgets-3.1.2.
GetDefaultCellAlignment
(self)¶Returns the default cell alignment.
Horizontal alignment will be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
.
Vertical alignment will be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
tuple
( horiz, vert )
See also
GetDefaultCellBackgroundColour
(self)¶Returns the current default background colour for grid cells.
Colour
GetDefaultCellFitMode
(self)¶Returns the default cell fitting mode.
The default mode is “overflow”, but can be modified using SetDefaultCellFitMode
.
New in version 4.1/wxWidgets-3.1.4.
See also
GetDefaultCellFont
(self)¶Returns the current default font for grid cell text.
Font
GetDefaultCellOverflow
(self)¶Returns True
if the cells can overflow by default.
This is identical to calling GetDefaultCellFitMode
and using wx.grid.GridFitMode.IsOverflow
on the returned value.
Prefer using GetDefaultCellFitMode
directly in the new code.
bool
GetDefaultCellTextColour
(self)¶Returns the current default colour for grid cell text.
Colour
GetDefaultColLabelSize
(self)¶Returns the default height for column labels.
int
GetDefaultColSize
(self)¶Returns the current default width for grid columns.
int
GetDefaultEditor
(self)¶Returns a pointer to the current default grid cell editor.
See wx.grid.GridCellEditor and the Grid Overview for more information about cell editors and renderers.
GetDefaultEditorForCell
(self, *args, **kw)¶Returns the default editor for the specified cell.
The base class version returns the editor appropriate for the current cell type but this method may be overridden in the derived classes to use custom editors for some cells by default.
Notice that the same may be achieved in a usually simpler way by associating a custom editor with the given cell or cells.
The caller must call DecRef() on the returned pointer.
GetDefaultEditorForCell (self, row, col)
row (int) –
col (int) –
GetDefaultEditorForCell (self, c)
c (wx.grid.GridCellCoords) –
GetDefaultEditorForType
(self, typeName)¶Returns the default editor for the cells containing values of the given type.
The base class version returns the editor which was associated with the specified typeName when it was registered RegisterDataType
but this function may be overridden to return something different. This allows overriding an editor used for one of the standard types.
The caller must call DecRef() on the returned pointer.
typeName (string) –
GetDefaultGridLinePen
(self)¶Returns the pen used for grid lines.
This virtual function may be overridden in derived classes in order to change the appearance of grid lines. Note that currently the pen width must be 1.
Pen
See also
GetDefaultRenderer
(self)¶Returns a pointer to the current default grid cell renderer.
See wx.grid.GridCellRenderer and the Grid Overview for more information about cell editors and renderers.
The caller must call DecRef() on the returned pointer.
GetDefaultRendererForCell
(self, row, col)¶Returns the default renderer for the given cell.
The base class version returns the renderer appropriate for the current cell type but this method may be overridden in the derived classes to use custom renderers for some cells by default.
The caller must call DecRef() on the returned pointer.
row (int) –
col (int) –
GetDefaultRendererForType
(self, typeName)¶Returns the default renderer for the cell containing values of the given type.
typeName (string) –
See also
GetDefaultRowLabelSize
(self)¶Returns the default width for the row labels.
int
GetDefaultRowSize
(self)¶Returns the current default height for grid rows.
int
GetFirstFullyVisibleColumn
(self)¶Returns the leftmost column of the current visible area.
Returns -1 if the grid doesn’t have any columns.
int
GetFirstFullyVisibleRow
(self)¶Returns the topmost row of the current visible area.
Returns -1 if the grid doesn’t have any rows.
int
GetFrozenColGridWindow
(self)¶Return the columns grid window containing column frozen cells.
This window is shown only when there are frozen columns.
Window
New in version 4.1/wxWidgets-3.1.3.
GetFrozenCornerGridWindow
(self)¶Return the corner grid window containing frozen cells.
This window is shown only when there are frozen rows and columns.
Window
New in version 4.1/wxWidgets-3.1.3.
GetFrozenRowGridWindow
(self)¶Return the rows grid window containing row frozen cells.
This window is shown only when there are frozen rows.
Window
New in version 4.1/wxWidgets-3.1.3.
GetGridColHeader
(self)¶Return the header control used for column labels display.
This function can only be called if UseNativeColHeader
had been called.
HeaderCtrl
See also
GetGridColLabelWindow
(self)¶Return the column labels window.
This window is not shown if the columns labels were hidden using HideColLabels
.
Depending on whether UseNativeColHeader
was called or not this can be either a wx.HeaderCtrl or a plain wx.Window. This function returns a valid window pointer in either case but in the former case you can also use GetGridColHeader
to access it if you need HeaderCtrl-specific functionality.
Window
GetGridCornerLabelWindow
(self)¶Return the window in the top left grid corner.
This window is shown only of both columns and row labels are shown and normally doesn’t contain anything. Clicking on it is handled by wx.grid.Grid however and can be used to select the entire grid.
Window
GetGridCursorCol
(self)¶Returns the current grid cell column position.
int
See also
GetGridCursorCoords
(self)¶Returns the current grid cursor position.
If grid cursor doesn’t have any valid position (e.g. if the grid is completely empty and doesn’t have any rows or columns), returns GridNoCellCoords
which has both row and columns set to -1
.
New in version 4.1/wxWidgets-3.1.3.
GetGridCursorRow
(self)¶Returns the current grid cell row position.
int
See also
GetGridLineColour
(self)¶Returns the colour used for grid lines.
Colour
See also
GetGridRowLabelWindow
(self)¶Return the row labels window.
This window is not shown if the row labels were hidden using HideRowLabels
.
Window
GetGridWindow
(self)¶Return the main grid window containing the grid cells.
This window is always shown.
Window
GetGridWindowOffset
(self, gridWindow)¶This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
gridWindow (wx.grid.GridWindow) –
Point
GetLabelBackgroundColour
(self)¶Returns the colour used for the background of row and column labels.
Colour
GetLabelFont
(self)¶Returns the font used for row and column labels.
Font
GetLabelTextColour
(self)¶Returns the colour used for row and column label text.
Colour
GetNumberCols
(self)¶Returns the total number of grid columns.
This is the same as the number of columns in the underlying grid table.
int
GetNumberFrozenCols
(self)¶Returns the number of frozen grid columns.
If there are no frozen columns, returns 0.
int
New in version 4.1/wxWidgets-3.1.3.
See also
GetNumberFrozenRows
(self)¶Returns the number of frozen grid rows.
If there are no frozen rows, returns 0.
int
New in version 4.1/wxWidgets-3.1.3.
See also
GetNumberRows
(self)¶Returns the total number of grid rows.
This is the same as the number of rows in the underlying grid table.
int
GetOrCreateCellAttr
(self, row, col)¶Returns the attribute for the given cell creating one if necessary.
If the cell already has an attribute, it is returned. Otherwise a new attribute is created, associated with the cell and returned. In any case the caller must call DecRef() on the returned pointer.
Prefer to use GetOrCreateCellAttrPtr
to avoid the need to call DecRef() on the returned pointer.
This function may only be called if CanHaveAttributes
returns True
.
row (int) –
col (int) –
GetOrCreateCellAttrPtr
(self, row, col)¶Returns the attribute for the given cell creating one if necessary.
This method is identical to GetOrCreateCellAttr
, but returns a smart pointer, which frees the caller from the need to call DecRef() manually.
row (int) –
col (int) –
wx.grid.GridCellAttrPtr
New in version 4.1/wxWidgets-3.1.4.
GetRowAt
(self, rowPos)¶Returns the row ID
of the specified row position.
rowPos (int) –
int
New in version 4.1/wxWidgets-3.1.7.
GetRowGridLinePen
(self, row)¶Returns the pen used for horizontal grid lines.
This virtual function may be overridden in derived classes in order to change the appearance of individual grid line for the given row.
Example:
# in a grid displaying music notation, use a solid black pen between
# octaves (C0=row 127, C1=row 115 etc.)
def GetRowGridLinePen(self, row):
if row % 12 == 7:
return wx.Pen(wx.BLACK, 1, wx.SOLID)
else:
return self.GetDefaultGridLinePen()
row (int) –
Pen
GetRowLabelAlignment
(self)¶Returns the alignment used for row labels.
Horizontal alignment will be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
.
Vertical alignment will be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
tuple
( horiz, vert )
GetRowLabelSize
(self)¶Returns the current width of the row labels.
int
GetRowLabelValue
(self, row)¶Returns the specified row label.
The default grid table class provides numeric row labels. If you are using a custom grid table you can override wx.grid.GridTableBase.GetRowLabelValue
to provide your own labels.
row (int) –
string
GetRowMinimalAcceptableHeight
(self)¶Returns the minimal size to which rows can be resized.
Use SetRowMinimalAcceptableHeight
to change this value globally or SetRowMinimalHeight
to do it for individual cells.
int
See also
GetRowMinimalHeight
(self, col)¶Returns the minimal size for the given column.
The value returned by this function may be different from that returned by GetRowMinimalAcceptableHeight
if SetRowMinimalHeight
had been called for this row.
col (int) –
int
GetRowPos
(self, rowID)¶Returns the position of the specified row.
rowID (int) –
int
New in version 4.1/wxWidgets-3.1.7.
GetRowSize
(self, row)¶Returns the height of the specified row.
row (int) –
int
GetRowSizes
(self)¶Get size information for all row at once.
See also
GetScrollLineX
(self)¶Returns the number of pixels per horizontal scroll increment.
The default is 15.
int
See also
GetScrollLineY
(self)¶Returns the number of pixels per vertical scroll increment.
The default is 15.
int
See also
GetSelectedBlocks
(self)¶Returns a range of grid selection blocks.
The returned range can be iterated over, e.g. with C++11
range-for loop:
# For Python the returned GridBlocks object has a __iter__ method so iterating
# in the Python way is possible.
do_something(block)
Notice that the blocks returned by this method are not ordered in any particular way and may overlap. For grids using rows or columns-only selection modes, GetSelectedRowBlocks
or GetSelectedColBlocks
can be more convenient, as they return ordered and non-overlapping blocks.
New in version 4.1/wxWidgets-3.1.4.
GetSelectedCells
(self)¶Returns an array of individually selected cells.
Notice that this array does not contain all the selected cells in general as it doesn’t include the cells selected as part of column, row or block selection. You must use this method, GetSelectedCols
, GetSelectedRows
and GetSelectionBlockTopLeft
and GetSelectionBlockBottomRight
methods to obtain the entire selection in general.
Please notice this behaviour is by design and is needed in order to support grids of arbitrary size (when an entire column is selected in a grid with a million of columns, we don’t want to create an array with a million of entries in this function, instead it returns an empty array and GetSelectedCols
returns an array containing one element).
The function can be slow for the big grids, use GetSelectedBlocks
in the new code.
GridCellCoordsArray
GetSelectedColBlocks
(self)¶Returns an ordered range of non-overlapping selected columns.
This method is symmetric to GetSelectedRowBlocks
, but is useful only in GridSelectColumns selection mode.
PyObject
New in version 4.1/wxWidgets-3.1.4.
See also
GetSelectedCols
(self)¶Returns an array of selected columns.
Please notice that this method alone is not sufficient to find all the selected columns as it contains only the columns which were individually selected but not those being part of the block selection or being selected in virtue of all of their cells being selected individually, please see GetSelectedCells
for more details.
The function can be slow for the big grids, use GetSelectedBlocks
in the new code.
list of integers
GetSelectedRowBlocks
(self)¶Returns an ordered range of non-overlapping selected rows.
For the grids using GridSelectRows selection mode, returns the possibly empty vector containing the coordinates of non-overlapping selected row blocks in the natural order, i.e. from smallest to the biggest row indices.
To see the difference between this method and GetSelectedBlocks
, consider the case when the user selects rows 2..4 in the grid and then also selects (using Ctrl/Shift keys) the rows 1..3. Iterating over the result of GetSelectedBlocks
would yield two blocks directly corresponding to the users selection, while this method returns a vector with a single element corresponding to the rows 1..4.
This method returns empty vector for the other selection modes.
PyObject
New in version 4.1/wxWidgets-3.1.4.
See also
GetSelectedRows
(self)¶Returns an array of selected rows.
Please notice that this method alone is not sufficient to find all the selected rows as it contains only the rows which were individually selected but not those being part of the block selection or being selected in virtue of all of their cells being selected individually, please see GetSelectedCells
for more details.
The function can be slow for the big grids, use GetSelectedBlocks
in the new code.
list of integers
GetSelectionBackground
(self)¶Returns the colour used for drawing the selection background.
Colour
GetSelectionBlockBottomRight
(self)¶Returns an array of the bottom right corners of blocks of selected cells.
Please see GetSelectedCells
for more information about the selection representation in wx.grid.Grid.
The function can be slow for the big grids, use GetSelectedBlocks
in the new code.
GridCellCoordsArray
See also
GetSelectionBlockTopLeft
(self)¶Returns an array of the top left corners of blocks of selected cells.
Please see GetSelectedCells
for more information about the selection representation in wx.grid.Grid.
The function can be slow for the big grids, use GetSelectedBlocks
in the new code.
GridCellCoordsArray
See also
GetSelectionForeground
(self)¶Returns the colour used for drawing the selection foreground.
Colour
GetSelectionMode
(self)¶Returns the current selection mode.
See also
GetSortingColumn
(self)¶Return the column in which the sorting indicator is currently displayed.
Returns NOT_FOUND
if sorting indicator is not currently displayed at all.
int
See also
GetTable
(self)¶Returns a base pointer to the current table object.
The returned pointer is still owned by the grid.
GoToCell
(self, *args, **kw)¶Make the given cell current and ensure it is visible.
This method is equivalent to calling MakeCellVisible
and SetGridCursor
and so, as with the latter, a wxEVT_GRID_SELECT_CELL
event is generated by it and the selected cell doesn’t change if the event is vetoed.
GoToCell (self, row, col)
row (int) –
col (int) –
GoToCell (self, coords)
coords (wx.grid.GridCellCoords) –
GridLinesEnabled
(self)¶Returns True
if drawing of grid lines is turned on, False
otherwise.
bool
HideCellEditControl
(self)¶Hides the in-place cell edit control.
HideCol
(self, col)¶Hides the specified column.
To show the column later you need to call SetColSize
with non-0 width or ShowCol
to restore the previous column width.
If the column is already hidden, this method doesn’t do anything.
col (int) – The column index.
HideColLabels
(self)¶Hides the column labels by calling SetColLabelSize
with a size of 0.
The labels can be shown again by calling SetColLabelSize
with a height greater than 0.
Note that when the column labels are hidden, the grid won’t have any visible border on the top side, which may result in a less than ideal appearance. Because of this, you may want to create the grid window with a border style, such as BORDER_SIMPLE
, when you don’t plan to show the column labels for it.
See also
HideRow
(self, col)¶Hides the specified row.
To show the row later you need to call SetRowSize
with non-0 width or ShowRow
to restore its original height.
If the row is already hidden, this method doesn’t do anything.
col (int) – The row index.
HideRowLabels
(self)¶Hides the row labels by calling SetRowLabelSize
with a size of 0.
The labels can be shown again by calling SetRowLabelSize
with a width greater than 0.
See HideColLabels
for a note explaining why you may want to use a border with a grid without the row labels.
InsertCols
(self, pos=0, numCols=1, updateLabels=True)¶Inserts one or more new columns into a grid with the first new column at the specified position.
Notice that inserting the columns in the grid requires grid table cooperation: when this method is called, grid object begins by requesting the underlying grid table to insert new columns. If this is successful the table notifies the grid and the grid updates the display. For a default grid (one where you have called CreateGrid
) this process is automatic. If you are using a custom grid table (specified with SetTable
or AssignTable
) then you must override wx.grid.GridTableBase.InsertCols
in your derived table class.
pos (int) – The position which the first newly inserted column will have.
numCols (int) – The number of columns to insert.
updateLabels (bool) – Currently not used.
bool
True
if the columns were successfully inserted, False
if an error occurred (most likely the table couldn’t be updated).
InsertRows
(self, pos=0, numRows=1, updateLabels=True)¶Inserts one or more new rows into a grid with the first new row at the specified position.
Notice that you must implement wx.grid.GridTableBase.InsertRows
if you use a grid with a custom table, please see InsertCols
for more information.
pos (int) – The position which the first newly inserted row will have.
numRows (int) – The number of rows to insert.
updateLabels (bool) – Currently not used.
bool
True
if the rows were successfully inserted, False
if an error occurred (most likely the table couldn’t be updated).
IsCellEditControlEnabled
(self)¶Returns True
if the in-place edit control is currently enabled.
bool
IsCellEditControlShown
(self)¶Returns True
if the in-place edit control is currently shown.
bool
See also
IsColShown
(self, col)¶Returns True
if the specified column is not currently hidden.
col (int) –
bool
IsCurrentCellReadOnly
(self)¶Returns True
if the current cell is read-only.
bool
See also
IsEditable
(self)¶Returns False
if the whole grid has been set as read-only or True
otherwise.
See EnableEditing
for more information about controlling the editing status of grid cells.
bool
IsInSelection
(self, *args, **kw)¶Returns True
if the given cell is selected.
IsInSelection (self, row, col)
row (int) –
col (int) –
bool
IsInSelection (self, coords)
coords (wx.grid.GridCellCoords) –
bool
IsReadOnly
(self, row, col)¶Returns True
if the cell at the specified location can’t be edited.
row (int) –
col (int) –
bool
See also
IsRowShown
(self, row)¶Returns True
if the specified row is not currently hidden.
row (int) –
bool
IsSelection
(self)¶Returns True
if there are currently any selected cells, rows, columns or blocks.
bool
IsSortOrderAscending
(self)¶Return True
if the current sorting order is ascending or False
if it is descending.
It only makes sense to call this function if GetSortingColumn
returns a valid column index and not NOT_FOUND
.
bool
See also
IsSortingBy
(self, col)¶Return True
if this column is currently used for sorting.
col (int) –
bool
See also
IsUsingNativeHeader
(self)¶Return True
if native header control is currently being used.
bool
New in version 4.1/wxWidgets-3.1.4.
IsVisible
(self, *args, **kw)¶Returns True
if a cell is either entirely or at least partially visible in the grid window.
By default, the cell must be entirely visible for this function to return True
but if wholeCellVisible is False
, the function returns True
even if the cell is only partially visible.
IsVisible (self, row, col, wholeCellVisible=True)
row (int) –
col (int) –
wholeCellVisible (bool) –
bool
IsVisible (self, coords, wholeCellVisible=True)
coords (wx.grid.GridCellCoords) –
wholeCellVisible (bool) –
bool
MakeCellVisible
(self, *args, **kw)¶Brings the specified cell into the visible grid cell area with minimal scrolling.
Does nothing if the cell is already visible.
MakeCellVisible (self, row, col)
row (int) –
col (int) –
MakeCellVisible (self, coords)
coords (wx.grid.GridCellCoords) –
MoveCursorDown
(self, expandSelection)¶Moves the grid cursor down by one row.
If a block of cells was previously selected it will expand if the argument is True
or be cleared if the argument is False
.
expandSelection (bool) –
bool
MoveCursorDownBlock
(self, expandSelection)¶Moves the grid cursor down in the current column such that it skips to the beginning or end of a block of non-empty cells.
If a block of cells was previously selected it will expand if the argument is True
or be cleared if the argument is False
.
expandSelection (bool) –
bool
MoveCursorLeft
(self, expandSelection)¶Moves the grid cursor left by one column.
If a block of cells was previously selected it will expand if the argument is True
or be cleared if the argument is False
.
expandSelection (bool) –
bool
MoveCursorLeftBlock
(self, expandSelection)¶Moves the grid cursor left in the current row such that it skips to the beginning or end of a block of non-empty cells.
If a block of cells was previously selected it will expand if the argument is True
or be cleared if the argument is False
.
expandSelection (bool) –
bool
MoveCursorRight
(self, expandSelection)¶Moves the grid cursor right by one column.
If a block of cells was previously selected it will expand if the argument is True
or be cleared if the argument is False
.
expandSelection (bool) –
bool
MoveCursorRightBlock
(self, expandSelection)¶Moves the grid cursor right in the current row such that it skips to the beginning or end of a block of non-empty cells.
If a block of cells was previously selected it will expand if the argument is True
or be cleared if the argument is False
.
expandSelection (bool) –
bool
MoveCursorUp
(self, expandSelection)¶Moves the grid cursor up by one row.
If a block of cells was previously selected it will expand if the argument is True
or be cleared if the argument is False
.
expandSelection (bool) –
bool
MoveCursorUpBlock
(self, expandSelection)¶Moves the grid cursor up in the current column such that it skips to the beginning or end of a block of non-empty cells.
If a block of cells was previously selected it will expand if the argument is True
or be cleared if the argument is False
.
expandSelection (bool) –
bool
MovePageDown
(self)¶Moves the grid cursor down by some number of rows so that the previous bottom visible row becomes the top visible row.
bool
MovePageUp
(self)¶Moves the grid cursor up by some number of rows so that the previous top visible row becomes the bottom visible row.
bool
ProcessTableMessage
(self, msg)¶Receive and handle a message from the table.
msg (wx.grid.GridTableMessage) –
bool
RefreshAttr
(self, row, col)¶Invalidates the cached attribute for the given cell.
For efficiency reasons, wx.grid.Grid may cache the recently used attributes (currently it caches only the single most recently used one, in fact) which can result in the cell appearance not being refreshed even when the attribute returned by your custom GridCellAttrProvider-derived class has changed. To force the grid to refresh the cell attribute, this function may be used. Notice that calling it will not result in actually redrawing the cell, you still need to call wx.Window.RefreshRect
to invalidate the area occupied by the cell in the window to do this. Also note that you don’t need to call this function if you store the attributes in wx.grid.Grid itself, i.e. use its SetAttr
and similar methods, it is only useful when using a separate custom attributes provider.
row (int) – The row of the cell whose attribute needs to be queried again.
col (int) – The column of the cell whose attribute needs to be queried again.
New in version 2.9.2.
RefreshBlock
(self, *args, **kw)¶RefreshBlock (self, topLeft, bottomRight)
Redraw all the cells in the given block.
Refresh the block of cells with the given corners.
If the bottom right corner coordinates are invalid, i.e. set to -1
, the top left corner coordinates are used for it, i.e. just a single cell is refreshed. If the top left corner coordinates are invalid as well, the function simply returns without doing anything. Note, however, that both coordinates need to be valid or invalid simultaneously, i.e. setting the top row to -1
but using a valid value for the left column is unsupported and would result in an assertion failure.
topLeft (wx.grid.GridCellCoords) –
bottomRight (wx.grid.GridCellCoords) –
New in version 4.1/wxWidgets-3.1.3.
RefreshBlock (self, topRow, leftCol, bottomRow, rightCol)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
topRow (int) –
leftCol (int) –
bottomRow (int) –
rightCol (int) –
RegisterDataType
(self, typeName, renderer, editor)¶Register a new data type.
The data types allow to naturally associate specific renderers and editors to the cells containing values of the given type. For example, the grid automatically registers a data type with the name GRID_VALUE_STRING
which uses wx.grid.GridCellStringRenderer and wx.grid.GridCellTextEditor as its renderer and editor respectively – this is the data type used by all the cells of the default wx.grid.GridStringTable, so this renderer and editor are used by default for all grid cells.
However if a custom table returns GRID_VALUE_BOOL
from its wx.grid.GridTableBase.GetTypeName
method, then wx.grid.GridCellBoolRenderer and wx.grid.GridCellBoolEditor are used for it because the grid also registers a boolean data type with this name.
And as this mechanism is completely generic, you may register your own data types using your own custom renderers and editors. Just remember that the table must identify a cell as being of the given type for them to be used for this cell.
typeName (string) – Name of the new type. May be any string, but if the type name is the same as the name of an already registered type, including one of the standard ones (which are GRID_VALUE_STRING
, GRID_VALUE_BOOL
, GRID_VALUE_NUMBER
, GRID_VALUE_FLOAT
, GRID_VALUE_CHOICE
and GRID_VALUE_DATE
), then the new registration information replaces the previously used renderer and editor.
renderer (wx.grid.GridCellRenderer) – The renderer to use for the cells of this type. Its ownership is taken by the grid, i.e. it will call DecRef() on this pointer when it doesn’t need it any longer.
editor (wx.grid.GridCellEditor) – The editor to use for the cells of this type. Its ownership is also taken by the grid.
Render
(self, dc, pos=DefaultPosition, size=DefaultSize, topLeft=GridCellCoords(-1, -1), bottomRight=GridCellCoords(-1, -1), style=GRID_DRAW_DEFAULT)¶Draws part or all of a wx.grid.Grid on a wx.DC for printing or display.
Pagination can be accomplished by using sequential Render
calls with appropriate values in wx.grid.GridCellCoords topLeft and bottomRight.
pos (wx.Point) – The position on the wx.DC where rendering should begin. If not specified drawing will begin at the wx.DC MaxX() and MaxY().
size (wx.Size) – The size of the area on the wx.DC that the rendered wx.grid.Grid should occupy. If not specified the drawing will be scaled to fit the available dc width or height. The wx.grid.Grid’s aspect ratio is maintained whether or not size is specified.
topLeft (wx.grid.GridCellCoords) – The top left cell of the block to be drawn. Defaults to ( 0, 0 ).
bottomRight (wx.grid.GridCellCoords) – The bottom right cell of the block to be drawn. Defaults to row and column counts.
style (int) – A combination of values from GridRenderStyle.
New in version 2.9.4.
ResetColPos
(self)¶Resets the position of the columns to the default.
ResetRowPos
(self)¶Resets the position of the rows to the default.
New in version 4.1/wxWidgets-3.1.7.
SaveEditControlValue
(self)¶Sets the value of the current grid cell to the current in-place edit control value.
This is called automatically when the grid cursor moves from the current cell to a new cell. It is also a good idea to call this function when closing a grid since any edits to the final cell location will not be saved otherwise.
SelectAll
(self)¶Selects all cells in the grid.
SelectBlock
(self, *args, **kw)¶Selects a rectangular block of cells.
If addToSelected is False
then any existing selection will be deselected; if True
the column will be added to the existing selection.
SelectBlock (self, topRow, leftCol, bottomRow, rightCol, addToSelected=False)
topRow (int) –
leftCol (int) –
bottomRow (int) –
rightCol (int) –
addToSelected (bool) –
SelectBlock (self, topLeft, bottomRight, addToSelected=False)
topLeft (wx.grid.GridCellCoords) –
bottomRight (wx.grid.GridCellCoords) –
addToSelected (bool) –
SelectCol
(self, col, addToSelected=False)¶Selects the specified column.
If addToSelected is False
then any existing selection will be deselected; if True
the column will be added to the existing selection.
This method won’t select anything if the current selection mode is GridSelectRows.
col (int) –
addToSelected (bool) –
SelectRow
(self, row, addToSelected=False)¶Selects the specified row.
If addToSelected is False
then any existing selection will be deselected; if True
the row will be added to the existing selection.
This method won’t select anything if the current selection mode is GridSelectColumns.
row (int) –
addToSelected (bool) –
SetAttr
(self, row, col, attr)¶Sets the cell attributes for the specified cell.
The grid takes ownership of the attribute pointer.
See the wx.grid.GridCellAttr class for more information about controlling cell attributes.
row (int) –
col (int) –
attr (wx.grid.GridCellAttr) –
SetCellAlignment
(self, row, col, horiz, vert)¶Sets the horizontal and vertical alignment for grid cell text at the specified location.
Horizontal alignment should be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
.
Vertical alignment should be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
row (int) –
col (int) –
horiz (int) –
vert (int) –
SetCellBackgroundColour
(self, row, col, colour)¶Set the background colour for the given cell or all cells by default.
row (int) –
col (int) –
colour (wx.Colour) –
SetCellEditor
(self, row, col, editor)¶Sets the editor for the grid cell at the specified location.
The grid will take ownership of the pointer.
See wx.grid.GridCellEditor and the Grid Overview for more information about cell editors and renderers.
row (int) –
col (int) –
editor (wx.grid.GridCellEditor) –
SetCellFitMode
(self, row, col, fitMode)¶Specifies the behaviour of the cell contents if it doesn’t fit into the available space.
row (int) –
col (int) –
fitMode (wx.grid.GridFitMode) –
New in version 4.1/wxWidgets-3.1.4.
See also
SetCellFont
(self, row, col, font)¶Sets the font for text in the grid cell at the specified location.
row (int) –
col (int) –
font (wx.Font) –
SetCellHighlightPenWidth
(self, width)¶width (int) –
SetCellHighlightROPenWidth
(self, width)¶width (int) –
SetCellOverflow
(self, row, col, allow)¶Sets the overflow permission of the cell.
Prefer using SetCellFitMode
in the new code.
row (int) –
col (int) –
allow (bool) –
SetCellRenderer
(self, row, col, renderer)¶Sets the renderer for the grid cell at the specified location.
The grid will take ownership of the pointer.
See wx.grid.GridCellRenderer and the Grid Overview for more information about cell editors and renderers.
row (int) –
col (int) –
renderer (wx.grid.GridCellRenderer) –
SetCellSize
(self, row, col, num_rows, num_cols)¶Set the size of the cell.
Specifying a value of more than 1 in num_rows or num_cols will make the cell at (row, col) span the block of the specified size, covering the other cells which would be normally shown in it. Passing 1 for both arguments resets the cell to normal appearance.
row (int) – The row of the cell.
col (int) – The column of the cell.
num_rows (int) – Number of rows to be occupied by this cell, must be >= 1.
num_cols (int) – Number of columns to be occupied by this cell, must be >= 1.
See also
SetCellTextColour
(self, row, col, colour)¶Sets the text colour for the given cell.
row (int) –
col (int) –
colour (wx.Colour) –
SetCellValue
(self, *args, **kw)¶Sets the string value for the cell at the specified location.
For simple applications where a grid object automatically uses a default grid table of string values you use this function together with GetCellValue
to access cell values. For more complex applications where you have derived your own grid table class that contains various data types (e.g. numeric, boolean or user-defined custom types) then you only use this function for those cells that contain string values.
See wx.grid.GridTableBase.CanSetValueAs
and the Grid Overview for more information.
SetCellValue (self, row, col, s)
row (int) –
col (int) –
s (string) –
SetCellValue (self, coords, s)
coords (wx.grid.GridCellCoords) –
s (string) –
SetColAttr
(self, col, attr)¶Sets the cell attributes for all cells in the specified column.
For more information about controlling grid cell attributes see the wx.grid.GridCellAttr cell attribute class and the Grid Overview.
col (int) –
attr (wx.grid.GridCellAttr) –
SetColFormatBool
(self, col)¶Sets the specified column to display boolean values.
col (int) –
See also
SetColFormatCustom
(self, col, typeName)¶Sets the specified column to display data in a custom format.
This method provides an alternative to defining a custom grid table which would return typeName from its GetTypeName() method for the cells in this column: while it doesn’t really change the type of the cells in this column, it does associate the renderer and editor used for the cells of the specified type with them.
See the Grid Overview for more information on working with custom data types.
col (int) –
typeName (string) –
SetColFormatDate
(self, col, format="")¶Sets the specified column to display date values.
The format argument is used with wx.grid.GridCellDateRenderer and allows to specify the strftime-like format string to use for displaying the dates in this column.
col (int) –
format (string) –
New in version 4.1/wxWidgets-3.1.3.
See also
SetColFormatFloat
(self, col, width=-1, precision=-1)¶Sets the specified column to display floating point values with the given width and precision.
col (int) –
width (int) –
precision (int) –
See also
SetColFormatNumber
(self, col)¶Sets the specified column to display integer values.
col (int) –
See also
SetColLabelAlignment
(self, horiz, vert)¶Sets the horizontal and vertical alignment of column label text.
Horizontal alignment should be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
. Vertical alignment should be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
horiz (int) –
vert (int) –
SetColLabelSize
(self, height)¶Sets the height of the column labels.
If height equals to GRID_AUTOSIZE
then height is calculated automatically so that no label is truncated. Note that this could be slow for a large table.
height (int) –
SetColLabelTextOrientation
(self, textOrientation)¶Sets the orientation of the column labels (either HORIZONTAL
or VERTICAL
).
textOrientation (int) –
SetColLabelValue
(self, col, value)¶Set the value for the given column label.
If you are using a custom grid table you must override wx.grid.GridTableBase.SetColLabelValue
for this to have any effect.
col (int) –
value (string) –
SetColMinimalAcceptableWidth
(self, width)¶Sets the minimal width to which the user can resize columns.
width (int) –
See also
SetColMinimalWidth
(self, col, width)¶Sets the minimal width for the specified column col.
It is usually best to call this method during grid creation as calling it later will not resize the column to the given minimal width even if it is currently narrower than it.
width must be greater than the minimal acceptable column width as returned by GetColMinimalAcceptableWidth
.
col (int) –
width (int) –
SetColPos
(self, colID, newPos)¶Sets the position of the specified column.
colID (int) –
newPos (int) –
SetColSize
(self, col, width)¶Sets the width of the specified column.
col (int) – The column index.
width (int) – The new column width in pixels, 0 to hide the column or -1 to fit the column width to its label width.
SetColSizes
(self, sizeInfo)¶Restore all columns sizes.
This is usually called with wx.grid.GridSizesInfo object previously returned by GetColSizes
.
sizeInfo (wx.grid.GridSizesInfo) –
See also
SetColumnsOrder
(self, order)¶Sets the positions of all columns at once.
This method takes an array containing the indices of the columns in their display order, i.e. uses the same convention as wx.HeaderCtrl.SetColumnsOrder
.
order (list of integers) –
SetCornerLabelAlignment
(self, horiz, vert)¶Sets the horizontal and vertical alignment of the (top-left) corner label text.
Horizontal alignment should be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
. Vertical alignment should be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
horiz (int) –
vert (int) –
New in version 4.1/wxWidgets-3.1.2.
SetCornerLabelTextOrientation
(self, textOrientation)¶Sets the orientation of the (top-left) corner label (either HORIZONTAL
or VERTICAL
).
textOrientation (int) –
New in version 4.1/wxWidgets-3.1.2.
SetCornerLabelValue
(self)¶Set the value for the (top-left) corner label.
If you are using a custom grid table you must override wx.grid.GridTableBase.SetCornerLabelValue
for this to have any effect.
`` (string) –
New in version 4.1/wxWidgets-3.1.2.
SetDefaultCellAlignment
(self, horiz, vert)¶Sets the default horizontal and vertical alignment for grid cell text.
Horizontal alignment should be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
. Vertical alignment should be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
horiz (int) –
vert (int) –
SetDefaultCellBackgroundColour
(self, colour)¶Sets the default background colour for grid cells.
colour (wx.Colour) –
SetDefaultCellFitMode
(self, fitMode)¶Specifies the default behaviour of the cell contents if it doesn’t fit into the available space.
fitMode (wx.grid.GridFitMode) –
New in version 4.1/wxWidgets-3.1.4.
See also
SetDefaultCellFont
(self, font)¶Sets the default font to be used for grid cell text.
font (wx.Font) –
SetDefaultCellOverflow
(self, allow)¶Sets the default overflow permission of the cells.
Prefer using SetDefaultCellFitMode
in the new code.
allow (bool) –
SetDefaultCellTextColour
(self, colour)¶Sets the current default colour for grid cell text.
colour (wx.Colour) –
SetDefaultColSize
(self, width, resizeExistingCols=False)¶Sets the default width for columns in the grid.
This will only affect columns subsequently added to the grid unless resizeExistingCols is True
.
If width is less than GetColMinimalAcceptableWidth
, then the minimal acceptable width is used instead of it.
width (int) –
resizeExistingCols (bool) –
SetDefaultEditor
(self, editor)¶Sets the default editor for grid cells.
The grid will take ownership of the pointer.
See wx.grid.GridCellEditor and the Grid Overview for more information about cell editors and renderers.
editor (wx.grid.GridCellEditor) –
SetDefaultRenderer
(self, renderer)¶Sets the default renderer for grid cells.
The grid will take ownership of the pointer.
See wx.grid.GridCellRenderer and the Grid Overview for more information about cell editors and renderers.
renderer (wx.grid.GridCellRenderer) –
SetDefaultRowSize
(self, height, resizeExistingRows=False)¶Sets the default height for rows in the grid.
This will only affect rows subsequently added to the grid unless resizeExistingRows is True
.
If height is less than GetRowMinimalAcceptableHeight
, then the minimal acceptable height is used instead of it.
height (int) –
resizeExistingRows (bool) –
SetGridCursor
(self, *args, **kw)¶Set the grid cursor to the specified cell.
The grid cursor indicates the current cell and can be moved by the user using the arrow keys or the mouse.
Calling this function generates a wxEVT_GRID_SELECT_CELL
event and if the event handler vetoes this event, the cursor is not moved.
This function doesn’t make the target call visible, use GoToCell
to do this.
SetGridCursor (self, row, col)
row (int) –
col (int) –
SetGridCursor (self, coords)
coords (wx.grid.GridCellCoords) –
SetGridFrozenBorderPenWidth
(self, width)¶width (int) –
SetGridLineColour
(self, colour)¶Sets the colour used to draw grid lines.
colour (wx.Colour) –
SetLabelBackgroundColour
(self, colour)¶Sets the background colour for row and column labels.
colour (wx.Colour) –
SetLabelTextColour
(self, colour)¶Sets the colour for row and column label text.
colour (wx.Colour) –
SetMargins
(self, extraWidth, extraHeight)¶Sets the extra margins used around the grid area.
A grid may occupy more space than needed for its data display and this function allows setting how big this extra space is
extraWidth (int) –
extraHeight (int) –
SetReadOnly
(self, row, col, isReadOnly=True)¶Makes the cell at the specified location read-only or editable.
row (int) –
col (int) –
isReadOnly (bool) –
See also
SetRowAttr
(self, row, attr)¶Sets the cell attributes for all cells in the specified row.
The grid takes ownership of the attribute pointer.
See the wx.grid.GridCellAttr class for more information about controlling cell attributes.
row (int) –
attr (wx.grid.GridCellAttr) –
SetRowLabelAlignment
(self, horiz, vert)¶Sets the horizontal and vertical alignment of row label text.
Horizontal alignment should be one of ALIGN_LEFT
, ALIGN_CENTRE
or ALIGN_RIGHT
. Vertical alignment should be one of ALIGN_TOP
, ALIGN_CENTRE
or ALIGN_BOTTOM
.
horiz (int) –
vert (int) –
SetRowLabelSize
(self, width)¶Sets the width of the row labels.
If width equals GRID_AUTOSIZE
then width is calculated automatically so that no label is truncated. Note that this could be slow for a large table.
width (int) –
SetRowLabelValue
(self, row, value)¶Sets the value for the given row label.
If you are using a derived grid table you must override wx.grid.GridTableBase.SetRowLabelValue
for this to have any effect.
row (int) –
value (string) –
SetRowMinimalAcceptableHeight
(self, height)¶Sets the minimal row height used by default.
See SetColMinimalAcceptableWidth
for more information.
height (int) –
SetRowMinimalHeight
(self, row, height)¶Sets the minimal height for the specified row.
See SetColMinimalWidth
for more information.
row (int) –
height (int) –
SetRowPos
(self, rowID, newPos)¶Sets the position of the specified row.
rowID (int) –
newPos (int) –
New in version 4.1/wxWidgets-3.1.7.
SetRowSize
(self, row, height)¶Sets the height of the specified row.
See SetColSize
for more information.
row (int) –
height (int) –
SetRowSizes
(self, sizeInfo)¶Restore all rows sizes.
sizeInfo (wx.grid.GridSizesInfo) –
See also
SetRowsOrder
(self, order)¶Sets the positions of all rows at once.
This method takes an array containing the indices of the rows in their display order.
order (list of integers) –
New in version 4.1/wxWidgets-3.1.7.
SetScrollLineX
(self, x)¶Sets the number of pixels per horizontal scroll increment.
The default is 15.
x (int) –
See also
SetScrollLineY
(self, y)¶Sets the number of pixels per vertical scroll increment.
The default is 15.
y (int) –
See also
SetSelectionBackground
(self, c)¶Set the colour to be used for drawing the selection background.
c (wx.Colour) –
SetSelectionForeground
(self, c)¶Set the colour to be used for drawing the selection foreground.
c (wx.Colour) –
SetSelectionMode
(self, selmode)¶Set the selection behaviour of the grid.
The existing selection is converted to conform to the new mode if possible and discarded otherwise (e.g. any individual selected cells are deselected if the new mode allows only the selection of the entire rows or columns).
selmode (GridSelectionModes) –
SetSortingColumn
(self, col, ascending=True)¶Set the column to display the sorting indicator in and its direction.
col (int) – The column to display the sorting indicator in or NOT_FOUND
to remove any currently displayed sorting indicator.
ascending (bool) – If True
, display the ascending sort indicator, otherwise display the descending sort indicator.
See also
SetTabBehaviour
(self, behaviour)¶Set the grid’s behaviour when the user presses the TAB
key.
Pressing the TAB
key moves the grid cursor right in the current row, if there is a cell at the right and, similarly, Shift-TAB moves the cursor to the left in the current row if it’s not in the first column.
What happens if the cursor can’t be moved because it it’s already at the beginning or end of the row can be configured using this function, see wx.grid.Grid.TabBehaviour documentation for the detailed description.
IF
none of the standard behaviours is appropriate, you can always handle wxEVT_GRID_TABBING
event directly to implement a custom TAB-handling logic.
behaviour (TabBehaviour) –
New in version 2.9.5.
_SetTable
(self, table, takeOwnership=False, selmode=GridSelectCells)¶Passes a pointer to a custom grid table to be used by the grid.
This should be called after the grid constructor and before using the grid object. If takeOwnership is set to True
then the table will be deleted by the wx.grid.Grid destructor.
Use this function instead of CreateGrid
when your application involves complex or non-string data or data sets that are too large to fit wholly in memory.
When the custom table should be owned by the grid, consider using the simpler AssignTable
function instead of this one with True
value of takeOwnership parameter.
table (wx.grid.GridTableBase) –
takeOwnership (bool) –
selmode (GridSelectionModes) –
bool
SetTable
(self, table, takeOwnership=False, selmode=Grid.GridSelectCells)¶Set the Grid Table to be used by this grid.
SetUseNativeColLabels
(self, native=True)¶Call this in order to make the column labels use a native look by using wx.RendererNative.DrawHeaderButton
internally.
There is no equivalent method for drawing row columns as there is not native look for that. This option is useful when using wx.grid.Grid for displaying tables and not as a spread-sheet.
native (bool) –
See also
ShowCellEditControl
(self)¶Displays the active in-place cell edit control for the current cell after it was hidden.
This method should only be called after calling HideCellEditControl
, to start editing the current grid cell use EnableCellEditControl
instead.
ShowCol
(self, col)¶Shows the previously hidden column by resizing it to non-0 size.
The column is shown again with the same width that it had before HideCol
call.
If the column is currently shown, this method doesn’t do anything.
col (int) –
See also
ShowRow
(self, col)¶Shows the previously hidden row.
The row is shown again with the same height that it had before HideRow
call.
If the row is currently shown, this method doesn’t do anything.
col (int) –
See also
UnsetSortingColumn
(self)¶Remove any currently shown sorting indicator.
This is equivalent to calling SetSortingColumn
with NOT_FOUND
first argument.
UseNativeColHeader
(self, native=True)¶Enable the use of native header window for column labels.
If this function is called with True
argument, a wx.HeaderCtrl is used instead to display the column labels instead of drawing them in wx.grid.Grid code itself. This has the advantage of making the grid look and feel perfectly the same as native applications (using SetUseNativeColLabels
the grid can be made to look more natively but it still doesn’t feel natively, notably the column resizing and dragging still works slightly differently as it is implemented in wxWidgets itself) but results in different behaviour for column and row headers, for which there is no equivalent function, and, most importantly, is unsuitable for grids with huge numbers of columns as wx.HeaderCtrl doesn’t support virtual mode. Because of this, by default the grid does not use the native header control but you should call this function to enable it if you are using the grid to display tabular data and don’t have thousands of columns in it.
Another difference between the default behaviour and the native header behaviour is that the latter provides the user with a context menu (which appears on right clicking the header) allowing to rearrange the grid columns if CanDragColMove
returns True
. If you want to prevent this from happening for some reason, you need to define a handler for wxEVT_GRID_LABEL_RIGHT_CLICK
event which simply does nothing (in particular doesn’t skip the event) as this will prevent the default right click handling from working.
Also note that currently wxEVT_GRID_LABEL_RIGHT_DCLICK
event is not generated for the column labels if the native columns header is used (but this limitation could possibly be lifted in the future).
Finally, please note that using the native control is currently incompatible with freezing columns in the grid (see FreezeTo
) and this function will return False
, without doing anything, if it’s called on a grid in which any columns are frozen.
native (bool) –
bool
XToCol
(self, x, clipToMinMax=False, gridWindow=None)¶Returns the column at the given pixel position depending on the window.
x (int) – The x position to evaluate.
clipToMinMax (bool) – If True
, rather than returning NOT_FOUND
, it returns either the first or last column depending on whether x is too far to the left or right respectively.
gridWindow (wx.grid.GridWindow) – The associated grid window that limits the search (note that this parameter is only available since wxWidgets 3.1.3). If gridWindow is None
, it will consider all the cells, no matter which grid they belong to.
int
The column index or NOT_FOUND
.
XToEdgeOfCol
(self, x)¶Returns the column whose right hand edge is close to the given logical x position.
If no column edge is near to this position NOT_FOUND
is returned.
x (int) –
int
XYToCell
(self, *args, **kw)¶XYToCell (self, x, y, gridWindow=None)
Translates logical pixel coordinates to the grid cell coordinates.
Notice that this function expects logical coordinates on input so if you use this function in a mouse event handler you need to translate the mouse position, which is expressed in device coordinates, to logical ones.
The parameter gridWindow is new since wxWidgets 3.1.3. If it is specified, i.e. not None
, the coordinates must be in this window coordinate system and only the cells of this window are considered, i.e. the function returns NOT_FOUND
if the coordinates are out of bounds.
If gridWindow is None
, coordinates are relative to the main grid window and all cells are considered.
x (int) –
y (int) –
gridWindow (wx.grid.GridWindow) –
See also
XYToCell (self, pos, gridWindow=None)
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
pos (wx.Point) –
gridWindow (wx.grid.GridWindow) –
YToEdgeOfRow
(self, y)¶Returns the row whose bottom edge is close to the given logical y position.
If no row edge is near to this position NOT_FOUND
is returned.
y (int) –
int
YToRow
(self, y, clipToMinMax=False, gridWindow=None)¶Returns the grid row that corresponds to the logical y coordinate.
The parameter gridWindow is new since wxWidgets 3.1.3. If it is specified, i.e. not None
, only the cells of this window are considered, i.e. the function returns NOT_FOUND
if y is out of bounds.
If gridWindow is None
, the function returns NOT_FOUND
only if there is no row at all at the y position.
y (int) –
clipToMinMax (bool) –
gridWindow (wx.grid.GridWindow) –
int
BatchCount
¶See GetBatchCount
CellHighlightColour
¶CellHighlightPenWidth
¶CellHighlightROPenWidth
¶See GetCellHighlightROPenWidth
and SetCellHighlightROPenWidth
ColLabelSize
¶See GetColLabelSize
and SetColLabelSize
ColLabelTextOrientation
¶See GetColLabelTextOrientation
and SetColLabelTextOrientation
ColMinimalAcceptableWidth
¶See GetColMinimalAcceptableWidth
and SetColMinimalAcceptableWidth
ColSizes
¶See GetColSizes
and SetColSizes
CornerLabelTextOrientation
¶See GetCornerLabelTextOrientation
and SetCornerLabelTextOrientation
CornerLabelValue
¶DefaultCellBackgroundColour
¶See GetDefaultCellBackgroundColour
and SetDefaultCellBackgroundColour
DefaultCellFitMode
¶DefaultCellFont
¶See GetDefaultCellFont
and SetDefaultCellFont
DefaultCellOverflow
¶DefaultCellTextColour
¶DefaultColLabelSize
¶DefaultColSize
¶See GetDefaultColSize
and SetDefaultColSize
DefaultEditor
¶See GetDefaultEditor
and SetDefaultEditor
DefaultGridLinePen
¶DefaultRenderer
¶See GetDefaultRenderer
and SetDefaultRenderer
DefaultRowLabelSize
¶DefaultRowSize
¶See GetDefaultRowSize
and SetDefaultRowSize
FirstFullyVisibleColumn
¶FirstFullyVisibleRow
¶FrozenColGridWindow
¶FrozenCornerGridWindow
¶FrozenRowGridWindow
¶GridColHeader
¶See GetGridColHeader
GridColLabelWindow
¶GridCornerLabelWindow
¶GridCursorCol
¶See GetGridCursorCol
GridCursorCoords
¶GridCursorRow
¶See GetGridCursorRow
GridLineColour
¶See GetGridLineColour
and SetGridLineColour
GridRowLabelWindow
¶GridWindow
¶See GetGridWindow
LabelBackgroundColour
¶LabelFont
¶See GetLabelFont
and SetLabelFont
LabelTextColour
¶See GetLabelTextColour
and SetLabelTextColour
NumberCols
¶See GetNumberCols
NumberFrozenCols
¶NumberFrozenRows
¶NumberRows
¶See GetNumberRows
RowLabelSize
¶See GetRowLabelSize
and SetRowLabelSize
RowMinimalAcceptableHeight
¶See GetRowMinimalAcceptableHeight
and SetRowMinimalAcceptableHeight
RowSizes
¶See GetRowSizes
and SetRowSizes
ScrollLineX
¶See GetScrollLineX
and SetScrollLineX
ScrollLineY
¶See GetScrollLineY
and SetScrollLineY
SelectedBlocks
¶SelectedCells
¶See GetSelectedCells
SelectedColBlocks
¶SelectedCols
¶See GetSelectedCols
SelectedRowBlocks
¶SelectedRows
¶See GetSelectedRows
SelectionBackground
¶SelectionBlockBottomRight
¶SelectionBlockTopLeft
¶SelectionForeground
¶SelectionMode
¶See GetSelectionMode
and SetSelectionMode
SortingColumn
¶See GetSortingColumn
and SetSortingColumn