From 7eec241c82bf11643b532a25cc6436f7c8870e0f Mon Sep 17 00:00:00 2001 From: RumovZ Date: Sun, 17 Oct 2021 17:56:40 +0200 Subject: [PATCH] Add utility func for setting window icon --- qt/aqt/browser/card_info.py | 5 ++--- qt/aqt/browser/previewer.py | 8 ++------ qt/aqt/utils.py | 6 ++++++ 3 files changed, 10 insertions(+), 9 deletions(-) diff --git a/qt/aqt/browser/card_info.py b/qt/aqt/browser/card_info.py index 26f99426c..9b67e2c36 100644 --- a/qt/aqt/browser/card_info.py +++ b/qt/aqt/browser/card_info.py @@ -14,6 +14,7 @@ from aqt.utils import ( qconnect, restoreGeom, saveGeom, + setWindowIcon, tr, ) from aqt.webview import AnkiWebView @@ -47,9 +48,7 @@ class CardInfoDialog(QDialog): disable_help_button(self) restoreGeom(self, self.GEOMETRY_KEY) addCloseShortcut(self) - icon = QIcon() - icon.addPixmap(QPixmap("icons:anki.png"), QIcon.Mode.Normal, QIcon.State.Off) - self.setWindowIcon(icon) + setWindowIcon(self) self.web = AnkiWebView(title=self.TITLE) self.web.setVisible(False) diff --git a/qt/aqt/browser/previewer.py b/qt/aqt/browser/previewer.py index 190d65ecb..01b6c253f 100644 --- a/qt/aqt/browser/previewer.py +++ b/qt/aqt/browser/previewer.py @@ -17,9 +17,7 @@ from aqt.qt import ( QCheckBox, QDialog, QDialogButtonBox, - QIcon, QKeySequence, - QPixmap, QShortcut, Qt, QTimer, @@ -30,7 +28,7 @@ from aqt.qt import ( from aqt.reviewer import replay_audio from aqt.sound import av_player, play_clicked_audio from aqt.theme import theme_manager -from aqt.utils import disable_help_button, restoreGeom, saveGeom, tr +from aqt.utils import disable_help_button, restoreGeom, saveGeom, setWindowIcon, tr from aqt.webview import AnkiWebView LastStateAndMod = tuple[str, int, int] @@ -52,10 +50,8 @@ class Previewer(QDialog): self._parent = parent self._close_callback = on_close self.mw = mw - icon = QIcon() - icon.addPixmap(QPixmap("icons:anki.png"), QIcon.Mode.Normal, QIcon.State.Off) disable_help_button(self) - self.setWindowIcon(icon) + setWindowIcon(self) def card(self) -> Card | None: raise NotImplementedError diff --git a/qt/aqt/utils.py b/qt/aqt/utils.py index ab3163e9e..28f1242dc 100644 --- a/qt/aqt/utils.py +++ b/qt/aqt/utils.py @@ -406,6 +406,12 @@ def disable_help_button(widget: QWidget) -> None: ) +def setWindowIcon(widget: QWidget) -> None: + icon = QIcon() + icon.addPixmap(QPixmap("icons:anki.png"), QIcon.Mode.Normal, QIcon.State.Off) + widget.setWindowIcon(icon) + + # File handling ######################################################################