About GridCellRenderer

Hello,

I'm using custom GridCellRenderers to draw the grid cell contents, all Ok.

But recently I discovered that for simply cell decorations i can call to any gridrenderer to draw the contents with the current attributes and after, do the decoration.

That is:

class CellRendererStringWithBorder(gridlib.PyGridCellRenderer):
     def Draw(self, grid, attr, dc, rect, row, col, isSelected):

         # Call string renderer to draw contents
         gridlib.GridCellStringRenderer().Draw(grid, attr, dc, rect, row, col, isSelected)

         # do decoration
         dc.SetBrush(wx.Brush(wx.Colour(0,0,0), wx.TRANSPARENT))
         dc.SetPen(wx.Pen(wx.Colour(255, 0, 0), 1, wx.SOLID))
         dc.DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, 3)

This renderer call GridCellStringRenderer.Draw for draw the contents and after draw a box. On simple tests works fine.

The question is:

I have not seen anywhere these way to do the render. It's correct?
Can produce unwanted side effects?

Thanks,

···

--
Oswaldo Hern�ndez

I think that in this case it is probably alright since creating a new instance of the renderer is fairly lightweight and doesn't create any UI objects.

···

On 2/14/11 9:40 AM, Oswaldo Hern�ndez wrote:

Hello,

I'm using custom GridCellRenderers to draw the grid cell contents, all Ok.

But recently I discovered that for simply cell decorations i can call to
any gridrenderer to draw the contents with the current attributes and
after, do the decoration.

That is:

class CellRendererStringWithBorder(gridlib.PyGridCellRenderer):
def Draw(self, grid, attr, dc, rect, row, col, isSelected):

# Call string renderer to draw contents
gridlib.GridCellStringRenderer().Draw(grid, attr, dc, rect, row, col,
isSelected)

# do decoration
dc.SetBrush(wx.Brush(wx.Colour(0,0,0), wx.TRANSPARENT))
dc.SetPen(wx.Pen(wx.Colour(255, 0, 0), 1, wx.SOLID))
dc.DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, 3)

This renderer call GridCellStringRenderer.Draw for draw the contents and
after draw a box. On simple tests works fine.

The question is:

I have not seen anywhere these way to do the render. It's correct?
Can produce unwanted side effects?

--
Robin Dunn
Software Craftsman

El 14/02/2011 18:57, Robin Dunn escribi�:

···

On 2/14/11 9:40 AM, Oswaldo Hern�ndez wrote:

Hello,

I'm using custom GridCellRenderers to draw the grid cell contents, all
Ok.

But recently I discovered that for simply cell decorations i can call to
any gridrenderer to draw the contents with the current attributes and
after, do the decoration.

That is:

class CellRendererStringWithBorder(gridlib.PyGridCellRenderer):
def Draw(self, grid, attr, dc, rect, row, col, isSelected):

# Call string renderer to draw contents
gridlib.GridCellStringRenderer().Draw(grid, attr, dc, rect, row, col,
isSelected)

# do decoration
dc.SetBrush(wx.Brush(wx.Colour(0,0,0), wx.TRANSPARENT))
dc.SetPen(wx.Pen(wx.Colour(255, 0, 0), 1, wx.SOLID))
dc.DrawRoundedRectangle(rect.x, rect.y, rect.width, rect.height, 3)

This renderer call GridCellStringRenderer.Draw for draw the contents and
after draw a box. On simple tests works fine.

The question is:

I have not seen anywhere these way to do the render. It's correct?
Can produce unwanted side effects?

I think that in this case it is probably alright since creating a new
instance of the renderer is fairly lightweight and doesn't create any UI
objects.

Thanks Robin

--
Oswaldo Hern�ndez