wxTreeCtrl problems

I have a wxTreeCtrl and I'm capturing EVT_TREE_KEY_DOWN. My code looks a lot like this:

def OnKeyDown (self, event):
  code = event.GetKeyCode()

  if (code == 13):
    cur_item = event.GetItem()
    print self.GetItemText(cur_item)

But the text for the item is empty, even though the item clearly has text in it in the display. Is the event not giving me the correct item, or do I have to do something else to get this to work?

I'm using libwx 2.4, MacPython 2.3a2 with Chandler 0.1 (if that matters).

···

--
Nick

This is very strange. I was just doing a tree control and decided to
test this.

If I use self.GetItemText(self.GetSelection()), I get the item's label.
If I use
self.GetItemText(event.GetItem()), I get an empty string.

The following snippet:

  def OnKeyPress(self, event):
    print event.GetItem()
    print self.GetSelection()
    print "(%s)" % self.GetItemText(event.GetItem())
    print "(%s)" % self.GetItemText(self.GetSelection())
    print event.GetItem() == self.GetSelection()

Produces:

  <C wxTreeItemId instance at _8dd5f08_wxTreeItemId_p>
  <C wxTreeItemId instance at _8dd5f08_wxTreeItemId_p>
  ()
  (My Label)
  0

This appears to be a bug with the event. I am running wxPython/wxGTK
2.4.0.7 on Debian Unstable (Python 2.2.2).

···

--
Jason Cater
GNU Enterprise

On Thu, 29 May 2003 16:35:06 -0400 Nick Bastin <nbastin@opnet.com> wrote:

I have a wxTreeCtrl and I'm capturing EVT_TREE_KEY_DOWN. My code
looks a lot like this:

def OnKeyDown (self, event):
  code = event.GetKeyCode()

  if (code == 13):
    cur_item = event.GetItem()
    print self.GetItemText(cur_item)

But the text for the item is empty, even though the item clearly has
text in it in the display. Is the event not giving me the correct
item, or do I have to do something else to get this to work?

I'm using libwx 2.4, MacPython 2.3a2 with Chandler 0.1 (if that
matters).

--
Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwindows.org
For additional commands, e-mail:
wxPython-users-help@lists.wxwindows.org

--

Nick Bastin wrote:

I have a wxTreeCtrl and I'm capturing EVT_TREE_KEY_DOWN. My code looks a lot like this:

def OnKeyDown (self, event):
    code = event.GetKeyCode()

    if (code == 13):
        cur_item = event.GetItem()
        print self.GetItemText(cur_item)

But the text for the item is empty, even though the item clearly has text in it in the display. Is the event not giving me the correct item, or do I have to do something else to get this to work?

I'm using libwx 2.4, MacPython 2.3a2 with Chandler 0.1 (if that matters).

For some reason the current item is not set for this event. You can test the validity by calling cur_item.Ok().

You can work around this by saving the current item in the EVT_TREE_SEL_CHANGED handler and then using the saved value in the EVT_TREE_KEY_DOWN.

···

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

Jason Cater wrote:

If I use self.GetItemText(self.GetSelection()), I get the item's label.
If I use self.GetItemText(event.GetItem()), I get an empty string.

This appears to be a bug with the event.

It may be, but it behaves the same on all platforms so that tells me that it may be intentional. I'm looking further into it...

···

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