|
| 1 | +from PyQt6.QtWidgets import QWidget |
| 2 | +from pyqttoast import Toast, ToastPreset |
| 3 | + |
| 4 | + |
| 5 | +def show_toast( |
| 6 | + parent: QWidget, title: str, text: str, timeout_ms: int, preset: ToastPreset |
| 7 | +) -> None: |
| 8 | + """Display a toast message with the given properties |
| 9 | + :param parent: parent widget to inject toast message component |
| 10 | + :param title: title of toast message |
| 11 | + :param text: text of toast message |
| 12 | + :param timeout_ms: duration of the message (in ms) |
| 13 | + :param preset: preset of the message box |
| 14 | + """ |
| 15 | + toast = Toast(parent) |
| 16 | + toast.setDuration(timeout_ms) |
| 17 | + toast.setTitle(title) |
| 18 | + toast.setText(text) |
| 19 | + toast.applyPreset(preset) |
| 20 | + toast.setShowCloseButton(False) |
| 21 | + toast.setBorderRadius(10) |
| 22 | + toast.setShowDurationBar(False) |
| 23 | + toast.show() |
| 24 | + |
| 25 | + |
| 26 | +def success_toast(parent: QWidget, text: str, timeout_ms: int = 1000) -> None: |
| 27 | + """Display a success toast message |
| 28 | + :param parent: parent widget to inject toast message component |
| 29 | + :param text: text of toast message |
| 30 | + :param timeout_ms: duration of the message (in ms) |
| 31 | + """ |
| 32 | + show_toast(parent, "", text, timeout_ms, ToastPreset.SUCCESS_DARK) |
| 33 | + |
| 34 | + |
| 35 | +def failure_toast(parent: QWidget, text: str, timeout_ms: int = 1000) -> None: |
| 36 | + """Display a failure toast message |
| 37 | + :param parent: parent widget to inject toast message component |
| 38 | + :param text: text of toast message |
| 39 | + :param timeout_ms: duration of the message (in ms) |
| 40 | + """ |
| 41 | + show_toast(parent, "", text, timeout_ms, ToastPreset.ERROR_DARK) |
| 42 | + |
| 43 | + |
| 44 | +def info_toast(parent: QWidget, text: str, timeout_ms: int = 1000) -> None: |
| 45 | + """Display an information toast message |
| 46 | + :param parent: parent widget to inject toast message component |
| 47 | + :param text: text of toast message |
| 48 | + :param timeout_ms: duration of the message (in ms) |
| 49 | + """ |
| 50 | + show_toast(parent, "", text, timeout_ms, ToastPreset.INFORMATION_DARK) |
| 51 | + |
| 52 | + |
| 53 | +def warning_toast(parent: QWidget, text: str, timeout_ms: int = 1000) -> None: |
| 54 | + """Display a warning toast message |
| 55 | + :param parent: parent widget to inject toast message component |
| 56 | + :param text: text of toast message |
| 57 | + :param timeout_ms: duration of the message (in ms) |
| 58 | + """ |
| 59 | + show_toast(parent, "", text, timeout_ms, ToastPreset.WARNING_DARK) |
0 commit comments