Actions performed by selecting a menu item in the context menu act
upon the currently selected listbox item. Therefore, I'd like to make
right clicking select the listbox item first, then bring up the
context menu. This avoids forcing the user to left click on an item,
then right click to bring up its context menu.
My first attempt was to catch the RIGHT_DOWN event, clone it and
reprocess it as a LEFT_DOWN event - hoping the listbox would intepret
it as a left click and select the item for me.
Actions performed by selecting a menu item in the context menu act
upon the currently selected listbox item. Therefore, I’d like to make
right clicking select the listbox item first, then bring up the
context menu. This avoids forcing the user to left click on an item,
then right click to bring up its context menu.
My first attempt was to catch the RIGHT_DOWN event, clone it and
reprocess it as a LEFT_DOWN event - hoping the listbox would intepret
it as a left click and select the item for me.
I would imagine that there is a mechanism whereby you can discover which
item was right-clicked on, you can select the item
(self.list.SetStringSelection I would imagine), then pop up the
context-sensitive menu relating to that item.
- Josiah
···
"Aaron Leiby" <aaron.wxpython@gmail.com> wrote:
Unfortunately, this didn't work for me. Am I going about this the
wrong way? This seems like something that would happen pretty often.
Something like that would work great, but the only HitTest I can find
returns just an int (flags). I imagine ListBox must have some
functionality for determining which item was clicked on, but I don't
see it exposed anywhere.
Also, it seems to me that now PopupMenu works better if you *don't* specify
the event.GetPosition()... but I may be wrong here.
Good call.
That brings up something else I was wondering about. I just started
playing with wxPython. I recently picked up Robin and Noel's book -
which is great! I started building a small app, and am at the point
now where some peer review would be useful to identify stuff that
could be done better - like not passing the position into PopupMenu.
Is there any mechanism in the wxPython community for that kind of
thing? Spamming the list with a bunch of code seems like it might be
a bit rude.
Please see the attached file if it does what you need. Here
(wxPython 2.6.3.2, Python 2.4.3, Windows XP) it does react correctly
to right mouse clicks, whether there are scrollbars or not in the
listbox.
I don't think that a newbie that really wants to learn will ever be
considered as spammer if he/she posts some code. I think here there
are a lot of powerful coders that are glad to help newbies as long as
they demonstrate that they are putting a real effort in coding
Something like that would work great, but the only HitTest I can find
returns just an int (flags). I imagine ListBox must have some
functionality for determining which item was clicked on, but I don't
see it exposed anywhere.
> Also, it seems to me that now PopupMenu works better if you *don't* specify
> the event.GetPosition()... but I may be wrong here.
Good call.
That brings up something else I was wondering about. I just started
playing with wxPython. I recently picked up Robin and Noel's book -
which is great! I started building a small app, and am at the point
now where some peer review would be useful to identify stuff that
could be done better - like not passing the position into PopupMenu.
Is there any mechanism in the wxPython community for that kind of
thing? Spamming the list with a bunch of code seems like it might be
a bit rude.
Thanks!
---------------------------------------------------------------------
To unsubscribe, e-mail: wxPython-users-unsubscribe@lists.wxwidgets.org
For additional commands, e-mail: wxPython-users-help@lists.wxwidgets.org
--
"Imagination Is The Only Weapon In The War Against Reality."
Something like that would work great, but the only HitTest I can find
returns just an int (flags). I imagine ListBox must have some
functionality for determining which item was clicked on, but I don't
see it exposed anywhere.
A ListBox specific implementation of HitTest was added in 2.7. In 2.6 and before there isn't an easy way to do it and I usually suggest that people use a wx.ListCtrl instead. If you use the wx.LC_REPORT and wx.LC_NO_HEADER styles then the look and feel is very much like a wx.ListBox and you have a HitTest method that works.
···
--
Robin Dunn
Software Craftsman http://wxPython.org Java give you jitters? Relax with wxPython!
Please see the attached file if it does what you need. Here
(wxPython 2.6.3.2, Python 2.4.3, Windows XP) it does react correctly
to right mouse clicks, whether there are scrollbars or not in the
listbox.
Nice, thanks. It doesn't look like 2.7 has been released yet? I'll
look into using a ListCtrl instead. I initially just wanted to get
something simple up and running with a basic ListBox before moving on
to the more complex widgets. My eventual plans are to add a TreeCtrl
on a tabbed panel. Small steps. Plus I haven't gotten that far in
the book yet.
···
On 5/11/06, Robin Dunn <robin@alldunn.com> wrote:
A ListBox specific implementation of HitTest was added in 2.7. In 2.6
and before there isn't an easy way to do it and I usually suggest that
people use a wx.ListCtrl instead. If you use the wx.LC_REPORT and
wx.LC_NO_HEADER styles then the look and feel is very much like a
wx.ListBox and you have a HitTest method that works.