Positioning PopupMenu

I'm trying to use a popup menu in a ListCtrl so that the popup acts like it
does in the demo and pops up with its upper left corner exactly where the
mouse cursor is. But I can't seem to get this to work.

It *looks* to me as though what is happening is this:

Event.GetPosition() seems to return coordinates that are relative to the
upper left corner of the ListCtrl. But when these are used in the call to
PopupMenu, they are taken as relative to the *parent frame* -- so, for
example, instead of the popup appearing in the upper left corner of the
ListCtrl it appears in the upper left corner of the enclosing frame. In
fact, since my ListCtrl is on the right side of the frame, if you click in
order in the upper left, lower left, lower right, and upper right corners
of the list control, the popup appears correspondingly in the corners of a
rectangle on the left side of the frame :slight_smile: . This is kind of cute, but
not exactly what I need.

In addition to looking at previous problems reported for positioning
popups, I've tried experimenting with a variety of attempts involving
wxGetMousePosition, wxWindow.ClientToScreen, etc., but to not much avail.
With some coordinate arithmetic I seem to be able to the the popup to
appear kind of *close* to where it should, but not quite.

How do I get this to work? I see in the demo that the popup somewhat more
simplistically appears in a panel. Is it necessary to enclose my ListCtrl
in a panel to accomplish this? If so, what are the ramifications of this
requirement for complex layouts in nested sizers where you might want
PopupMenus of different sorts to appear relative to different items in the
sizers?

···

--------------------------------------
Gary H. Merrill
Director and Principal Scientist, New Applications
Data Exploration Sciences
GlaxoSmithKline Inc.
(919) 483-8456

I'm trying to use a popup menu in a ListCtrl so that the popup acts like it
does in the demo and pops up with its upper left corner exactly where the
mouse cursor is. But I can't seem to get this to work.

It *looks* to me as though what is happening is this:

Event.GetPosition() seems to return coordinates that are relative to the
upper left corner of the ListCtrl. But when these are used in the call to
PopupMenu, they are taken as relative to the *parent frame* -- so, for
example, instead of the popup appearing in the upper left corner of the
ListCtrl it appears in the upper left corner of the enclosing frame. In
fact, since my ListCtrl is on the right side of the frame, if you click in
order in the upper left, lower left, lower right, and upper right corners
of the list control, the popup appears correspondingly in the corners of a
rectangle on the left side of the frame :slight_smile: . This is kind of cute, but
not exactly what I need.

My guess is that when you call something.PopupMenu(..) that the something is the frame, not the ListCtrl, right? Do you see the problem with this?

In addition to looking at previous problems reported for positioning
popups, I've tried experimenting with a variety of attempts involving
wxGetMousePosition, wxWindow.ClientToScreen, etc., but to not much avail.
With some coordinate arithmetic I seem to be able to the the popup to
appear kind of *close* to where it should, but not quite.

SPerhaps smething like this:

  pos = frame.ScreenToClient(listctrl.ClientToScreen())

···

gary.h.merrill@gsk.com wrote:

--
Robin Dunn
Software Craftsman
http://wxPython.org Java give you jitters? Relax with wxPython!