#!/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)  #,size=(480, 360))

        self.CreateGrid(10, 5)
        self.SetRowLabelSize(0)
        self.SetColLabelSize(20)

        self.GridColLabelWindow.Bind(wx.EVT_ENTER_WINDOW,self.onEnter)
        self.GridColLabelWindow.Bind(wx.EVT_LEAVE_WINDOW,self.onLeave)

    def onEnter(self, evt):
        print 'enter', evt.Position,
        xpos = evt.Position[0]
        tot = 0
        col = 0
        for col in xrange(self.NumberCols):
            tot += self.GetColSize(col)
            if xpos <= tot:
                print 'col', col, self.GetColLabelValue(col)
                break
        else:
            print 'no column'

    def onLeave(self, evt):
        print 'leave'

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()
