[wxPython] wxGetMousePosition, and PopupMenu()

I have the following code:

    self.PopupMenu(cmdmenu, wxGetMousePosition())

Yet the menu is popping up nowhere near the mouse position, and seems to be popping up at the same place everytime.

BTW, I'm new to the list .... hi everyone. :slight_smile:

Michael

I'm not familiar with using wxGetMousePosition() but the doco says it returns the mouse position in screen coordinates, so you might need to
use wxWindow::ScreenToClient to convert it to your windows coord system.

If its popping up at the same place either wxGetMousePosition is broken or maybe the coords are out of bounds so it defaults to a sensible
position within the parent.

But even better, depending on your scenario, you could use the mouse position appropriate (as given by the event that triggered the popup
- if any):

def OnDoPopup(self, evt):
        menu = wxMenu()
        .... # build menu

        self.PopupMenu(menu, evt.GetPosition()) # <-- gets position at time of mouse click (or whatever)

HTH
Ellers

···

7/27/02 10:52:02 AM, Michael Kelley <tkelley70@insightbb.com> wrote:

I have the following code:

   self.PopupMenu(cmdmenu, wxGetMousePosition())

Yet the menu is popping up nowhere near the mouse position, and seems to
be popping up at the same place everytime.

Hi- HTH, this is a method that responds to a right-click in a list control with

    EVT_RIGHT_DOWN(self.dirListctl,self.onRightDown)

and this works fine every time.

def onRightDown(self,event):
    """ process right click in this panel """
    #pop up the menu
    popup = self.dirListctl.PopupMenu(self.menu,event.GetPosition())
   
So try getting the position from the event. Works fine over a list
control and probably over a panel, too. Most likely
wxGetMouseControl is not going to give you the position
that you want due to the way the event system works.

HTH,
jeff sasmor

···

#--------------------------------
Jeff Sasmor
jeff@sasmor.com
----- Original Message -----
From: "Michael Kelley" <tkelley70@insightbb.com>
To: <wxpython-users@lists.wxwindows.org>
Sent: Friday, July 26, 2002 10:52 PM
Subject: [wxPython] wxGetMousePosition, and PopupMenu()

I have the following code:

    self.PopupMenu(cmdmenu, wxGetMousePosition())

Yet the menu is popping up nowhere near the mouse position, and seems to
be popping up at the same place everytime.

BTW, I'm new to the list .... hi everyone. :slight_smile:

Michael

_______________________________________________
wxpython-users mailing list
wxpython-users@lists.wxwindows.org
http://lists.wxwindows.org/mailman/listinfo/wxpython-users