Ok, it took all morning but I got a custom grid renderer to work.  It turned 
out to be very simple. Needed help from others. 

I had a need to display a boolean in a grid with the background color green 
for True and red for False.  I also decided to change the text (since I 
could) to 'open' and 'closed' (this is for a class schedule).

class RedGreenBoolRenderer(wx.grid.PyGridCellRenderer): 
    def Draw(self, grid, attr, dc, rect, row, col, isSelected):
        import random
        #text = grid.GetCellValue(row, col)
        myval = grid.GetCellValue(row, col)
        if myval:
            text=u'Closed'
        else:
            text=u'Open'
        hAlign, vAlign = attr.GetAlignment()
        dc.SetFont( attr.GetFont() )
        if isSelected:
            bg = grid.GetSelectionBackground()
            fg = grid.GetSelectionForeground()
        else:
            if myval:
                bg="red"
                fg='white'
            else:
                bg='green'
                fg='black'
            #fg = attr.GetTextColour()

        dc.SetTextBackground(bg)
        dc.SetTextForeground(fg)
        dc.SetBrush(wx.Brush(bg, wx.SOLID))
        dc.SetPen(wx.TRANSPARENT_PEN)
        dc.DrawRectangleRect(rect)           
        grid.DrawTextRectangle(dc, text, rect, hAlign, vAlign)

-- 
John Fabiani

_______________________________________________
Post Messages to: [email protected]
Subscription Maintenance: http://leafe.com/mailman/listinfo/dabo-users
Searchable Archives: http://leafe.com/archives/search/dabo-users
This message: 
http://leafe.com/archives/byMID/[email protected]

Reply via email to