From 459d222356d12076a8fe5620a0e7194ffa448618 Mon Sep 17 00:00:00 2001 From: Joel Frederico <458871+joelfrederico@users.noreply.github.com> Date: Sun, 28 Nov 2021 14:48:41 -0500 Subject: [PATCH] Set icon properly for macOS On most platforms, windows have their own icons that are displayed in conjunction with windows. On macOS, icons are used differently. Individual windows should not have an icon unless they are associated with a file. On the other hand, processes ("Apps") have icons that can be set. If Matplotlib is running a FigureManagerBase, then we can assume that Matplotlib can be responsible for setting the process icon. --- lib/matplotlib/backends/backend_qt.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/matplotlib/backends/backend_qt.py b/lib/matplotlib/backends/backend_qt.py index 3f377929837d..c55937a019ea 100644 --- a/lib/matplotlib/backends/backend_qt.py +++ b/lib/matplotlib/backends/backend_qt.py @@ -1,7 +1,6 @@ import functools import operator import os -import signal import sys import traceback @@ -121,6 +120,10 @@ def _create_qApp(): except AttributeError: # Only for Qt>=5.14. pass qApp = QtWidgets.QApplication(["matplotlib"]) + if sys.platform == "darwin": + image = str(cbook._get_data_path('images/matplotlib.svg')) + icon = QtGui.QIcon(image) + qApp.setWindowIcon(icon) qApp.lastWindowClosed.connect(qApp.quit) cbook._setup_new_guiapp() else: @@ -519,8 +522,10 @@ def __init__(self, canvas, num): self.window.closing.connect(canvas.close_event) self.window.closing.connect(self._widgetclosed) - image = str(cbook._get_data_path('images/matplotlib.svg')) - self.window.setWindowIcon(QtGui.QIcon(image)) + if sys.platform != "darwin": + image = str(cbook._get_data_path('images/matplotlib.svg')) + icon = QtGui.QIcon(image) + self.window.setWindowIcon(icon) self.window._destroying = False