How do I get right clicks on wxTreeListCtrl?
I have migrated from a wxTreeCtrl where I used
EVT_RIGHT_DOWN and EVT_RIGHT_UP and did a
HitTest to get the item.
With wxTreeListCtrl, my even callbacks are never
called no matter where I right click.
Roger
You need to bind the events to wxTreeListCtrl.GetMainWindow()
Alberto
Here is a summary of what to do to work around the current quirks
in wxTreeListCtrl for those of you who may also be beating your
heads on your keyboard. There is no need to modify any of the
installed wxPython files.
Derive a class from wxTreeListCtrl. Add the following methods:
import wxPython.gizmosc as gizmosc
def GetFirstChild(self, *_args, **_kwargs):
val = gizmosc.wxTreeListCtrl_GetFirstChild(self, *_args, **_kwargs)
return val
def GetNextChild(self, *_args, **_kwargs):
val = gizmosc.wxTreeListCtrl_GetNextChild(self, *_args, **_kwargs)
return val
def HitTest(self, pt):
val1, val2, val3 = gizmosc.wxTreeListCtrl_HitTest(self, wxPoint(pt.x, pt.y+self._BIAS))
val1 = wxTreeItemIdPtr(val1)
val1.thisown = 1
return (val1, val2, val3)
In your __init__, just after adding the root item, add the following code:
self._BIAS=self.GetBoundingRect(rootitem).GetHeight()+self.GetSpacing()
The first two methods fix an exception in the wrappers as shipped. The hittest
and BIAS stuff is because the HitTest that is builtin gets the item
off by one.
Roger
In your __init__, just after adding the root item, add the following code:
self._BIAS=self.GetBoundingRect(rootitem).GetHeight()+self.GetSpacing()
The first two methods fix an exception in the wrappers as shipped. The
hittest and BIAS stuff is because the HitTest that is builtin gets the
item off by one.
Roger
I don't think this is entirely correct. The problem is not an off-by-one,
that's the symptom. The real reason is that the size of the header window
is not taken into account... so, my solution would be:
def HitTest(self, point):
w = self.GetMainWindow()
return gizmosc.wxTreeListCtrl_HitTest(self,
self.ScreenToClient(w.ClientToScreen(point)))
As for the wrong column numbers, it seems a bug... I'll try to fix this
ASAP, and send a patch to Robin when done.
Alberto