@@ -90,6 +90,36 @@ def onselect(epress, erelease):
9090 assert tool .center == (180 , 190 )
9191
9292
93+ def test_rectangle_selector_set_props_handle_props ():
94+ ax = get_ax ()
95+
96+ def onselect (epress , erelease ):
97+ pass
98+
99+ tool = widgets .RectangleSelector (ax , onselect , interactive = True ,
100+ props = dict (facecolor = 'b' , alpha = 0.2 ),
101+ handle_props = dict (alpha = 0.5 ))
102+ # Create rectangle
103+ do_event (tool , 'press' , xdata = 0 , ydata = 10 , button = 1 )
104+ do_event (tool , 'onmove' , xdata = 100 , ydata = 120 , button = 1 )
105+ do_event (tool , 'release' , xdata = 100 , ydata = 120 , button = 1 )
106+
107+ artist = tool .artists [0 ]
108+ assert artist .get_facecolor () == mcolors .to_rgba ('b' , alpha = 0.2 )
109+ props = dict (facecolor = 'r' , alpha = 0.3 )
110+ tool .set_props (** props )
111+ assert artist .get_facecolor () == mcolors .to_rgba (* props .values ())
112+
113+ for artist in tool ._handles_artists :
114+ assert artist .get_markeredgecolor () == 'black'
115+ assert artist .get_alpha () == 0.5
116+ handle_props = dict (markeredgecolor = 'r' , alpha = 0.3 )
117+ tool .set_handle_props (** handle_props )
118+ for artist in tool ._handles_artists :
119+ assert artist .get_markeredgecolor () == 'r'
120+ assert artist .get_alpha () == 0.3
121+
122+
93123def test_ellipse ():
94124 """For ellipse, test out the key modifiers"""
95125 ax = get_ax ()
@@ -185,9 +215,9 @@ def onselect(epress, erelease):
185215
186216 # Check that marker_props worked.
187217 assert mcolors .same_color (
188- tool ._corner_handles .artist .get_markerfacecolor (), 'r' )
218+ tool ._corner_handles .artists [ 0 ] .get_markerfacecolor (), 'r' )
189219 assert mcolors .same_color (
190- tool ._corner_handles .artist .get_markeredgecolor (), 'b' )
220+ tool ._corner_handles .artists [ 0 ] .get_markeredgecolor (), 'b' )
191221
192222
193223@pytest .mark .parametrize ('interactive' , [True , False ])
@@ -404,6 +434,36 @@ def onselect(*args):
404434 tool .direction = 'invalid_string'
405435
406436
437+ def test_span_selector_set_props_handle_props ():
438+ ax = get_ax ()
439+
440+ def onselect (epress , erelease ):
441+ pass
442+
443+ tool = widgets .SpanSelector (ax , onselect , 'horizontal' , interactive = True ,
444+ props = dict (facecolor = 'b' , alpha = 0.2 ),
445+ handle_props = dict (alpha = 0.5 ))
446+ # Create rectangle
447+ do_event (tool , 'press' , xdata = 0 , ydata = 10 , button = 1 )
448+ do_event (tool , 'onmove' , xdata = 100 , ydata = 120 , button = 1 )
449+ do_event (tool , 'release' , xdata = 100 , ydata = 120 , button = 1 )
450+
451+ artist = tool .artists [0 ]
452+ assert artist .get_facecolor () == mcolors .to_rgba ('b' , alpha = 0.2 )
453+ props = dict (facecolor = 'r' , alpha = 0.3 )
454+ tool .set_props (** props )
455+ assert artist .get_facecolor () == mcolors .to_rgba (* props .values ())
456+
457+ for artist in tool ._handles_artists :
458+ assert artist .get_color () == 'b'
459+ assert artist .get_alpha () == 0.5
460+ handle_props = dict (color = 'r' , alpha = 0.3 )
461+ tool .set_handle_props (** handle_props )
462+ for artist in tool ._handles_artists :
463+ assert artist .get_color () == 'r'
464+ assert artist .get_alpha () == 0.3
465+
466+
407467def test_tool_line_handle ():
408468 ax = get_ax ()
409469
@@ -781,6 +841,45 @@ def test_polygon_selector():
781841 check_polygon_selector (event_sequence , expected_result , 1 )
782842
783843
844+ def test_polygon_selector_set_props_handle_props ():
845+ ax = get_ax ()
846+
847+ ax ._selections_count = 0
848+
849+ def onselect (vertices ):
850+ ax ._selections_count += 1
851+ ax ._current_result = vertices
852+
853+ tool = widgets .PolygonSelector (ax , onselect ,
854+ props = dict (color = 'b' , alpha = 0.2 ),
855+ handle_props = dict (alpha = 0.5 ))
856+
857+ event_sequence = (polygon_place_vertex (50 , 50 )
858+ + polygon_place_vertex (150 , 50 )
859+ + polygon_place_vertex (50 , 150 )
860+ + polygon_place_vertex (50 , 50 ))
861+
862+ for (etype , event_args ) in event_sequence :
863+ do_event (tool , etype , ** event_args )
864+
865+ artist = tool .artists [0 ]
866+ assert artist .get_color () == 'b'
867+ assert artist .get_alpha () == 0.2
868+ props = dict (color = 'r' , alpha = 0.3 )
869+ tool .set_props (** props )
870+ assert artist .get_color () == props ['color' ]
871+ assert artist .get_alpha () == props ['alpha' ]
872+
873+ for artist in tool ._handles_artists :
874+ assert artist .get_color () == 'b'
875+ assert artist .get_alpha () == 0.5
876+ handle_props = dict (color = 'r' , alpha = 0.3 )
877+ tool .set_handle_props (** handle_props )
878+ for artist in tool ._handles_artists :
879+ assert artist .get_color () == 'r'
880+ assert artist .get_alpha () == 0.3
881+
882+
784883@pytest .mark .parametrize (
785884 "horizOn, vertOn" ,
786885 [(True , True ), (True , False ), (False , True )],
0 commit comments