wxGridTableBase's SetAttr parameter order

It always seems presumptuous when someone jumps out saying "Python has a bug!" Invariably it turns out to be the guy reporting the so-called bug is the one doing it wrong. In this case I believe it might be a documentation bug/issue, but I'll let you guys decide.

I was recently wanting to set the attributes of a single cell inside a wxGrid. I attempted to do so using:

self.SetAttr(myAttr, row, col)

only I kept getting an error:

TimesheetEntryCellEditor init
Traceback (most recent call last):
  File "/home/cooperg/quickbooks/gui/TimesheetGrid.py", line 179, in OnCellChange
    self.SetAttr(entryAttr, evt.GetRow(), col,)
  File "/usr/lib/python2.3/site-packages/wxPython/grid.py", line 1256, in SetAttr
    val = gridc.wxGrid_SetAttr(self, *_args, **_kwargs)
AttributeError: wxGridCellAttr instance has no attribute '__int__'

It turns out that these pages:

http://search.cpan.org/src/MBARBON/Wx-0.18/ext/grid/XS/GridTable.xsp
http://wiki.wxpython.org/index.cgi/wxPyGridTableBase

are -- it would seem -- incorrect in regard to the order of the attributes. They claim the parameter order is:
SetAttr(wxGridCellAttr* attr, int row, int col)
But it appears that the parameter order is:
SetAttr(int row, int col, wxGridCellAttr* attr)

Or at least that's the order I had to send it in to get it to work. :wink:

Not that the python help() function worked for anything :stuck_out_tongue: the only thing it tells you is to send *args, **kwargs. Right... *thanks!* :stuck_out_tongue:

=]

Gabriel Cooper wrote:

It always seems presumptuous when someone jumps out saying "Python has a bug!" Invariably it turns out to be the guy reporting the so-called bug is the one doing it wrong. In this case I believe it might be a documentation bug/issue, but I'll let you guys decide.

I was recently wanting to set the attributes of a single cell inside a wxGrid. I attempted to do so using:

self.SetAttr(myAttr, row, col)

only I kept getting an error:

TimesheetEntryCellEditor init
Traceback (most recent call last):
File "/home/cooperg/quickbooks/gui/TimesheetGrid.py", line 179, in OnCellChange
   self.SetAttr(entryAttr, evt.GetRow(), col,)
File "/usr/lib/python2.3/site-packages/wxPython/grid.py", line 1256, in SetAttr
   val = gridc.wxGrid_SetAttr(self, *_args, **_kwargs)
AttributeError: wxGridCellAttr instance has no attribute '__int__'

It turns out that these pages:

ext/grid/XS/GridTable.xsp - metacpan.org
http://wiki.wxpython.org/index.cgi/wxPyGridTableBase

are -- it would seem -- incorrect in regard to the order of the attributes. They claim the parameter order is:
SetAttr(wxGridCellAttr* attr, int row, int col)
But it appears that the parameter order is:
SetAttr(int row, int col, wxGridCellAttr* attr)

Or at least that's the order I had to send it in to get it to work. :wink:

Those pages are documenting wx*GridTableBase, but you are making the call on a wxGrid instance.

Not that the python help() function worked for anything :stuck_out_tongue: the only thing it tells you is to send *args, **kwargs. Right... *thanks!* :stuck_out_tongue:

Upgrade to 2.5.2.7 and you'll get some more (but not yet complete) help from the docstrings:

$ pydoc wx.grid.Grid.SetAttr
Help on method SetAttr in wx.grid.Grid:

wx.grid.Grid.SetAttr = SetAttr(*args, **kwargs) unbound wx.grid.Grid method
     SetAttr(self, int row, int col, GridCellAttr attr)

···

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