Draw line over a wxgrid

I want to draw a line over a grid, so I bind the paint event, and with this sample code I draw a line, but I can't see it. My question is this: is it possible to draw directly over a grid, or I must bind the paint event of the window that have inside the grid?

Thanks,
Michele

class MyGrid(wx.grid.Grid):
  def activate(self):
   self.Bind(wx.EVT_PAINT, self.__OnPaint)
  def __OnPaint(self, event):
   dc = wx.PaintDC(self)
   dc.BeginDrawing()
   dc.SetPen(wx.Pen('RED'))
   dc.DrawLine(0,0,500,500)
   dc.EndDrawing()

class frame(wx.Frame):

   <-cut->

  self.grid = MyGrid()
  self.grid.activate()

Michele Petrazzo wrote:

I want to draw a line over a grid, so I bind the paint event, and with this sample code I draw a line, but I can't see it. My question is this: is it possible to draw directly over a grid, or I must bind the paint event of the window that have inside the grid?

You'll need to bind the EVT_PAINT of the window returned by self.GetGridWindow, but you'll still have to do something tricky because the default handler will cause all the cells will draw themselves, and so if that happens after your paint handler runs it will cause your line to be drawn over by the cell contents. So you'll probably just want to set a flag in your OnPaint and then call evt.Skip so the default handler will be run. Then have an EVT_IDLE handler that will draw the line on a wx.ClientDC and then reset the flag.

···

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!