GenButton mouse capture

I’m using wx.lib.buttons.GenButton and a very slow running Linux machine (Centos5 or Centos7, not sure which) showed up some odd problems that wouldn’t normally appear. I’ve subclassed GenButton to get round them, but thought the info might be useful. I’m using wxPython with Python 2.7 but checked the source for 4.0.4 and the relevant bits appear to be the same.

On occasion, a traceback was recieved from a click on the button:

Traceback (most recent call last):
  File "/usr/local/wxPython-src-", line 330, in OnLeftDown
  File "/usr/local/wxPython-src-", line 10638, in CaptureMouse
wx._core.PyAssertionError: C++ assertion "!wxMouseCapture::IsInCaptureStack(this)" failed at ../src/common/wincmn.cpp(3271) in CaptureMouse(): Recapturing the mouse in the same window?

I overrode OnLeftDown and added

        if self.HasCapture():

before calling the GenButton OnLeftDown.

On a separate run a traceback complained that EVT_MOUSE_CAPTURE_LOST wasn’t being handled. I bound this to an OnCaptureLost method but wasn’t sure what the action should be, so guesed that you’d want the button to appear in its normal state and used:

    def OnCaptureLost(self, evt):
        """ OnCaptureLost: if mouse capture lost, put button back to "up" state """
        self.up = True

@JillHolliday, are you able to make a GItHub PR with these changes?

I can make a draft patch of Not sure about the PR as I haven’t used Git - I’ll have to investigate.

I added an issue to help keep track of this:

Thanks Robin, I’ve just added a Pull Request and referenced the issue.