wxPyGridCellEditor

The cell editor is a utility class for managing a wxControl instance for editing a particular data type. A particular instance of the editor (and thereby it's associated control) is used for all cells in the grid having the same data type.

Unfortunately, the editor is derived from an undocumented class, the wxGridCellWorker, whose methods I am inferring from usage within the wxPython demo.

Control Initialization

The editor is shared among all cells having the same data type, this lets the system reuse the editing control for each cell, but requires that the editor have machinery in place for creating, moving, and setting the current value for that single control.

        def Create(self, parent, id, evtHandler):
                self.control = self.buttonClass( parent, id)
                self.SetControl(self.control)
                if evtHandler:
                        self.control.PushEventHandler(evtHandler)

        def Clone(self):
                return self.__class__()

.

Configuration for a Cell

When a particular cell is to be edited, it is necessary to have the editor's control moved so that it appears to be contained within the rectangle defined by the cell. You define a handler for SetSize which performs this resizing.

The Edit Cycle

After the control has been positioned, the grid calls Show, to show the control on-screen, then BeginEdit to allow the editor to transfer data from the grid (or the table) to the control and set the Focus to the control.

Show needs to be overwritten if you wish to display more than than one control. For example, with a text control and a button:

        def Show(self, show, attr):
                self.textBox.Show(show)
                self.browseButton.Show(show)

From there, the grid calls one of two methods for handling the event which triggered the editing cycle (StartingKey or StartingClick), allowing the control to respond to those events.

While the control is active, a number of methods may be called in response to user interactions.

Control Cleanup

I have never had cause to use this, the default Destroy seems to properly clean up a control which has had SetControl called on it.

Display Customisation

If the control is smaller than the size of the cell, there will be a background area displayed in the remaining space. This method is called to clear that background area. Apparently the cell attribute object will provide information on appropriate colors.

Back to the wxGrid Manual

wxPyGridCellEditor (last edited 2008-03-11 10:50:37 by localhost)

NOTE: To edit pages in this wiki you must be a member of the TrustedEditorsGroup.