diff --git a/novelwriter/assets/icons/none.svg b/novelwriter/assets/icons/none.svg new file mode 100644 index 00000000..15cac73d --- /dev/null +++ b/novelwriter/assets/icons/none.svg @@ -0,0 +1,4 @@ + + + + diff --git a/novelwriter/gui/theme.py b/novelwriter/gui/theme.py index f40642c4..3ceb2a6f 100644 --- a/novelwriter/gui/theme.py +++ b/novelwriter/gui/theme.py @@ -544,6 +544,9 @@ class GuiIcons: self._confName = "icons.conf" self._iconPath = CONFIG.assetPath("icons") + # None Icon + self._noIcon = QIcon(str(self._iconPath / "none.svg")) + # Icon Theme Meta self.themeName = "" self.themeDescription = "" @@ -680,7 +683,7 @@ class GuiIcons: icon.addPixmap(pOne, QIcon.Mode.Normal, QIcon.State.On) icon.addPixmap(pTwo, QIcon.Mode.Normal, QIcon.State.Off) return icon - return QIcon() + return self._noIcon def getPixmap(self, name: str, size: tuple[int, int]) -> QPixmap: """Return an icon from the icon buffer as a QPixmap. If it @@ -712,7 +715,7 @@ class GuiIcons: elif tLayout == nwItemLayout.NOTE: iconName = "proj_note" if iconName is None: - return QIcon() + return self._noIcon return self.getIcon(iconName) @@ -753,7 +756,7 @@ class GuiIcons: """ if name not in self.ICON_KEYS: logger.error("Requested unknown icon name '%s'", name) - return QIcon() + return self._noIcon # If we just want the app icons, return right away if name == "novelwriter": @@ -769,7 +772,7 @@ class GuiIcons: # If we didn't find one, give up and return an empty icon logger.warning("Did not load an icon for '%s'", name) - return QIcon() + return self._noIcon # END Class GuiIcons diff --git a/tests/test_gui/test_gui_theme.py b/tests/test_gui/test_gui_theme.py index f4050c0d..84ade0f8 100644 --- a/tests/test_gui/test_gui_theme.py +++ b/tests/test_gui/test_gui_theme.py @@ -332,7 +332,7 @@ def testGuiTheme_LoadIcons(qtbot): # Load an unknown icon qIcon = iconCache.getIcon("stuff") assert isinstance(qIcon, QIcon) - assert qIcon.isNull() is True + assert qIcon == iconCache._noIcon # Load an icon, it is likely already cached qIcon = iconCache.getIcon("add") @@ -349,17 +349,17 @@ def testGuiTheme_LoadIcons(qtbot): # Load app icon qIcon = iconCache.getIcon("novelwriter") assert isinstance(qIcon, QIcon) - assert qIcon.isNull() is False + assert qIcon != iconCache._noIcon # Load mime icon qIcon = iconCache.getIcon("proj_nwx") assert isinstance(qIcon, QIcon) - assert qIcon.isNull() is False + assert qIcon != iconCache._noIcon # Toggle icon qIcon = iconCache.getToggleIcon("bullet", (24, 24)) assert isinstance(qIcon, QIcon) - assert qIcon.isNull() is False + assert qIcon != iconCache._noIcon pOn = qIcon.pixmap(24, 24, QIcon.Mode.Normal, QIcon.State.On) pOff = qIcon.pixmap(24, 24, QIcon.Mode.Normal, QIcon.State.Off) assert pOn != pOff @@ -367,7 +367,7 @@ def testGuiTheme_LoadIcons(qtbot): # Unknown toggle icon qIcon = iconCache.getToggleIcon("stuff", (24, 24)) assert isinstance(qIcon, QIcon) - assert qIcon.isNull() is True + assert qIcon == iconCache._noIcon # Load Item Icons # =============== @@ -420,7 +420,7 @@ def testGuiTheme_LoadIcons(qtbot): # No Type -> Null assert iconCache.getItemIcon( nwItemType.NO_TYPE, nwItemClass.NOVEL, nwItemLayout.DOCUMENT, hLevel="H0" - ).isNull() is True + ) == iconCache._noIcon # qtbot.stop()