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

Skip to content

Commit 459d222

Browse files
committed
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.
1 parent 25a54a4 commit 459d222

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/matplotlib/backends/backend_qt.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import functools
22
import operator
33
import os
4-
import signal
54
import sys
65
import traceback
76

@@ -121,6 +120,10 @@ def _create_qApp():
121120
except AttributeError: # Only for Qt>=5.14.
122121
pass
123122
qApp = QtWidgets.QApplication(["matplotlib"])
123+
if sys.platform == "darwin":
124+
image = str(cbook._get_data_path('images/matplotlib.svg'))
125+
icon = QtGui.QIcon(image)
126+
qApp.setWindowIcon(icon)
124127
qApp.lastWindowClosed.connect(qApp.quit)
125128
cbook._setup_new_guiapp()
126129
else:
@@ -519,8 +522,10 @@ def __init__(self, canvas, num):
519522
self.window.closing.connect(canvas.close_event)
520523
self.window.closing.connect(self._widgetclosed)
521524

522-
image = str(cbook._get_data_path('images/matplotlib.svg'))
523-
self.window.setWindowIcon(QtGui.QIcon(image))
525+
if sys.platform != "darwin":
526+
image = str(cbook._get_data_path('images/matplotlib.svg'))
527+
icon = QtGui.QIcon(image)
528+
self.window.setWindowIcon(icon)
524529

525530
self.window._destroying = False
526531

0 commit comments

Comments
 (0)