What's my problem with wxTipWindow?

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()

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.

Mmmh... yes interesting..
I also try this and it seems the 'SetBoundingRect' methode doesn't work as
expected ...

A workaround would be replacing

    if index != -1 and index != self.tip_shown:

with

    if index != -1 :

But that's not very clean :frowning:

Sorry, I also don't have the answer... but it interest me!
-philippe

Scott wrote:

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.

The problem is a bug in wxGTK. The GetItemRect method is not taking into account the size of the header, so the bounds you set on the tip window are offset such that the mouse is already outside the bounds. For example if you use wxLC_HO_HEADER then it works fine.

I'll ask about this on wx-dev.

···

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