I got the CustomRendererClass working for a grid - below is an example
class StatRedGreenBoolRenderer(wx.grid.GridCellRenderer):
def Draw(self, grid, attr, dc, rect, row, col, isSelected):
"""Below is an example of creating a custom cell renderer.
Where the
Grid col is set as
col.CustomRendererClass = StatRedGreenBoolRenderer
In this case the value is a string in the dataset (in the cell)"""
text = myval = grid.cell(row,col).Value #grid.GetCellValue(row,
col)
if myval == 'Inactive':
bg = "yellow"
fg = 'black'
elif myval == 'On Hold':
bg = "orange"
fg = 'black'
elif myval == 'Terminated':
bg = "red"
fg = 'white'
elif myval == 'Completed':
bg = "green"
fg = 'Black'
else:
text = 'TBD'
bg = "salmon"
fg = 'white'
hAlign, vAlign = attr.GetAlignment()
dc.SetFont( attr.GetFont() )
#if isSelected:
#bg = grid.GetSelectionBackground()
#fg = grid.GetSelectionForeground()
dc.SetTextBackground(bg)
dc.SetTextForeground(fg)
dc.SetBrush(wx.Brush(bg, wx.SOLID))
dc.SetPen(wx.TRANSPARENT_PEN)
dc.DrawRectangle(rect)
grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)
def Clone(self):
return StatRedGreenBoolRenderer()
I made the changes that you noticed and one other the
'dc.DrawRectangleRect(rect)' to '
dc.DrawRectangle(rect)'.
While researching the issue I noticed that Dabo is looping over the data
to set the cellAttr. I wonder if there isn't a more efficient way. It
looks like there is a way to set the cellAttr using
myGrid.SetColAttr(col, property_settings). I will check into this
further at some point in the future. See
https://stackoverflow.com/questions/54843888/wxpython-how-to-set-an-editor-for-a-column-of-a-grid
Johnf
On 7/10/19 7:14 PM, Ed Leafe wrote:
On Jul 10, 2019, at 7:14 PM, johnf <[email protected]> wrote:
dc.SetBrush(wx.Brush(bg, wx.SOLID))
dc.SetPen(wx.TRANSPARENT_PEN)
Note that these constants have changed in wxPython 4.x: they should be
wx.BRUSHSTYLE_SOLID and wx.PENSTYLE_TRANSPARENT, respectively. I noticed that
there are still a few of those old names still in the dabo3 branch, so I can
fix those quickly. Be sure to update your custom classes.
-- Ed Leafe
[excessive quoting removed by server]
_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: https://mail.leafe.com/mailman/listinfo/dabo-dev
Searchable Archives: https://leafe.com/archives
This message:
https://leafe.com/archives/byMID/[email protected]