I’ve got a wxpython grid, and I’m changing the background color of a cell to show that something has happened to it.
I’d like to fade the color change in/out (like JavaScript in the browser) for a smoother look. Is this possible to do?
Right now, I’m just changing the background color, and then changing it back after a 1.5-second interval.
def do_stuf(self):
# ... stuff ...
wx.CallAfter(self.HighlightCell, row, col)
def HighlightCell(self, row, col):
self.grid.Table.highlight = (row, col)
self.grid.ForceRefresh()
wx.CallLater(1500, self.ClearCellHighlight)
def ClearCellHighlight(self):
self.grid.Table.highlight = None
self.grid.ForceRefresh()
Then in the virtual table, I check if the cell needs highlighting:
def GetAttr(self, row, col, kind):
"""
Use this callback to set the cell's background color
"""
attr = wx.grid.GridCellAttr()
if (row, col) == self.highlight:
attr.SetBackgroundColour("green")
elif row % 2:
attr.SetBackgroundColour("white")
else:
attr.SetBackgroundColour("#e7ffff")
return attr
Alternatively, is there another pretty way to indicate that a cell’s contents have changed?
This is something I did a while ago to get a ListCtrl with items that fade out when deleted. Save the code to fade.py and run it to see the demo. Shouldn’t be too hard to adapt it to a Grid.