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

Skip to content

Commit 4352733

Browse files
authored
Move ToolManager warnings to rcParam validator
Applies patch from #15284 (comment)
1 parent e69c490 commit 4352733

File tree

4 files changed

+29
-32
lines changed

4 files changed

+29
-32
lines changed

lib/matplotlib/backend_managers.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import logging
2-
31
from matplotlib import _api, cbook, widgets
42
from matplotlib.rcsetup import validate_stringlist
53
import matplotlib.backend_tools as tools
64

7-
_log = logging.getLogger(__name__)
8-
95

106
class ToolEvent:
117
"""Event for tool manipulation (add/remove)."""
@@ -50,9 +46,6 @@ class ToolManager:
5046
"""
5147

5248
def __init__(self, figure=None):
53-
_log.warning('Treat the new Tool classes introduced in v1.5 as '
54-
'experimental for now, the API will likely change in '
55-
'version 2.1 and perhaps the rcParam as well')
5649

5750
self._key_press_handler_id = None
5851

lib/matplotlib/backend_tools.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
"""
1313

1414
from enum import IntEnum
15-
import logging
1615
import re
1716
import time
1817
from types import SimpleNamespace
@@ -25,8 +24,6 @@
2524
from matplotlib._pylab_helpers import Gcf
2625
from matplotlib import _api, cbook
2726

28-
_log = logging.getLogger(__name__)
29-
3027

3128
class Cursors(IntEnum): # Must subclass int for the macOS backend.
3229
"""Backend-independent cursor types."""
@@ -80,9 +77,6 @@ class ToolBase:
8077
"""
8178

8279
def __init__(self, toolmanager, name):
83-
_api.warn_external(
84-
'The new Tool classes introduced in v1.5 are experimental; their '
85-
'API (including names) will likely change in future versions.')
8680
self._name = name
8781
self._toolmanager = toolmanager
8882
self._figure = None

lib/matplotlib/rcsetup.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515

1616
import ast
1717
from functools import lru_cache, reduce
18-
import logging
1918
from numbers import Number
2019
import operator
2120
import re
@@ -32,7 +31,6 @@
3231
from cycler import Cycler, cycler as ccycler
3332

3433

35-
_log = logging.getLogger(__name__)
3634
# The capitalized forms are needed for ipython at present; this may
3735
# change for later versions.
3836
interactive_bk = ['GTK3Agg', 'GTK3Cairo',
@@ -310,6 +308,16 @@ def validate_backend(s):
310308
_deprecated_since="3.3")
311309

312310

311+
def _validate_toolbar(s):
312+
s = ValidateInStrings(
313+
'toolbar', ['None', 'toolbar2', 'toolmanager'], ignorecase=True)(s)
314+
if s == 'toolmanager':
315+
_api.warn_external(
316+
"Treat the new Tool classes introduced in v1.5 as experimental "
317+
"for now; the API and rcParam may change in future versions.")
318+
return s
319+
320+
313321
@_api.deprecated("3.3")
314322
def _make_nseq_validator(cls, n=None, allow_none=False):
315323

@@ -984,7 +992,7 @@ def _convert_validator_spec(key, conv):
984992
_validators = {
985993
"backend": validate_backend,
986994
"backend_fallback": validate_bool,
987-
"toolbar": _ignorecase(["none", "toolbar2", "toolmanager"]),
995+
"toolbar": _validate_toolbar,
988996
"interactive": validate_bool,
989997
"timezone": validate_string,
990998

lib/matplotlib/tests/test_backend_bases.py

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -167,21 +167,23 @@ def test_interactive_zoom():
167167

168168

169169
def test_toolbar_zoompan():
170-
plt.rcParams['toolbar'] = 'toolmanager'
170+
expected_warning_regex = (
171+
r"Treat the new Tool classes introduced in "
172+
r"v[0-9]*.[0-9]* as experimental for now; "
173+
"the API and rcParam may change in future versions.")
174+
with pytest.warns(UserWarning, match=expected_warning_regex):
175+
plt.rcParams['toolbar'] = 'toolmanager'
171176
ax = plt.gca()
172177
assert ax.get_navigate_mode() is None
173-
expected_warning_regex = (r"The new Tool classes introduced in "
174-
r"v[0-9]*.[0-9]* are experimental")
175-
with pytest.warns(UserWarning, match=expected_warning_regex) as rec:
176-
ax.figure.canvas.manager.toolmanager.add_tool(name="zoom",
177-
tool=ToolZoom)
178-
ax.figure.canvas.manager.toolmanager.add_tool(name="pan",
179-
tool=ToolPan)
180-
ax.figure.canvas.manager.toolmanager.add_tool(name=_views_positions,
181-
tool=ToolViewsPositions)
182-
ax.figure.canvas.manager.toolmanager.add_tool(name='rubberband',
183-
tool=RubberbandBase)
184-
ax.figure.canvas.manager.toolmanager.trigger_tool('zoom')
185-
assert ax.get_navigate_mode() == "ZOOM"
186-
ax.figure.canvas.manager.toolmanager.trigger_tool('pan')
187-
assert ax.get_navigate_mode() == "PAN"
178+
ax.figure.canvas.manager.toolmanager.add_tool(name="zoom",
179+
tool=ToolZoom)
180+
ax.figure.canvas.manager.toolmanager.add_tool(name="pan",
181+
tool=ToolPan)
182+
ax.figure.canvas.manager.toolmanager.add_tool(name=_views_positions,
183+
tool=ToolViewsPositions)
184+
ax.figure.canvas.manager.toolmanager.add_tool(name='rubberband',
185+
tool=RubberbandBase)
186+
ax.figure.canvas.manager.toolmanager.trigger_tool('zoom')
187+
assert ax.get_navigate_mode() == "ZOOM"
188+
ax.figure.canvas.manager.toolmanager.trigger_tool('pan')
189+
assert ax.get_navigate_mode() == "PAN"

0 commit comments

Comments
 (0)