diff --git a/README.md b/README.md index 52c26b6..a3c8940 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # PyQt Toast -[![PyPI](https://img.shields.io/badge/pypi-v1.3.1-blue)](https://pypi.org/project/pyqt-toast-notification/) +[![PyPI](https://img.shields.io/badge/pypi-v1.3.2-blue)](https://pypi.org/project/pyqt-toast-notification/) [![Python](https://img.shields.io/badge/python-3.7+-blue)](https://github.com/niklashenning/pyqttoast) [![Build](https://img.shields.io/badge/build-passing-neon)](https://github.com/niklashenning/pyqttoast) [![Coverage](https://img.shields.io/badge/coverage-95%25-green)](https://github.com/niklashenning/pyqttoast) @@ -107,6 +107,9 @@ toast.setShowIcon(True) # Default: False # Or setting a custom icon: toast.setIcon(QPixmap('path/to/your/icon.png')) + +# If you want to show the icon without recoloring it, set the icon color to None: +toast.setIconColor(None) # Default: #5C5C5C ``` > **AVAILABLE ICONS:**
`SUCCESS`, `WARNING`, `ERROR`, `INFORMATION`, `CLOSE` diff --git a/setup.py b/setup.py index 5248150..ddddf43 100644 --- a/setup.py +++ b/setup.py @@ -6,7 +6,7 @@ setup( name='pyqt-toast-notification', - version='1.3.1', + version='1.3.2', author='Niklas Henning', author_email='business@niklashenning.com', license='MIT', diff --git a/src/pyqttoast/icon_utils.py b/src/pyqttoast/icon_utils.py index a4d9c20..1359d02 100644 --- a/src/pyqttoast/icon_utils.py +++ b/src/pyqttoast/icon_utils.py @@ -25,14 +25,18 @@ def get_icon_from_enum(enum_icon: ToastIcon): return QPixmap(OSUtils.get_current_directory() + '/icons/close.png') @staticmethod - def recolor_image(image: QImage, color: QColor): + def recolor_image(image: QImage, color: QColor | None): """Take an image and return a copy with the colors changed :param image: image to recolor - :param color: new color + :param color: new color (None if the image should not be recolored) :return: recolored image """ + # Leave image as is if color is None + if color is None: + return image + # Loop through every pixel for x in range(0, image.width()): for y in range(0, image.height()): diff --git a/src/pyqttoast/toast.py b/src/pyqttoast/toast.py index 170a92e..e15fdcc 100644 --- a/src/pyqttoast/toast.py +++ b/src/pyqttoast/toast.py @@ -1303,27 +1303,26 @@ def setTextColor(self, color: QColor): return self.__text_color = color - def getIconColor(self) -> QColor: + def getIconColor(self) -> QColor | None: """Get the color of the icon - :return: icon color + :return: icon color (None if no color is set) """ return self.__icon_color - def setIconColor(self, color: QColor): + def setIconColor(self, color: QColor | None): """Set the color of the icon - :param color: new icon color + :param color: new icon color (None if the icon should not be recolored) """ if self.__used: return self.__icon_color = color - recolored_image = IconUtils.recolor_image(self.__icon_widget.icon().pixmap( - self.__icon_widget.iconSize()).toImage(), - color) + recolored_image = IconUtils.recolor_image(QIcon(self.__icon).pixmap( + self.__icon_widget.iconSize()).toImage(), color) self.__icon_widget.setIcon(QIcon(QPixmap(recolored_image))) def getIconSeparatorColor(self) -> QColor: @@ -1344,27 +1343,26 @@ def setIconSeparatorColor(self, color: QColor): return self.__icon_separator_color = color - def getCloseButtonIconColor(self) -> QColor: + def getCloseButtonIconColor(self) -> QColor | None: """Get the color of the close button icon - :return: color + :return: icon color (None if no color is set) """ return self.__close_button_icon_color - def setCloseButtonIconColor(self, color: QColor): + def setCloseButtonIconColor(self, color: QColor | None): """Set the color of the close button icon - :param color: new color + :param color: new color (None if the icon should not be recolored) """ if self.__used: return self.__close_button_icon_color = color - recolored_image = IconUtils.recolor_image(self.__close_button.icon().pixmap( - self.__close_button.iconSize()).toImage(), - color) + recolored_image = IconUtils.recolor_image(QIcon(self.__close_button_icon).pixmap( + self.__close_button.iconSize()).toImage(), color) self.__close_button.setIcon(QIcon(QPixmap(recolored_image))) def getDurationBarColor(self) -> QColor: diff --git a/tests/icon_handler_test.py b/tests/icon_utils_test.py similarity index 100% rename from tests/icon_handler_test.py rename to tests/icon_utils_test.py diff --git a/tests/toast_test.py b/tests/toast_test.py index 743dad1..826026a 100644 --- a/tests/toast_test.py +++ b/tests/toast_test.py @@ -848,6 +848,11 @@ def test_set_colors(qtbot): assert toast.getCloseButtonIconColor() == QColor('#1fad96') assert toast.getDurationBarColor() == QColor('#cc640e') + toast.setIconColor(None) + toast.setCloseButtonIconColor(None) + assert toast.getIconColor() is None + assert toast.getCloseButtonIconColor() is None + def test_set_fonts(qtbot): """Test setting the fonts of a toast"""