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 3.0.2.0 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-3.0.2.0/wxPython/wx/lib/buttons.py", line 330, in OnLeftDown
  File "/usr/local/wxPython-src-3.0.2.0/wxPython/wx/_core.py", 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():
            return

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
        self.Refresh()

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

I can make a draft patch of buttons.py. 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.