Introduction
The wxTreeCtrl has a bug in its arrow keys.
What Objects are Involved
Uh, the wxTreeCtrl
Process Overview
The "correct" keystrokes for a tree control are:
Down select the prior visible item
Left if the current node's expanded it collapses, else select the prior visible item
Right if the current node's collapsed it expands, else select the next visible item
Up select the next visible item
Special Concerns
The wxTreeCtrl gets Left wrong. It does not opt to collapse.
The following sample works if you have inherited the tree control; otherwise refactor the 'self.' and adjust the binding. I added this to the ListAndTreeControls example.
Code Sample
def __init__( ... blah blah blah EVT_KEY_DOWN(self, self.OnKey) ... def OnKey(self, event): 'On <Left>, if the current item is expanded, collapse it' key = event.KeyCode() if key == WXK_LEFT: ID = self.GetSelection() if self.IsExpanded(ID): self.Collapse(ID) return event.Skip()
Comments
It'd be nice if someone promoted this patch back up to the source (WxGtk) instead of only fixing it down here in the python.
--PhlIp
It seems to have been fixed now.. (well, the bindings are correct in the latest wxPython demo, and I can't see anything resembling your fix in the code)