#!/usr/bin/env python
import wx, wx.grid as grd

class MyFrame(wx.Frame):
    def __init__(self, parent, id, title):
        wx.Frame.__init__(self, parent, id, title, size=(480, 180))
        MyPanel(self)
        self.CentreOnScreen()

class MyPanel(wx.Panel):
    def __init__(self,frame):
        wx.Panel.__init__(self,frame,-1)
        grid = MyGrid(self)
        grid.Size = frame.ClientSize
        grid.SetFocus()

class MyGrid(grd.Grid):
    def __init__(self,panel):
        grd.Grid.__init__(self,panel,-1)

        self.CreateGrid(10, 15)
        self.SetRowLabelSize(0)
        self.SetColLabelSize(20)

        self.tool_tip = wx.ToolTip('')
        self.GridColLabelWindow.ToolTip = self.tool_tip

        self.GridColLabelWindow.Bind(wx.EVT_ENTER_WINDOW,self.onEnter)

    def onEnter(self, evt):
        xpos = evt.Position[0] + self.CalcUnscrolledPosition((0,0))[0]
        tot = 0
        for col in xrange(self.NumberCols):
            tot += self.GetColSize(col)
            if xpos <= tot:
                self.tool_tip.Tip = 'Tool tip for Column %s' % (
                    self.GetColLabelValue(col))
                break
        else:  # mouse is in label area beyond the right-most column
            self.tool_tip.Tip = ''

class MyApp(wx.App):
    def OnInit(self):
        frame = MyFrame(None, -1, "Test grid tooltip")
        frame.Show(True)
        self.SetTopWindow(frame)
        return True

MyApp(0).MainLoop()
