I'm trying to get a list control to display a wxTipWindow based on the contents of the listitem being pointed to. I haven't quite got it. I've stripped my program down to the very minimal version below. Can someone tell me what I've got wrong? I'm using wxPython 2.4.0.1, gtk version under Linux.
#!/usr/bin/env python
from wxPython.wx import *
class MyListCtrl(wxListCtrl):
def __init__(self, parent, win_id = -1, pos = wxDefaultPosition, size = wxDefaultSize, style = wxLC_REPORT | wxSUNKEN_BORDER):
wxListCtrl.__init__(self, parent, win_id, pos, size, style)
self.tip_shown = -1
EVT_MOTION(self, self.OnMotion)
def OnMotion(self, event):
x, y = event.GetPosition()
index, trash = self.HitTest(wxPoint(x, y))
if index != -1 and index != self.tip_shown:
rect = self.GetItemRect(index)
left, top = self.ClientToScreenXY(rect.x, rect.y)
right, bottom = self.ClientToScreenXY(rect.GetRight(), rect.GetBottom())
rect = wxRect(left, top, right - left + 1, bottom - top + 1)
self.tip = wxTipWindow(self, self.GetItem(index, 0).GetText())
self.tip.SetBoundingRect(rect)
self.tip_shown = index
class MyApp(wxApp):
def OnInit(self):
frame = wxFrame(NULL, -1, 'Test')
list = MyListCtrl(frame)
list.InsertColumn(0, 'Header')
list.InsertStringItem(0, 'One')
list.InsertStringItem(1, 'Two')
list.InsertStringItem(2, 'Three')
list.InsertStringItem(3, 'Four')
frame.Show(1)
self.SetTopWindow(frame)
return 1
def main():
app = MyApp()
app.MainLoop()
if __name__ == '__main__':
main()