Thanks to visit codestin.com
Credit goes to github.com

Skip to content

WX/WXagg backend add code that zooms properly on a Mac with a Retina display #5631

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 5 commits into from
Dec 9, 2015
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
41 changes: 38 additions & 3 deletions lib/matplotlib/backends/backend_wx.py
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ def notify_axes_change(fig):

def show(self):
self.frame.Show()
self.canvas.draw()

def destroy(self, *args):
DEBUG_MSG("destroy()", 1, self)
Expand Down Expand Up @@ -1572,6 +1573,12 @@ def __init__(self, canvas):
self.canvas = canvas
self._idle = True
self.statbar = None
self.prevZoomRect = None
# for now, use alternate zoom-rectangle drawing on all
# Macs. N.B. In future versions of wx it may be possible to
# detect Retina displays with window.GetContentScaleFactor()
# and/or dc.GetContentScaleFactor()
self.retinaFix = 'wxMac' in wx.PlatformInfo

def get_canvas(self, frame, fig):
return FigureCanvasWx(frame, -1, fig)
Expand Down Expand Up @@ -1673,16 +1680,44 @@ def dynamic_update(self):

def press(self, event):
if self._active == 'ZOOM':
self.wxoverlay = wx.Overlay()
if not self.retinaFix:
self.wxoverlay = wx.Overlay()
else:
self.savedRetinaImage = self.canvas.copy_from_bbox(
self.canvas.figure.gca().bbox)
self.zoomStartX = event.xdata
self.zoomStartY = event.ydata

def release(self, event):
if self._active == 'ZOOM':
# When the mouse is released we reset the overlay and it
# restores the former content to the window.
self.wxoverlay.Reset()
del self.wxoverlay
if not self.retinaFix:
self.wxoverlay.Reset()
del self.wxoverlay
else:
del self.savedRetinaImage
if self.prevZoomRect:
self.prevZoomRect.pop(0).remove()
self.prevZoomRect = None

def draw_rubberband(self, event, x0, y0, x1, y1):
if self.retinaFix: # On Macs, use the following code
# wx.DCOverlay does not work properly on Retina displays.
rubberBandColor = '#C0C0FF'
if self.prevZoomRect:
self.prevZoomRect.pop(0).remove()
self.canvas.restore_region(self.savedRetinaImage)
X0, X1 = self.zoomStartX, event.xdata
Y0, Y1 = self.zoomStartY, event.ydata
lineX = (X0, X0, X1, X1, X0)
lineY = (Y0, Y1, Y1, Y0, Y0)
self.prevZoomRect = self.canvas.figure.gca().plot(
lineX, lineY, '-', color=rubberBandColor)
self.canvas.figure.gca().draw_artist(self.prevZoomRect[0])
self.canvas.blit(self.canvas.figure.gca().bbox)
return

# Use an Overlay to draw a rubberband-like bounding box.

dc = wx.ClientDC(self.canvas)
Expand Down