Inserting a checkbox as a column in a Grid.

Hi!

I'm new to wxPython and I'm willing to add a column with checkboxes to
a grid and I'm using wxGlade to write the Python code. Is there an
easier way to do that rather than subclassing the grid and creating it
by hand?

I got this from the demo (GridCustTable.py)

···

----------------------------------------------------------------------
    def __init__(self, log):
        wxPyGridTableBase.__init__(self)
        self.log = log

        self.colLabels = ['ID', 'Description', 'Severity', 'Priority', 'Platform',
                          'Opened?', 'Fixed?', 'Tested?', 'TestFloat']

        self.dataTypes = [wxGRID_VALUE_NUMBER,
                          wxGRID_VALUE_STRING,
                          wxGRID_VALUE_CHOICE + ':only in a million years!,wish list,minor,normal,major,critical',
                          wxGRID_VALUE_NUMBER + ':1,5',
                          wxGRID_VALUE_CHOICE + ':all,MSW,GTK,other',
                          wxGRID_VALUE_BOOL,
                          wxGRID_VALUE_BOOL,
                          wxGRID_VALUE_BOOL,
                          wxGRID_VALUE_FLOAT + ':6,2',
                          ]

        self.data = [
            [1010, "The foo doesn't bar", "major", 1, 'MSW', 1, 1, 1, 1.12],
            [1011, "I've got a wicket in my wocket", "wish list", 2, 'other', 0, 0, 0, 1.50],
            [1012, "Rectangle() returns a triangle", "critical", 5, 'all', 0, 0, 0, 1.56]

            ]
----------------------------------------------------------------------

and I'm willing something as in the wxGRID_VALUE_BOOL. But my grid has
23 columns and it can grow a 'little' later... I'm willing to avoid
having to specify each column by hand and, if possible, just change
the datatypes. Is it possible?

--
Godoy. <godoy@metalab.unc.edu>

Jorge Godoy <godoy@metalab.unc.edu> writes:

I'm new to wxPython and I'm willing to add a column with checkboxes to
a grid and I'm using wxGlade to write the Python code. Is there an
easier way to do that rather than subclassing the grid and creating it
by hand?

Answering myself:

I used

(...)
self.grid.SetColFormatBool(column_number)
(...)

To change the format of just that column.

Then, to have the effect of checkboxes I added the following to my
event table:

(...)
    EVT_GRID_CELL_LEFT_CLICK(self, self.OnMouseRightDown)
(...)

And then I defined the following method to handle that event:

(...)
def OnMouseRightDown(self, event):
    row = event.GetRow()
    column = event.GetCol()
    if self.notebook.GetSelection() == 6: # Just one of the tabs
        if column == 23: # Column 'Delete'
            if str(self.grid6.GetCellValue(row, column)) == '0':
                self.grid6.SetCellValue(row, column, '1')
            else:
                self.grid6.SetCellValue(row, column, '0')
(...)

See you,

···

--
Godoy. <godoy@metalab.unc.edu>