EVT_RIGHT_DOWN vs EVT_CONTEXT_MENU

When I run the Python program below, EVT_RIGHT_DOWN events are caught and the mouse
position is shown in the title. When I run this program under control of another program (StoryText)
which catches both EVT_RIGHT_DOWN and EVT_CONTEXT_MENU events, the Skip call in the OnRightDown
method below results in StoryText catching an EVT_CONTEXT_MENU event, not an EVT_RIGHT_DOWN
event, even though it was the latter which caused OnRightDown to be called.

I would really like for the EVT_RIGHT_DOWN event to be propagated to StoryText. I'm guess that
EVT_CONTEXT_MENU is constructed when an EVT_RIGHT_DOWN is followed by an EVT_RIGHT_UP, so
perhaps both EVT_RIGHT_DOWN and EVT_CONTEXT_MENU are generated when this program is
run. But why is the latter propagated from a method for handling the former?

My first thought about how to approach this was to look at ALL events occurring while running this program.
I have not been able to find any info on how to do this. Older postings state that it can't be done. Has
this situation changed?

Thank you for your help.

Roger House

import wx

class MyApp(wx.App):
     def OnInit(self):
         self.frame = MyFrame(None, title="Right Down Example")
         self.SetTopWindow(self.frame)
         self.frame.Show()
         return True

class MyFrame(wx.Frame):
     def __init__(self, *args, **kwargs):
         super(MyFrame, self).__init__(*args, **kwargs)
         self.panel = p = wx.Panel(self)

         wx.StaticText(p, -1,
             "Right-down on the panel to change the title", (25,25))

         p.Bind(wx.EVT_RIGHT_DOWN, self.OnRightDown)

     def OnRightDown(self, event):
         pos = event.GetPosition()
         mess = "Mouse is at " + str(pos)
         self.SetTitle(mess)
         event.Skip()

     def OnExit(self, event):
         self.Close()

if __name__ == "__main__":
     app = MyApp(False)
     app.MainLoop()

When I run the Python program below, EVT_RIGHT_DOWN events are caught
and the mouse
position is shown in the title. When I run this program under control of
another program (StoryText)
which catches both EVT_RIGHT_DOWN and EVT_CONTEXT_MENU events, the Skip
call in the OnRightDown
method below results in StoryText catching an EVT_CONTEXT_MENU event,
not an EVT_RIGHT_DOWN
event, even though it was the latter which caused OnRightDown to be called.

I would really like for the EVT_RIGHT_DOWN event to be propagated to
StoryText. I'm guess that
EVT_CONTEXT_MENU is constructed when an EVT_RIGHT_DOWN is followed by an
EVT_RIGHT_UP, so
perhaps both EVT_RIGHT_DOWN and EVT_CONTEXT_MENU are generated when this
program is
run. But why is the latter propagated from a method for handling the
former?

It depends on the platform. Some will generate the context menu event before the right-up if the right-down was not handled. (This lets the user popup the menu and select an item with one click-move-release action.) Others will generate the context menu event from the right-up if both the right-down and right-up are unhandled. It can also depend on the widget type as some native widgets will capture some mouse events before wx has a chance to see them and send the wx.MouseEvent.

By calling event.Skip() you are telling wx that even though you handled the event that it should still be considered unhandled, and so the system will go on to eventually send the context menu event. If you don't want the context menu event then it should work if you do not call Skip.

My first thought about how to approach this was to look at ALL events
occurring while running this program.
I have not been able to find any info on how to do this. Older postings
state that it can't be done. Has
this situation changed?

The WIT has the ability to show you a log of all (or selected) events for a particular widget. http://wiki.wxpython.org/Widget_Inspection_Tool

···

On 5/16/12 4:37 PM, Roger House wrote:

--
Robin Dunn
Software Craftsman