FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Set macOS icon when using Qt backend by joelfrederico · Pull Request #21784 · matplotlib/matplotlib · GitHub

Repository navigation

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .py  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
11 changes: 8 additions & 3 deletions lib/matplotlib/backends/backend_qt.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import functools
import operator
import os
import signal
import sys
import traceback

Expand Down Expand Up @@ -121,6 +120,10 @@ def _create_qApp():
except AttributeError: # Only for Qt>=5.14.
pass
qApp = QtWidgets.QApplication(["matplotlib"])
if sys.platform == "darwin":

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Is there a harm in setting this regardless of platform? I just tested on a Linux box and it didn't seem to have an impact.

Ditto to the block below, where even if we are on mac, I don't think it hurts anything to call setWindowIcon on the windows.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

I don't have a problem removing this one.

With the other one, theoretically window icons on macOS are supposed to only be set along with a file path when the window represents a file. However, if you don't set the file path, the icon won't show. So while it's an unnecessary call that's semantically incorrect, it's effectively a noop.

So I guess it's really up to your priorities: semantics? Performance? Less code? Up to you!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Here's the documentation from Qt re: QWidget::setWindowIcon():

https://doc.qt.io/qt-5/qwidget.html#windowIcon-prop

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does it make sense to keep Darwin for now, and if someone wants this on another system they can add it?

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:
Expand Down Expand Up @@ -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

Expand Down

Back | FazBrowse Home | New Git URL