From 84f634ebc6aa564c14cb7dd2eee999283a2a5385 Mon Sep 17 00:00:00 2001 From: Niklas Henning Date: Sun, 25 Aug 2024 00:11:50 +0200 Subject: [PATCH 1/5] Add option to not recolor icons (#17) --- src/pyqttoast/icon_utils.py | 8 ++++++-- src/pyqttoast/toast.py | 26 ++++++++++++-------------- 2 files changed, 18 insertions(+), 16 deletions(-) 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: From 704b85a8cb3d3dafe0f3000357d98863bfe2dfdf Mon Sep 17 00:00:00 2001 From: Niklas Henning Date: Sun, 25 Aug 2024 00:18:18 +0200 Subject: [PATCH 2/5] Update documentation (#17) --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 52c26b6..5136414 100644 --- a/README.md +++ b/README.md @@ -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` From 1a364b7d771dec775f0e480954064ae6716c33d9 Mon Sep 17 00:00:00 2001 From: Niklas Henning Date: Sun, 25 Aug 2024 00:23:34 +0200 Subject: [PATCH 3/5] Rename file --- tests/{icon_handler_test.py => icon_utils_test.py} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename tests/{icon_handler_test.py => icon_utils_test.py} (100%) 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 From 6441f0573ed2f5d0ade774a45ae8281b5ef275d5 Mon Sep 17 00:00:00 2001 From: Niklas Henning Date: Sun, 25 Aug 2024 00:24:44 +0200 Subject: [PATCH 4/5] Update version --- README.md | 2 +- setup.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 5136414..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) 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', From 54a7b15315cc5addede2dd909f59e5e9b961cb5c Mon Sep 17 00:00:00 2001 From: Niklas Henning Date: Tue, 27 Aug 2024 15:51:06 +0200 Subject: [PATCH 5/5] Update tests (#17) --- tests/toast_test.py | 5 +++++ 1 file changed, 5 insertions(+) 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"""