views:

119

answers:

1

I'm trying to figure out how I can specify that the mouse_down event in wxPython (StyledTextCtrl) is first handled by the built in event listener, which changes the caret position, and then handled by my own custom event handler.

To bind the custom event handler I use wx.EVT_LEFT_DOWN(self.styCtrl, self.OnMouseClick)

def OnMouseClick(self, evt): evt.Skip() foo()

I want the built in event handler to fire and complete prior to foo().

+1  A: 

Never mind, I've figured out a solution. If someone has a more elegant solution it would be welcome. My solution uses the wx.CallAfter() approach:

def BindEvents(self):

    self.ctrl.Bind(wx.EVT_LEFT_DOWN, self.OnMouseClickDelay)

def OnMouseClickDelay(self, evt):
    wx.CallAfter(self.OnMouseClick, evt)
    evt.Skip()

def OnMouseClick(self, evt):
    foo()

This way, whatever the base control does on the event happens, and then the message queue will execute the actual OnMouseClick event. So foo() happens after internal event handling of ctrl

jhaukur