[wxPython] wxGridTableBase implementation for wxGrid::IsCurrentCellReadOnly?

I'm trying to add "read-only" support to the property editing framework. However, the implementation of IsCurrentCellReadOnly does not provide for subclasses overriding it. i.e. the following in a wxGrid subclass does not get called:

  def IsCurrentCellReadOnly( self ):
    """Workaround to avoid the use of attributes by forwarding read-only query to the table"""
    print "IsCurrentCellReadOnly"
    return self.GetTable().IsReadOnlyCell(
      self.GetGridCursorRow(),
      self.GetGridCursorCol(),
    )

Would it be possible to add the machinery for overriding the method to the next pre-release? Is there a better way of doing this without needing to delve into the wild world of attribute maintenance?

Enjoy yourselves,
Mike

···

_______________________________________
   Mike C. Fletcher
   http://members.rogers.com/mcfletch/

def IsCurrentCellReadOnly( self ):
"""Workaround to avoid the use of attributes by forwarding read-only query
to the table"""
print "IsCurrentCellReadOnly"
return self.GetTable().IsReadOnlyCell(
self.GetGridCursorRow(),
self.GetGridCursorCol(),
)

Would it be possible to add the machinery for overriding the method to
the next pre-release?

'Fraid not. It's not a virtual method and I'd rather avoid making a
wxPyGrid anyway...

Is there a better way of doing this without
needing to delve into the wild world of attribute maintenance?

I don't remember, are you using a custom GridTable? If so I think if you
don't override any of the Attr related methods then the defaults should work
just fine. Then all you need to do for read-only is call
grid.SetReadOnly(row, col, true).

···

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

Yes, I'm using a custom grid table. Thing is, having to explicitly call SetReadOnly means that you'd force the system to call this for every cell, rather than just having the value requested when needed.

... later ...

Okay, I bit the bullet and figured out the wxGridCellAttr, turns out the docs are wrong on how the class is used, there's a simple wxGridCellAttr() call (doesn't require all the params specified, as though the note was carried out but never re-documented), then call SetReadOnly( 1 ) and return.

Minor note: got an assertion error when I attempted to access the font in a default-initialised attr object.

i.e.
     attr.GetFont().GetFaceName()

which I'm gathering is supposed to be avoided using attr.HasFont(). Not sure why the attr wouldn't return the default font, but oh well.

Here's the wxPyGridTableBase method I'm currently using:

     def GetAttr(self, row, col, someExtraParameter ):
         property = self.GetPropertyForCoordinate( row, col )
         object = self.GetObjectForCoordinate( row, col )
         attr = wxGridCellAttr()
         if property.ReadOnly( object ):
             attr.SetReadOnly( 1 )
         return attr

It seems to work, as did returning null if I didn't want to SetReadOnly. For now I'm always returning one just in case there are problems with the null pointer being returned.

Enjoy all,
Mike

Robin Dunn wrote:
...

Would it be possible to add the machinery for overriding the method to
the next pre-release?

'Fraid not. It's not a virtual method and I'd rather avoid making a
wxPyGrid anyway...

Is there a better way of doing this without
needing to delve into the wild world of attribute maintenance?

I don't remember, are you using a custom GridTable? If so I think if you
don't override any of the Attr related methods then the defaults should work
just fine. Then all you need to do for read-only is call
grid.SetReadOnly(row, col, true).

...

Minor note: got an assertion error when I attempted to access the font
in a default-initialised attr object.

i.e.
     attr.GetFont().GetFaceName()

which I'm gathering is supposed to be avoided using attr.HasFont(). Not
sure why the attr wouldn't return the default font, but oh well.

Yep. The design there was that all attrs would be considered invalid until
explicitly set. That allows attr objects to be merged. For example for a
cell that has a cell attr and also a row attr set.

Here's the wxPyGridTableBase method I'm currently using:

     def GetAttr(self, row, col, someExtraParameter ):
         property = self.GetPropertyForCoordinate( row, col )
         object = self.GetObjectForCoordinate( row, col )
         attr = wxGridCellAttr()
         if property.ReadOnly( object ):
             attr.SetReadOnly( 1 )
         return attr

It seems to work, as did returning null if I didn't want to SetReadOnly.
  For now I'm always returning one just in case there are problems with
the null pointer being returned.

Returning None should be okay.

···

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