| 1 |
''' |
| 2 |
Notification |
| 3 |
============ |
| 4 |
|
| 5 |
The :class:`Notification` provides access to public methods to create |
| 6 |
notifications. |
| 7 |
|
| 8 |
Simple Examples |
| 9 |
--------------- |
| 10 |
|
| 11 |
To send notification:: |
| 12 |
|
| 13 |
>>> from plyer import notification |
| 14 |
>>> title = 'plyer' |
| 15 |
>>> message = 'This is an example.' |
| 16 |
>>> notification.notify(title=title, message=message) |
| 17 |
|
| 18 |
Android toast notification:: |
| 19 |
|
| 20 |
>>> from plyer import notification |
| 21 |
>>> notification.notify(message='hello', toast=True) |
| 22 |
|
| 23 |
Android simple notification:: |
| 24 |
|
| 25 |
>>> from plyer import notification |
| 26 |
>>> notification.notify(message='hello', toast=True) |
| 27 |
|
| 28 |
Notification with custom icon:: |
| 29 |
|
| 30 |
>>> from plyer import notification |
| 31 |
>>> notification.notify(title='title', message='hello', app_icon=<path>) |
| 32 |
|
| 33 |
.. versionadded:: 1.0.0 |
| 34 |
|
| 35 |
.. versionadded:: 1.4.0 |
| 36 |
Add implementation of primitive Android popup-like notification (toast) |
| 37 |
|
| 38 |
.. versionchanged:: 1.4.0 |
| 39 |
Android implementation now supports custom icons for notifications. |
| 40 |
''' |
| 41 |
|
| 42 |
|
| 43 |
class Notification: |
| 44 |
''' |
| 45 |
Notification facade. |
| 46 |
''' |
| 47 |
|
| 48 |
def notify(self, title='', message='', app_name='', app_icon='', |
| 49 |
timeout=10, ticker='', toast=False, hints={}): |
| 50 |
''' |
| 51 |
Send a notification. |
| 52 |
|
| 53 |
:param title: Title of the notification |
| 54 |
:param message: Message of the notification |
| 55 |
:param app_name: Name of the app launching this notification |
| 56 |
:param app_icon: Icon to be displayed along with the message |
| 57 |
:param timeout: time to display the message for, defaults to 10 |
| 58 |
:param ticker: text to display on status bar as the notification |
| 59 |
arrives |
| 60 |
:param toast: simple Android message instead of full notification |
| 61 |
:param hints: Optional hints that can be used to pass along extra |
| 62 |
instructions on Linux. |
| 63 |
(See https://specifications.freedesktop.org/notification-spec/latest/ar01s08.html) # noqa: E501 |
| 64 |
|
| 65 |
:type title: str |
| 66 |
:type message: str |
| 67 |
:type app_name: str |
| 68 |
:type app_icon: str |
| 69 |
:type timeout: int |
| 70 |
:type ticker: str |
| 71 |
:type toast: bool |
| 72 |
:type hints: dict |
| 73 |
|
| 74 |
.. note:: |
| 75 |
When called on Windows, ``app_icon`` has to be a path to |
| 76 |
a file in .ICO format. |
| 77 |
|
| 78 |
.. versionadded:: 1.0.0 |
| 79 |
|
| 80 |
.. versionchanged:: 1.4.0 |
| 81 |
Add 'toast' keyword argument |
| 82 |
''' |
| 83 |
|
| 84 |
self._notify( |
| 85 |
title=title, message=message, |
| 86 |
app_icon=app_icon, app_name=app_name, |
| 87 |
timeout=timeout, ticker=ticker, toast=toast, hints=hints |
| 88 |
) |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
def _notify(self, **kwargs): |
| 93 |
raise NotImplementedError("No usable implementation found!") |