wxPython - is it possible to determine List Box item under a right click?

akameswaran at gmail.com akameswaran at gmail.com
Thu Jan 19 14:14:11 EST 2006


I have a list box, I'd like to generate a right click menu for items in
the list box.  The problem is unless I left click the item first, I
can't figure out which item in the list I clicked over.  So it seems to
me, I need to determine the which item I right clicked over, perform a
setselected on the listbox object and then run my right-click menu.
(I'd like a right-click to also serve as selection)
The originating object is obvioiusly the List box, but I can get the
mouse position from the event.

The problem is, the only thing I can think that might work is to pull
the list font object, calculate the sizes of items in the list and
"guess" which list item is under the mouse.  This seems really really
ugly.

Any suggestions?  Should I bind elswhere?  Should I just build my own
list box?

I have a control based on wx.Panel something like  - no this doesn't
run ;

class myPanel (wx.Panel):
  def __init(self):
    wx.Panel.__init__(self)
    self.myList = wx.ListBox()
    self.myList.foo - populate list

    self.myList.Bind(wx.EVT_RIGHT_DOWN, self.ListRIghtClicked)

 def ListRightClicked(self,event):

   mousePos = event.GetPosition()

  # wtf do I do with the position?
  magic = doSomething?

  self.myList.SetSelected(Magic)

  self.PopupMenu(myMenu(),mousePos)




More information about the Python-list mailing list