Skip to content

Commit ee84682

Browse files
committed
Merge branch 'v1.4.x' into master
2 parents 1a1b82d + 893352f commit ee84682

File tree

2 files changed

+40
-49
lines changed

2 files changed

+40
-49
lines changed

lib/matplotlib/backends/backend_webagg_core.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,8 @@ def get_javascript(cls, stream=None):
403403
for filetype, ext in sorted(FigureCanvasWebAggCore.
404404
get_supported_filetypes_grouped().
405405
items()):
406-
extensions.append(ext[0])
406+
if not ext[0] == 'pgf': # pgf does not support BytesIO
407+
extensions.append(ext[0])
407408
output.write("mpl.extensions = {0};\n\n".format(
408409
json.dumps(extensions)))
409410

lib/matplotlib/backends/backend_wx.py

+38-48
Original file line numberDiff line numberDiff line change
@@ -789,28 +789,12 @@ def draw_idle(self):
789789
"""
790790
DEBUG_MSG("draw_idle()", 1, self)
791791
self._isDrawn = False # Force redraw
792-
# Create a timer for handling draw_idle requests
793-
# If there are events pending when the timer is
794-
# complete, reset the timer and continue. The
795-
# alternative approach, binding to wx.EVT_IDLE,
796-
# doesn't behave as nicely.
797-
if hasattr(self,'_idletimer'):
798-
self._idletimer.Restart(IDLE_DELAY)
799-
else:
800-
self._idletimer = wx.FutureCall(IDLE_DELAY,self._onDrawIdle)
801-
# FutureCall is a backwards-compatible alias;
802-
# CallLater became available in 2.7.1.1.
803-
804-
def _onDrawIdle(self, *args, **kwargs):
805-
if wx.GetApp().Pending():
806-
self._idletimer.Restart(IDLE_DELAY, *args, **kwargs)
807-
else:
808-
del self._idletimer
809-
# GUI event or explicit draw call may already
810-
# have caused the draw to take place
811-
if not self._isDrawn:
812-
self.draw(*args, **kwargs)
813-
792+
793+
# Triggering a paint event is all that is needed to defer drawing
794+
# until later. The platform will send the event when it thinks it is
795+
# a good time (usually as soon as there are no other events pending).
796+
self.Refresh(eraseBackground=False)
797+
814798
def draw(self, drawDC=None):
815799
"""
816800
Render the figure using RendererWx instance renderer, or using a
@@ -1709,30 +1693,30 @@ def dynamic_update(self):
17091693
self.canvas.draw()
17101694
self._idle = True
17111695

1712-
def draw_rubberband(self, event, x0, y0, x1, y1):
1713-
'adapted from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/189744'
1714-
canvas = self.canvas
1715-
dc =wx.ClientDC(canvas)
1716-
1717-
# Set logical function to XOR for rubberbanding
1718-
dc.SetLogicalFunction(wx.XOR)
1696+
def press(self, event):
1697+
if self._active == 'ZOOM':
1698+
self.wxoverlay = wx.Overlay()
17191699

1720-
# Set dc brush and pen
1721-
# Here I set brush and pen to white and grey respectively
1722-
# You can set it to your own choices
1700+
def release(self, event):
1701+
if self._active == 'ZOOM':
1702+
# When the mouse is released we reset the overlay and it
1703+
# restores the former content to the window.
1704+
self.wxoverlay.Reset()
1705+
del self.wxoverlay
17231706

1724-
# The brush setting is not really needed since we
1725-
# dont do any filling of the dc. It is set just for
1726-
# the sake of completion.
1707+
def draw_rubberband(self, event, x0, y0, x1, y1):
1708+
# Use an Overlay to draw a rubberband-like bounding box.
17271709

1728-
wbrush =wx.Brush(wx.Colour(255,255,255), wx.TRANSPARENT)
1729-
wpen =wx.Pen(wx.Colour(200, 200, 200), 1, wx.SOLID)
1730-
dc.SetBrush(wbrush)
1731-
dc.SetPen(wpen)
1710+
dc = wx.ClientDC(self.canvas)
1711+
odc = wx.DCOverlay(self.wxoverlay, dc)
1712+
odc.Clear()
17321713

1714+
# Mac's DC is already the same as a GCDC, and it causes
1715+
# problems with the overlay if we try to use an actual
1716+
# wx.GCDC so don't try it.
1717+
if 'wxMac' not in wx.PlatformInfo:
1718+
dc = wx.GCDC(dc)
17331719

1734-
dc.ResetBoundingBox()
1735-
dc.BeginDrawing()
17361720
height = self.canvas.figure.bbox.height
17371721
y1 = height - y1
17381722
y0 = height - y0
@@ -1742,14 +1726,20 @@ def draw_rubberband(self, event, x0, y0, x1, y1):
17421726

17431727
w = x1 - x0
17441728
h = y1 - y0
1729+
rect = wx.Rect(x0, y0, w, h)
17451730

1746-
rect = int(x0), int(y0), int(w), int(h)
1747-
try: lastrect = self.lastrect
1748-
except AttributeError: pass
1749-
else: dc.DrawRectangle(*lastrect) #erase last
1750-
self.lastrect = rect
1751-
dc.DrawRectangle(*rect)
1752-
dc.EndDrawing()
1731+
rubberBandColor = '#C0C0FF' # or load from config?
1732+
1733+
# Set a pen for the border
1734+
color = wx.NamedColour(rubberBandColor)
1735+
dc.SetPen(wx.Pen(color, 1))
1736+
1737+
# use the same color, plus alpha for the brush
1738+
r, g, b = color.Get()
1739+
color.Set(r,g,b, 0x60)
1740+
dc.SetBrush(wx.Brush(color))
1741+
dc.DrawRectangleRect(rect)
1742+
17531743

17541744
def set_status_bar(self, statbar):
17551745
self.statbar = statbar

0 commit comments

Comments
 (0)