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

A

akameswaran

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)
 
A

akameswaran

In case someone finds this - My own solution to this was to use a
wx.ListCtrl - it's a bit more work, but the mixin's are quite handy
for my purposes, also a right click causes selection for ListCtrl - so
it's nice and clean
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top