@@ -90,6 +90,36 @@ 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 .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
+
93
123
def test_ellipse ():
94
124
"""For ellipse, test out the key modifiers"""
95
125
ax = get_ax ()
@@ -185,9 +215,9 @@ def onselect(epress, erelease):
185
215
186
216
# Check that marker_props worked.
187
217
assert mcolors .same_color (
188
- tool ._corner_handles .artist .get_markerfacecolor (), 'r' )
218
+ tool ._corner_handles .artists [ 0 ] .get_markerfacecolor (), 'r' )
189
219
assert mcolors .same_color (
190
- tool ._corner_handles .artist .get_markeredgecolor (), 'b' )
220
+ tool ._corner_handles .artists [ 0 ] .get_markeredgecolor (), 'b' )
191
221
192
222
193
223
def check_span (* args , ** kwargs ):
@@ -281,6 +311,36 @@ def onselect(epress, erelease):
281
311
tool .direction = 'invalid_string'
282
312
283
313
314
+ def test_span_selector_set_props_handle_props ():
315
+ ax = get_ax ()
316
+
317
+ def onselect (epress , erelease ):
318
+ pass
319
+
320
+ tool = widgets .SpanSelector (ax , onselect , 'horizontal' , interactive = True ,
321
+ props = dict (facecolor = 'b' , alpha = 0.2 ),
322
+ handle_props = dict (alpha = 0.5 ))
323
+ # Create rectangle
324
+ do_event (tool , 'press' , xdata = 0 , ydata = 10 , button = 1 )
325
+ do_event (tool , 'onmove' , xdata = 100 , ydata = 120 , button = 1 )
326
+ do_event (tool , 'release' , xdata = 100 , ydata = 120 , button = 1 )
327
+
328
+ artist = tool .artists [0 ]
329
+ assert artist .get_facecolor () == mcolors .to_rgba ('b' , alpha = 0.2 )
330
+ props = dict (facecolor = 'r' , alpha = 0.3 )
331
+ tool .set_props (** props )
332
+ assert artist .get_facecolor () == mcolors .to_rgba (* props .values ())
333
+
334
+ for artist in tool ._handles_artists :
335
+ assert artist .get_color () == 'b'
336
+ assert artist .get_alpha () == 0.5
337
+ handle_props = dict (color = 'r' , alpha = 0.3 )
338
+ tool .set_handle_props (** handle_props )
339
+ for artist in tool ._handles_artists :
340
+ assert artist .get_color () == 'r'
341
+ assert artist .get_alpha () == 0.3
342
+
343
+
284
344
def test_tool_line_handle ():
285
345
ax = get_ax ()
286
346
@@ -658,6 +718,45 @@ def test_polygon_selector():
658
718
check_polygon_selector (event_sequence , expected_result , 1 )
659
719
660
720
721
+ def test_polygon_selector_set_props_handle_props ():
722
+ ax = get_ax ()
723
+
724
+ ax ._selections_count = 0
725
+
726
+ def onselect (vertices ):
727
+ ax ._selections_count += 1
728
+ ax ._current_result = vertices
729
+
730
+ tool = widgets .PolygonSelector (ax , onselect ,
731
+ props = dict (color = 'b' , alpha = 0.2 ),
732
+ handle_props = dict (alpha = 0.5 ))
733
+
734
+ event_sequence = (polygon_place_vertex (50 , 50 )
735
+ + polygon_place_vertex (150 , 50 )
736
+ + polygon_place_vertex (50 , 150 )
737
+ + polygon_place_vertex (50 , 50 ))
738
+
739
+ for (etype , event_args ) in event_sequence :
740
+ do_event (tool , etype , ** event_args )
741
+
742
+ artist = tool .artists [0 ]
743
+ assert artist .get_color () == 'b'
744
+ assert artist .get_alpha () == 0.2
745
+ props = dict (color = 'r' , alpha = 0.3 )
746
+ tool .set_props (** props )
747
+ assert artist .get_color () == props ['color' ]
748
+ assert artist .get_alpha () == props ['alpha' ]
749
+
750
+ for artist in tool ._handles_artists :
751
+ assert artist .get_color () == 'b'
752
+ assert artist .get_alpha () == 0.5
753
+ handle_props = dict (color = 'r' , alpha = 0.3 )
754
+ tool .set_handle_props (** handle_props )
755
+ for artist in tool ._handles_artists :
756
+ assert artist .get_color () == 'r'
757
+ assert artist .get_alpha () == 0.3
758
+
759
+
661
760
@pytest .mark .parametrize (
662
761
"horizOn, vertOn" ,
663
762
[(True , True ), (True , False ), (False , True )],
0 commit comments