popup menu in TreeCtrl drop handler

Danny Shevitz shevitz at lanl.gov
Mon Mar 3 14:32:57 PST 2008


> In a TreeCtrl I am trying to display a popup menu when I drag something
> onto the TreeCtrl. I have all the events worked out and the menu created. 
> It's mostly working except that the popup menu flashes instead of staying up. 
> It is impossible to select an item in the popup menu. The TreeCtrl has a 
> DropTarget.
> 
> I am simply implementing (in the OnData method of the DropTarget):
> 
> menu = ...
> self.treeCtrl.PopupMenuXY(menu,point[0], point[1])
> 
> any ideas what's going on?

I can add a little more info. In the OnData handler, I actually have two
kinds of drops. Ordinary, or pull up the context menu if the Alt key was 
pressed. The logic I used was:

if wx.GetKeyState(wx.WXK_ALT):
  pull up the context menu
else:
  do ordinary drop

if instead, I just pull up the context menu (remove the "if" statement above)
the popup menu displays just fine. Something about pushing the Alt key
makes the menu close immediately.

I also tried changing the modifier from the Alt key to Ctrl or Shift.
Both of the latter work just fine. What is it about the Alt key that causes
the popup to immediately close, and is there a workaround? I'd like to use
the Alt key.

Any ideas now?

thanks,
Danny







More information about the wxpython-users mailing list