[wxPython-users] sorry, troubling every one for wx.grid again.

Robin Dunn robin at alldunn.com
Tue Sep 4 15:32:33 PDT 2007


krishnakant Mane wrote:
> hello,
> I am really not understanding the concept of wx.grid, so troubling the
> list again.
> I am really sorry but I am confused with the entire concept of the
> wx.grid and its related classes like the classes for sells and their
> editing etc.

The Grid family of classes are large and complex, but they fit together
in a logical way and follow common patterns.  Here are some important
key points:

* The Grid class follows a Model/View architecture, where the model is
the data and the view is the UI widgets.

* The data model is implemented using a GridTable class.  There is a
built-in default table class that can only store strings and keeps them
all in memory.  You can plug in a custom table that deals with the data
however you want to.  It simply needs to provide the data values to the
view when it is asked for them.  It can also use data types other than
strings and can also provide the view with the display attributes for
each cell and it can provide the row and column labels.

* The Grid also supports a plug-in architecture for the displaying and
editing of the cells.

* Each cell is drawn with a GridCellRenderer object, and there are
different built-in renderer classes for various data types.  You can
also create your own renderer classes for drawing the cells in a custom
way if needed.  The renderer classes need to override certain methods,
but the main one is the Draw method.  It is called by the grid whenever
a cell needs to be redrawn.

* Cell values are edited with a GridCellEditor object, again there are
different built-in editor classes for the various data types and you can
also use custom editors if needed.  The editor encapsulates and controls
a UI widget that is used to do the actual editing of the value, for
example the GridCellStringEditor class uses a wx.TextCtrl.

* There is only at most one editor active at one time.  The currently
active cell will have the editor when it is in edit mode.  For all the
other cells only the renderer is used for displaying the cell.

* The choice of which kinds of renderer or editor is used for a cell can
be determined in a few different ways.  The cell, col or row can have an
attributes object associated with it, and part of the attributes is the
renderer and editor objects to use.  The renderer/editor can also be
chosen by data type if you are using a custom table that overrides the
GetTypeName method to return non-default typenames.  You can also
register with the grid to map new data typenames to a set of
renderer/editor objects.  Finally, the table can provide the attributes
for each cell on-demand.


-- 
Robin Dunn
Software Craftsman
http://wxPython.org  Java give you jitters?  Relax with wxPython!






More information about the wxpython-users mailing list