Skip to content

Commit

Permalink
Merge pull request #18 from niklashenning/develop
Browse files Browse the repository at this point in the history
v1.3.2
  • Loading branch information
niklashenning authored Aug 27, 2024
2 parents 7c14a50 + 54a7b15 commit c127912
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 18 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down Expand Up @@ -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:** <br> `SUCCESS`, `WARNING`, `ERROR`, `INFORMATION`, `CLOSE`
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

setup(
name='pyqt-toast-notification',
version='1.3.1',
version='1.3.2',
author='Niklas Henning',
author_email='[email protected]',
license='MIT',
Expand Down
8 changes: 6 additions & 2 deletions src/pyqttoast/icon_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()):
Expand Down
26 changes: 12 additions & 14 deletions src/pyqttoast/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions tests/toast_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down

0 comments on commit c127912

Please sign in to comment.