Hi all!
Seems to be rather quiet during Christmas...
I'm trying to popup a menu using a wx.EVT_LIST_ITEM_RIGHT_CLICK. This
works fine, but I have no idea how to find out where the mouse is located,
as I'd like to make the menu popup under the mouse. Any ideas?
Unfortunately, GetPosition() is not available for this event... Do I have
to use the mouse events and find out which list item is underneeth or can
I combine them in some nice way?
My current wx.EVT_LIST_ITEM_RIGHT_CLICK event handler looks something as:
self.PopupMenu(MyMenu(self),wx.Point(0,0))
(so only very rarely the popup comes out under the mouse...)
wxPython 2.4.2.4
Python 2.3.3
Windows XP
With best regards
Oscar Gustafsson
Hi all!
Hello Oscar!
Seems to be rather quiet during Christmas...
Sure does
I'm trying to popup a menu using a wx.EVT_LIST_ITEM_RIGHT_CLICK. This
works fine, but I have no idea how to find out where the mouse is located,
as I'd like to make the menu popup under the mouse. Any ideas?
Unfortunately, GetPosition() is not available for this event... Do I have
to use the mouse events and find out which list item is underneeth or can
I combine them in some nice way?
If you haven't already, I suggest you take a look at the wonderful
wxPython Demo (download from
Redirecting...).
In the demo, look under "ListCtrl". Test right-clicking on the
ListCtrl. The contextual menu appears where the mouse is. I assume
this is the behaviour you are looking for?
I only took a quick look at the source, but it seems Robin and Gary
(who wrote the demo) saved the mouse coordinates in wx.EVT_RIGHT_DOWN
(as self.x and self.y, using event.GetX and event.GetY respectively).
Then, in EVT_LIST_ITEM_RIGHT_CLICK, they just open the contextual menu with
self.PopupMenu(menu, (self.x, self.y))
While this sure seems to work, I don't really know what the correct
way to do it is. I mean, one could show the contextual menu either
where the mouse was at the time of mouse-down (as in the example
above), or one could show it where the mouse was at the time of
mouse-up (this is the behaviour you get if you try right-clicking on
some item in the start-menu under WinXP, releasing the right-button at
a position different from where you pressed it). A third way is to
simpy show the menu directly in wx.EVT_RIGHT_DOWN (this is the
behaviour you see in iTunes when you right-click a song).
Oh well, the above solution from the wxPython Demo works anyway
//Jonatan
ยทยทยท
On Sun, 26 Dec 2004 00:27:13 +0100 (MET), Oscar Gustafsson <oscar@lysator.liu.se> wrote:
Hi Jonatan!
If you haven't already, I suggest you take a look at the wonderful
wxPython Demo (download from
Redirecting...).
In the demo, look under "ListCtrl". Test right-clicking on the
ListCtrl. The contextual menu appears where the mouse is. I assume
this is the behaviour you are looking for?
This is slightly embassasing for me... I assumed that, Well, it's probably
just a plain ListCtrl in the demo...
I only took a quick look at the source, but it seems Robin and Gary
(who wrote the demo) saved the mouse coordinates in wx.EVT_RIGHT_DOWN
(as self.x and self.y, using event.GetX and event.GetY respectively).
I did try this after writing my first mail, but looking at the demo source
EVT_RIGHT_UP (as I used) is somehow not supported for the ListCtrl under
Win, but instead EVT_COMMAND_RIGHT_CLICK should be used. So this should
do the trick I guess.
Thanks for the help!
With best regards
Oscar