Setting default sizes

You can change the size of the entire grid by changing the default size of all rows or all columns. Following are the two methods for this.

SetDefaultColSize(width, resizeExistingCols=False)

SetDefaultRowSize(height, resizeExistingRows=False).

In both cases, the first parameter is the new size in pixels. If the Boolean second parameter is True, all the currently existing rows or columns are immediately resized to the new default. If the parameter is False, existing rows or columns are left untouched, and the new default is only applied to new rows or columns as they are added. In a typical use, you would most likely want to set this value at the beginning of your initialization, even before the call to CreateGrid() or Set-Table(). You can get the current default sizes using GetDefaultColSize() and GetDefaultRowSize().

There is a performance implication to setting the default versus setting the sizes for individual rows or columns. To store the default values, wxPython only needs to store the two integer values. As soon as you set a single row or column to a non-default size, wxPython switches and stores the size of every row or column in an array. If your table is very large, this could use a significant amount of additional memory, so it's something to watch.

Occasionally, you'll want to set a minimum size for a row or column so that no matter what program methods are called or what the user does by dragging grid lines, the row or column can get no smaller. This may be the case if you have text that you don't want to be chopped in half, or a number that you don't want digits cut off from.

In wxPython, you can set the minimum value on a grid-wide basis or set it separately for individual rows and columns. To change the minimum value for the entire grid, use the method SetColMinimalAcceptableWidth(width) or SetRow-MinimalAcceptableHeight(height). The parameter is the minimal size for all rows or columns in pixels. To set the minimum on a row-by-row basis, use Set-ColMinimalWidth(col, width) or SetRowMinimalHeight(row, height). For these methods, the first parameter is the index of the item being sized and the second method is the new size in pixels. The minimal size of an individual row must be higher than the minimum grid-wide value, if that value is set. Existing rows or columns that happen to have a size smaller than the new minimum will not be automatically resized. Therefore, you probably want to call these methods early in the initialization process before data is added. For performance reasons, it's best to keep the minimum acceptable values close to the actual smallest size of a real cell as displayed. Each of these methods has one of the following associated getter functions.

■ GetColMinimalAcceptableWidth()

■ GetRowMinimalAcceptableHeight()

■ GetColMinimalWidth(col)

■ GetRowMinimalHeight(row)

Was this article helpful?

0 0

Post a comment