|
4 | 4 | import platform
|
5 | 5 | import subprocess
|
6 | 6 | import sys
|
| 7 | +import tempfile |
| 8 | +import warnings |
| 9 | + |
| 10 | +from PIL import Image |
7 | 11 |
|
8 | 12 | import pytest
|
9 | 13 |
|
10 |
| -from matplotlib.testing import subprocess_run_helper |
| 14 | +import matplotlib |
11 | 15 | from matplotlib import _c_internal_utils
|
| 16 | +from matplotlib.backend_tools import ToolToggleBase |
| 17 | +from matplotlib.testing import subprocess_run_helper |
| 18 | +import matplotlib.pyplot as plt |
| 19 | + |
12 | 20 |
|
13 | 21 | _test_timeout = 60 # A reasonably safe value for slower architectures.
|
14 | 22 |
|
@@ -177,6 +185,32 @@ def test_never_update():
|
177 | 185 | # checks them.
|
178 | 186 |
|
179 | 187 |
|
| 188 | +@pytest.mark.backend('TkAgg', skip_on_importerror=True) |
| 189 | +@_isolated_tk_test(success_count=0) |
| 190 | +def test_toolbar_button_la_mode_icon(): |
| 191 | + # test that icon in LA mode can be used for buttons |
| 192 | + # see GH#25164 |
| 193 | + # tweaking toolbar raises an UserWarning |
| 194 | + with warnings.catch_warnings(): |
| 195 | + warnings.simplefilter("ignore", UserWarning) |
| 196 | + matplotlib.rcParams["toolbar"] = "toolmanager" |
| 197 | + |
| 198 | + # create an icon in LA mode |
| 199 | + with tempfile.TemporaryDirectory() as tempdir: |
| 200 | + img = Image.new("LA", (26, 26)) |
| 201 | + tmp_img_path = os.path.join(tempdir, "test_la_icon.png") |
| 202 | + img.save(tmp_img_path) |
| 203 | + |
| 204 | + class CustomTool(ToolToggleBase): |
| 205 | + image = tmp_img_path |
| 206 | + |
| 207 | + fig = plt.figure() |
| 208 | + toolmanager = fig.canvas.manager.toolmanager |
| 209 | + toolbar = fig.canvas.manager.toolbar |
| 210 | + toolmanager.add_tool("test", CustomTool) |
| 211 | + toolbar.add_tool("test", "group") |
| 212 | + |
| 213 | + |
180 | 214 | @_isolated_tk_test(success_count=2)
|
181 | 215 | def test_missing_back_button():
|
182 | 216 | import matplotlib.pyplot as plt
|
|
0 commit comments