Skip to content

Commit

Permalink
TST : ensure canvas drawn before testing widets
Browse files Browse the repository at this point in the history
Widgets assume that the canvas has been drawn atleast once
before they are called (which is reasonable for interactive usage
as the user needs to be able to _see_ the gui before they can
interact with it).  Ensure that the tests draw the canvas
before trying to use the widgets.  Doing this allows for removing
some of the error handling logic from the widgets.
  • Loading branch information
tacaswell authored and blink1073 committed Nov 12, 2014
1 parent d711940 commit 86f28fa
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
8 changes: 6 additions & 2 deletions lib/matplotlib/tests/test_widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,9 @@ def get_event(ax, button=1, xdata=0, ydata=0, key=None, step=1):

@cleanup
def check_rectangle(**kwargs):
ax = plt.gca()
fig, ax = plt.subplots(1, 1)
ax.plot([0, 200], [0, 200])
ax.figure.canvas.draw()

def onselect(epress, erelease):
ax._got_onselect = True
Expand Down Expand Up @@ -100,8 +101,9 @@ def test_rectangle_selector():

@cleanup
def check_span(*args, **kwargs):
ax = plt.gca()
fig, ax = plt.subplots(1, 1)
ax.plot([0, 200], [0, 200])
ax.figure.canvas.draw()

def onselect(vmin, vmax):
ax._got_onselect = True
Expand Down Expand Up @@ -140,8 +142,10 @@ def test_span_selector():

@cleanup
def check_lasso_selector(**kwargs):
fig, ax = plt.subplots(1, 1)
ax = plt.gca()
ax.plot([0, 200], [0, 200])
ax.figure.canvas.draw()

def onselect(verts):
ax._got_onselect = True
Expand Down
14 changes: 4 additions & 10 deletions lib/matplotlib/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -1182,16 +1182,10 @@ def update(self):
if self.background is not None:
self.canvas.restore_region(self.background)
for artist in self.artists:
try:
self.ax.draw_artist(artist)
except AssertionError:
self.canvas.draw_idle()
return False
try:
self.canvas.blit(self.ax.bbox)
except AttributeError:
self.canvas.draw_idle()
return False
self.ax.draw_artist(artist)

self.canvas.blit(self.ax.bbox)

else:
self.canvas.draw_idle()
return False
Expand Down

0 comments on commit 86f28fa

Please sign in to comment.