By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,570 Members | 1,325 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,570 IT Pros & Developers. It's quick & easy.

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

P: n/a
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)

Jan 19 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
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

Jan 19 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.