Skip to content

Commit 8d7ccb0

Browse files
committed
Fix issue #25164
1 parent baebe44 commit 8d7ccb0

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-1
lines changed

lib/matplotlib/backends/_backend_tk.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,8 @@ def _recolor_icon(image, color):
747747
# Use the high-resolution (48x48 px) icon if it exists and is needed
748748
with Image.open(path_large if (size > 24 and path_large.exists())
749749
else path_regular) as im:
750+
# assure a RGBA image as foreground color is RGB
751+
im = im.convert("RGBA")
750752
image = ImageTk.PhotoImage(im.resize((size, size)), master=self)
751753
button._ntimage = image
752754

lib/matplotlib/tests/test_backend_tk.py

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,19 @@
44
import platform
55
import subprocess
66
import sys
7+
import tempfile
8+
import warnings
9+
10+
from PIL import Image
711

812
import pytest
913

10-
from matplotlib.testing import subprocess_run_helper
14+
import matplotlib
1115
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+
1220

1321
_test_timeout = 60 # A reasonably safe value for slower architectures.
1422

@@ -177,6 +185,32 @@ def test_never_update():
177185
# checks them.
178186

179187

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+
180214
@_isolated_tk_test(success_count=2)
181215
def test_missing_back_button():
182216
import matplotlib.pyplot as plt

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy