Skip to content

bugfix for wx backend: release mouse on loss of focus and before trying to recapture #7752

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 24, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 23 additions & 12 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -685,6 +685,9 @@ def do_nothing(*args, **kwargs):
self.Bind(wx.EVT_MIDDLE_DCLICK, self._onMiddleButtonDClick)
self.Bind(wx.EVT_MIDDLE_UP, self._onMiddleButtonUp)

self.Bind(wx.EVT_MOUSE_CAPTURE_CHANGED, self._onCaptureLost)
self.Bind(wx.EVT_MOUSE_CAPTURE_LOST, self._onCaptureLost)

if wx.VERSION_STRING < "2.9":
# only needed in 2.8 to reduce flicker
self.SetBackgroundStyle(wx.BG_STYLE_CUSTOM)
Expand Down Expand Up @@ -1023,20 +1026,31 @@ def _onKeyUp(self, evt):
evt.Skip()
FigureCanvasBase.key_release_event(self, key, guiEvent=evt)

def _set_capture(self, capture=True):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see it being called anywhere without a value, so maybe the default value isn't necessary.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What would be gained by removing the default value?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Enforced explicitness at all callers (if that's what's required).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@QuLogic Sorry, I do not understand the meaning of your response -- If what is required?

The call signature is part of the documentation. Turning a keyword arg into a positional arg makes the code less readable. Won't change.

"""control wx mouse capture """
if self.HasCapture():
self.ReleaseMouse()
if capture:
self.CaptureMouse()

def _onCaptureLost(self, evt):
"""Capture changed or lost"""
self._set_capture(False)

def _onRightButtonDown(self, evt):
"""Start measuring on an axis."""
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
evt.Skip()
self.CaptureMouse()
self._set_capture(True)
FigureCanvasBase.button_press_event(self, x, y, 3, guiEvent=evt)

def _onRightButtonDClick(self, evt):
"""Start measuring on an axis."""
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
evt.Skip()
self.CaptureMouse()
self._set_capture(True)
FigureCanvasBase.button_press_event(self, x, y, 3,
dblclick=True, guiEvent=evt)

Expand All @@ -1045,24 +1059,23 @@ def _onRightButtonUp(self, evt):
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
evt.Skip()
if self.HasCapture():
self.ReleaseMouse()
self._set_capture(False)
FigureCanvasBase.button_release_event(self, x, y, 3, guiEvent=evt)

def _onLeftButtonDown(self, evt):
"""Start measuring on an axis."""
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
evt.Skip()
self.CaptureMouse()
self._set_capture(True)
FigureCanvasBase.button_press_event(self, x, y, 1, guiEvent=evt)

def _onLeftButtonDClick(self, evt):
"""Start measuring on an axis."""
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
evt.Skip()
self.CaptureMouse()
self._set_capture(True)
FigureCanvasBase.button_press_event(self, x, y, 1,
dblclick=True, guiEvent=evt)

Expand All @@ -1072,8 +1085,7 @@ def _onLeftButtonUp(self, evt):
y = self.figure.bbox.height - evt.GetY()
# print 'release button', 1
evt.Skip()
if self.HasCapture():
self.ReleaseMouse()
self._set_capture(False)
FigureCanvasBase.button_release_event(self, x, y, 1, guiEvent=evt)

# Add middle button events
Expand All @@ -1082,15 +1094,15 @@ def _onMiddleButtonDown(self, evt):
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
evt.Skip()
self.CaptureMouse()
self._set_capture(True)
FigureCanvasBase.button_press_event(self, x, y, 2, guiEvent=evt)

def _onMiddleButtonDClick(self, evt):
"""Start measuring on an axis."""
x = evt.GetX()
y = self.figure.bbox.height - evt.GetY()
evt.Skip()
self.CaptureMouse()
self._set_capture(True)
FigureCanvasBase.button_press_event(self, x, y, 2,
dblclick=True, guiEvent=evt)

Expand All @@ -1100,8 +1112,7 @@ def _onMiddleButtonUp(self, evt):
y = self.figure.bbox.height - evt.GetY()
# print 'release button', 1
evt.Skip()
if self.HasCapture():
self.ReleaseMouse()
self._set_capture(False)
FigureCanvasBase.button_release_event(self, x, y, 2, guiEvent=evt)

def _onMouseWheel(self, evt):
Expand Down