subclass of wx.grid but how to do SetCellValue?

I have created a subclass of wx.grid. I have provided my own versions of
GetNumberCols and GetNumberRows within my subclass. I'm trying to set a
value into a grid cell, but not having any luck.
<code>
  def SetCellValue(self, row, col, val):
        gridlib.Grid.SetCellValue(self, row, col, val)
        return
</code>
I've tried variations on this but nothing works...the values don't change
even though the code runs without errors.
Can someone help me with some ideas on how to get this to work? BTW I'm NOT
using a Table with this grid...perhaps I should?
Any help would be greatly appreciated.

···

--
View this message in context: http://wxpython-users.1045709.n5.nabble.com/subclass-of-wx-grid-but-how-to-do-SetCellValue-tp5018037p5018037.html
Sent from the wxPython-users mailing list archive at Nabble.com.

I have created a subclass of wx.grid. I have provided my own versions of
GetNumberCols and GetNumberRows within my subclass.

If you're expecting that to make calls to those methods from within the grid class then you're out of luck. OverridingMethods - wxPyWiki

I'm trying to set a
value into a grid cell, but not having any luck.
<code>
   def SetCellValue(self, row, col, val):
         gridlib.Grid.SetCellValue(self, row, col, val)
         return
</code>
I've tried variations on this but nothing works...the values don't change
even though the code runs without errors.

Are you calling SetCellValue, or expecting it to be called from the C++ side of the fence? Either way, showing us a runnable sample will help us help you. MakingSampleApps - wxPyWiki

Can someone help me with some ideas on how to get this to work? BTW I'm NOT
using a Table with this grid...perhaps I should?

Probably. It's methods have been set up to handle being overridden.

···

On 11/23/11 12:56 PM, johncblacker wrote:

Any help would be greatly appreciated.

--
Robin Dunn
Software Craftsman

Perhaps more explanation is necessary?

Originally, I created a subclass of wx.grid in order to create a bunch of grid object of various sizes and names. I create the grid(s) from within my do_layout method for the frame and then try to change a cell value.

So, I have:

csgrid = buildgrid(blah, blah, blah)

csgrid.SetCellValue(1, 0, “somevalue”)

The above did not change the value in the cell of the csgrid object. If I printed csgrid, it was indeed listed as a grid object. So, I tried another experiment to see what was going on. csgrid was originally created as a 1 column, 40 row grid. I tried the following:

print csgrid.GetNumberCols()

The value came back 0…hmmmmm…I though so that’s what led me to creating the two functions: GetNumberCols() and GetNumberRows() within the subclass.

Once I did this, of course, the above snippet returned the value I expected.

So, I added my own method for SetCellValue within the subclass. This method was coded as follows:

import wx.grid as gridlib

(more code)…

def SetCellValue(self, row, col, val):
gridlib.Grid.SetCellValue(self, row, col, val)
return

now when I called with:

csgrid.SetCellValue(row, col, value)

It still didn’t change the value in the grid…thus the reason for my original post.

I’m not expecting the wx.grid c++ code to be calling my method, I’m calling it from within my code and then calling the parent class method and it isn’t working and I don’t know why…

You are probably missing something in the setup of the widgets. Please make a small runnable sample that demonstrates the problem and if that does not help you find the source of the problem yourself then go ahead and post it here for us to look at.

···

On 11/24/11 5:30 PM, johncblacker wrote:

Perhaps more explanation is necessary?
Originally, I created a subclass of wx.grid in order to create a bunch
of grid object of various sizes and names. I create the grid(s) from
within my do_layout method for the frame and then try to change a cell
value.
So, I have:
<code>
csgrid = buildgrid(blah, blah, blah)
csgrid.SetCellValue(1, 0, "somevalue")
</code>
The above did not change the value in the cell of the csgrid object. If
I printed csgrid, it was indeed listed as a grid object. So, I tried
another experiment to see what was going on. csgrid was originally
created as a 1 column, 40 row grid. I tried the following:
<code>
print csgrid.GetNumberCols()
</code>
The value came back 0...hmmmmm....I though so that's what led me to
creating the two functions: GetNumberCols() and GetNumberRows() within
the subclass.
Once I did this, of course, the above snippet returned the value I expected.
So, I added my own method for SetCellValue within the subclass. This
method was coded as follows:
<code>
import wx.grid as gridlib
(more code)...
def SetCellValue(self, row, col, val):
gridlib.Grid.SetCellValue(self, row, col, val)
return
</code>
now when I called with:
<code>
csgrid.SetCellValue(row, col, value)
</code>
It still didn't change the value in the grid...thus the reason for my
original post.
I'm not expecting the wx.grid c++ code to be calling my method, I'm
calling it from within my code and then calling the parent class method
and it isn't working and I don't know why...

--
Robin Dunn
Software Craftsman