@@ -90,6 +90,34 @@ def onselect(epress, erelease):
90
90
assert tool .center == (180 , 190 )
91
91
92
92
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 ._selection_artist
108
+ assert artist .get_facecolor () == mcolors .to_rgba ('b' , alpha = 0.2 )
109
+ tool .set_props (facecolor = 'r' , alpha = 0.3 )
110
+ assert artist .get_facecolor () == mcolors .to_rgba ('r' , alpha = 0.3 )
111
+
112
+ for artist in tool ._handles_artists :
113
+ assert artist .get_markeredgecolor () == 'black'
114
+ assert artist .get_alpha () == 0.5
115
+ tool .set_handle_props (markeredgecolor = 'r' , alpha = 0.3 )
116
+ for artist in tool ._handles_artists :
117
+ assert artist .get_markeredgecolor () == 'r'
118
+ assert artist .get_alpha () == 0.3
119
+
120
+
93
121
def test_ellipse ():
94
122
"""For ellipse, test out the key modifiers"""
95
123
ax = get_ax ()
@@ -185,9 +213,9 @@ def onselect(epress, erelease):
185
213
186
214
# Check that marker_props worked.
187
215
assert mcolors .same_color (
188
- tool ._corner_handles .artist .get_markerfacecolor (), 'r' )
216
+ tool ._corner_handles .artists [ 0 ] .get_markerfacecolor (), 'r' )
189
217
assert mcolors .same_color (
190
- tool ._corner_handles .artist .get_markeredgecolor (), 'b' )
218
+ tool ._corner_handles .artists [ 0 ] .get_markeredgecolor (), 'b' )
191
219
192
220
193
221
@pytest .mark .parametrize ('interactive' , [True , False ])
@@ -404,6 +432,34 @@ def onselect(*args):
404
432
tool .direction = 'invalid_string'
405
433
406
434
435
+ def test_span_selector_set_props_handle_props ():
436
+ ax = get_ax ()
437
+
438
+ def onselect (epress , erelease ):
439
+ pass
440
+
441
+ tool = widgets .SpanSelector (ax , onselect , 'horizontal' , interactive = True ,
442
+ props = dict (facecolor = 'b' , alpha = 0.2 ),
443
+ handle_props = dict (alpha = 0.5 ))
444
+ # Create rectangle
445
+ do_event (tool , 'press' , xdata = 0 , ydata = 10 , button = 1 )
446
+ do_event (tool , 'onmove' , xdata = 100 , ydata = 120 , button = 1 )
447
+ do_event (tool , 'release' , xdata = 100 , ydata = 120 , button = 1 )
448
+
449
+ artist = tool ._selection_artist
450
+ assert artist .get_facecolor () == mcolors .to_rgba ('b' , alpha = 0.2 )
451
+ tool .set_props (facecolor = 'r' , alpha = 0.3 )
452
+ assert artist .get_facecolor () == mcolors .to_rgba ('r' , alpha = 0.3 )
453
+
454
+ for artist in tool ._handles_artists :
455
+ assert artist .get_color () == 'b'
456
+ assert artist .get_alpha () == 0.5
457
+ tool .set_handle_props (color = 'r' , alpha = 0.3 )
458
+ for artist in tool ._handles_artists :
459
+ assert artist .get_color () == 'r'
460
+ assert artist .get_alpha () == 0.3
461
+
462
+
407
463
def test_tool_line_handle ():
408
464
ax = get_ax ()
409
465
@@ -781,6 +837,43 @@ def test_polygon_selector():
781
837
check_polygon_selector (event_sequence , expected_result , 1 )
782
838
783
839
840
+ def test_polygon_selector_set_props_handle_props ():
841
+ ax = get_ax ()
842
+
843
+ ax ._selections_count = 0
844
+
845
+ def onselect (vertices ):
846
+ ax ._selections_count += 1
847
+ ax ._current_result = vertices
848
+
849
+ tool = widgets .PolygonSelector (ax , onselect ,
850
+ props = dict (color = 'b' , alpha = 0.2 ),
851
+ handle_props = dict (alpha = 0.5 ))
852
+
853
+ event_sequence = (polygon_place_vertex (50 , 50 )
854
+ + polygon_place_vertex (150 , 50 )
855
+ + polygon_place_vertex (50 , 150 )
856
+ + polygon_place_vertex (50 , 50 ))
857
+
858
+ for (etype , event_args ) in event_sequence :
859
+ do_event (tool , etype , ** event_args )
860
+
861
+ artist = tool ._selection_artist
862
+ assert artist .get_color () == 'b'
863
+ assert artist .get_alpha () == 0.2
864
+ tool .set_props (color = 'r' , alpha = 0.3 )
865
+ assert artist .get_color () == 'r'
866
+ assert artist .get_alpha () == 0.3
867
+
868
+ for artist in tool ._handles_artists :
869
+ assert artist .get_color () == 'b'
870
+ assert artist .get_alpha () == 0.5
871
+ tool .set_handle_props (color = 'r' , alpha = 0.3 )
872
+ for artist in tool ._handles_artists :
873
+ assert artist .get_color () == 'r'
874
+ assert artist .get_alpha () == 0.3
875
+
876
+
784
877
@pytest .mark .parametrize (
785
878
"horizOn, vertOn" ,
786
879
[(True , True ), (True , False ), (False , True )],
0 commit comments