niklashenning / pyqttoast

A fully customizable toast notification library for PyQt and PySide
https://pypi.org/project/pyqt-toast-notification/
MIT License
84 stars 10 forks source link

Allow user to force multi-line text #20

Open KenyonPrater opened 1 week ago

KenyonPrater commented 1 week ago

For instance, if I want to toast a pretty-printed dictionary:

toast = Toast()
toast.setTitle("User data")
my_data = {'id': 42, 'username': 'alice', 'role': 'user'}
toast.setText(json.dumps(my_data, indent=2))
toast.show()

Right now, only the first line of the text will be visible in the toast. It seems like the solution would be like this:

def __setup_ui(self):
    [...]
    if self.__title == '' or self.__text == '':
        text_section_spacing = 0

    # NEW CODE
    if self.__multiline:
        self.__text_label.setWordWrap(True)
        text_height = self.__text_label.sizeHint().height()
        text_width = self.__text_label.sizeHint().width()
    # END OF NEW CODE

    text_section_height = (self.__text_section_margins.top()
                           + title_height + text_section_spacing
                           + text_height + self.__text_section_margins.bottom())
    [...]

This gives:

image

Alright if I create a PR to this effect?

niklashenning commented 1 week ago

This looks like a very nice addition, definitely feel free to create a PR for it 👍🏻 We'll have to make sure everything is backwards compatible but I think that shouldn't be a problem with this feature