On Friday 20 February 2009 11:36:12 am johnf wrote: > 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)
Hey Paul is there other methods I should be dealing with? I'd like to post this to the how to's but I'm unsure if there are other method I need to override - or missing stuff in general. In the gridRenderer you guys use clip() and unclip(). This code seems to work on windows and my linux. -- 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]
