File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -1219,6 +1219,25 @@ def test_check_button_props(fig_test, fig_ref):
12191219 cb .set_check_props ({** check_props , 's' : (24 / 2 )** 2 })
12201220
12211221
1222+ @pytest .mark .parametrize ("widget" , [widgets .RadioButtons , widgets .CheckButtons ])
1223+ def test__buttons_callbacks (ax , widget ):
1224+ """Tests what https://github.com/matplotlib/matplotlib/pull/31031 fixed"""
1225+ on_clicked = mock .Mock (spec = noop , return_value = None )
1226+ button = widget (ax , ["Test Button" ])
1227+ button .on_clicked (on_clicked )
1228+ MouseEvent ._from_ax_coords (
1229+ "button_press_event" ,
1230+ ax ,
1231+ ax .transData .inverted ().transform (ax .transAxes .transform (
1232+ # (x, y) of the 0th button defined at
1233+ # `{Check,Radio}Buttons._init_props`
1234+ (0.15 , 0.5 ),
1235+ )),
1236+ 1 ,
1237+ )._process ()
1238+ on_clicked .assert_called_once ()
1239+
1240+
12221241def test_slider_slidermin_slidermax_invalid ():
12231242 fig , ax = plt .subplots ()
12241243 # test min/max with floats
Original file line number Diff line number Diff line change @@ -1110,11 +1110,11 @@ def _clicked(self, event):
11101110 if self .ignore (event ) or event .button != 1 or not self .ax .contains (event )[0 ]:
11111111 return
11121112 idxs = [ # Indices of frames and of texts that contain the event.
1113- * self ._frames .contains (event )[1 ]["ind" ],
1113+ * self ._buttons .contains (event )[1 ]["ind" ],
11141114 * [i for i , text in enumerate (self .labels ) if text .contains (event )[0 ]]]
11151115 if idxs :
1116- coords = self ._frames .get_offset_transform ().transform (
1117- self ._frames .get_offsets ())
1116+ coords = self ._buttons .get_offset_transform ().transform (
1117+ self ._buttons .get_offsets ())
11181118 self .set_active ( # Closest index, only looking in idxs.
11191119 idxs [(((event .x , event .y ) - coords [idxs ]) ** 2 ).sum (- 1 ).argmin ()])
11201120
You can’t perform that action at this time.
0 commit comments