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

Skip to content

Commit 86f28fa

Browse files
tacaswellblink1073
authored andcommitted
TST : ensure canvas drawn before testing widets
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.
1 parent d711940 commit 86f28fa

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

lib/matplotlib/tests/test_widgets.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,9 @@ def get_event(ax, button=1, xdata=0, ydata=0, key=None, step=1):
6565

6666
@cleanup
6767
def check_rectangle(**kwargs):
68-
ax = plt.gca()
68+
fig, ax = plt.subplots(1, 1)
6969
ax.plot([0, 200], [0, 200])
70+
ax.figure.canvas.draw()
7071

7172
def onselect(epress, erelease):
7273
ax._got_onselect = True
@@ -100,8 +101,9 @@ def test_rectangle_selector():
100101

101102
@cleanup
102103
def check_span(*args, **kwargs):
103-
ax = plt.gca()
104+
fig, ax = plt.subplots(1, 1)
104105
ax.plot([0, 200], [0, 200])
106+
ax.figure.canvas.draw()
105107

106108
def onselect(vmin, vmax):
107109
ax._got_onselect = True
@@ -140,8 +142,10 @@ def test_span_selector():
140142

141143
@cleanup
142144
def check_lasso_selector(**kwargs):
145+
fig, ax = plt.subplots(1, 1)
143146
ax = plt.gca()
144147
ax.plot([0, 200], [0, 200])
148+
ax.figure.canvas.draw()
145149

146150
def onselect(verts):
147151
ax._got_onselect = True

lib/matplotlib/widgets.py

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,16 +1182,10 @@ def update(self):
11821182
if self.background is not None:
11831183
self.canvas.restore_region(self.background)
11841184
for artist in self.artists:
1185-
try:
1186-
self.ax.draw_artist(artist)
1187-
except AssertionError:
1188-
self.canvas.draw_idle()
1189-
return False
1190-
try:
1191-
self.canvas.blit(self.ax.bbox)
1192-
except AttributeError:
1193-
self.canvas.draw_idle()
1194-
return False
1185+
self.ax.draw_artist(artist)
1186+
1187+
self.canvas.blit(self.ax.bbox)
1188+
11951189
else:
11961190
self.canvas.draw_idle()
11971191
return False

0 commit comments

Comments
 (0)