desktop-notifier 5.0.0.dev1__tar.gz → 5.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {desktop_notifier-5.0.0.dev1/src/desktop_notifier.egg-info → desktop_notifier-5.0.1}/PKG-INFO +79 -81
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/README.md +67 -78
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/pyproject.toml +18 -3
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/__init__.py +3 -2
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/base.py +0 -1
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/dbus.py +0 -1
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/dummy.py +0 -1
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/macos.py +2 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/macos_support.py +1 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/main.py +22 -91
- desktop_notifier-5.0.1/src/desktop_notifier/sync.py +136 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/winrt.py +0 -1
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1/src/desktop_notifier.egg-info}/PKG-INFO +79 -81
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier.egg-info/SOURCES.txt +3 -1
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/tests/test_api.py +0 -26
- desktop_notifier-5.0.1/tests/test_sync_api.py +66 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/LICENSE +0 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/setup.cfg +0 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/py.typed +0 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/resources/__init__.py +0 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/resources/python.png +0 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier.egg-info/dependency_links.txt +0 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier.egg-info/requires.txt +0 -0
- {desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier.egg-info/top_level.txt +0 -0
{desktop_notifier-5.0.0.dev1/src/desktop_notifier.egg-info → desktop_notifier-5.0.1}/PKG-INFO
RENAMED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: desktop-notifier
|
|
3
|
-
Version: 5.0.
|
|
3
|
+
Version: 5.0.1
|
|
4
4
|
Summary: Python library for cross-platform desktop notifications
|
|
5
5
|
Author-email: Sam Schott <sam.schott@outlook.com>
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/samschott/desktop-notifier
|
|
8
|
-
Keywords: desktop-notifier
|
|
9
|
-
Classifier: Development Status ::
|
|
8
|
+
Keywords: desktop-notifier,notifications,Notification Center,push notifications,Toast notifications
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
10
|
Classifier: Intended Audience :: Developers
|
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
13
16
|
Classifier: Programming Language :: Python :: 3
|
|
14
17
|
Classifier: Programming Language :: Python :: 3.7
|
|
15
18
|
Classifier: Programming Language :: Python :: 3.8
|
|
16
19
|
Classifier: Programming Language :: Python :: 3.9
|
|
17
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
23
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
24
|
+
Classifier: Topic :: Communications
|
|
25
|
+
Classifier: Topic :: Desktop Environment
|
|
26
|
+
Classifier: Topic :: Desktop Environment :: Gnome
|
|
27
|
+
Classifier: Topic :: Desktop Environment :: K Desktop Environment (KDE)
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
29
|
Requires-Python: >=3.7
|
|
21
30
|
Description-Content-Type: text/markdown
|
|
22
31
|
License-File: LICENSE
|
|
@@ -44,30 +53,22 @@ Requires-Dist: sphinx==7.3.7; extra == "docs"
|
|
|
44
53
|
Requires-Dist: sphinx-autoapi==3.1.2; extra == "docs"
|
|
45
54
|
Requires-Dist: sphinx-mdinclude==0.6.1; extra == "docs"
|
|
46
55
|
|
|
56
|
+
|
|
57
|
+
# Desktop Notifier
|
|
58
|
+
|
|
47
59
|
[](https://pypi.org/project/desktop-notifier/)
|
|
48
60
|
[](https://pypi.org/pypi/desktop-notifier/)
|
|
49
61
|
[](https://desktop-notifier.readthedocs.io/en/latest/?badge=latest)
|
|
50
62
|
|
|
51
|
-
# Desktop Notifier
|
|
52
|
-
|
|
53
63
|
`desktop-notifier` is a Python library for cross-platform desktop notifications.
|
|
54
64
|
Currently supported platforms are:
|
|
55
65
|
|
|
56
66
|
* Linux via the dbus service org.freedesktop.Notifications
|
|
57
67
|
* macOS and iOS via the Notification Center framework
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-

|
|
68
|
+
* Windows via the WinRT / Python bridge
|
|
61
69
|
|
|
62
70
|
## Features
|
|
63
71
|
|
|
64
|
-
`desktop-notifier` aims to be a good citizen of the platforms which it supports. It
|
|
65
|
-
therefore stays within the limits of the native platform APIs and does not try to work
|
|
66
|
-
around limitations which are often deliberate UI choices. For example, on macOS and
|
|
67
|
-
iOS, it is not possible to change the app icon which is shown on notifications. There
|
|
68
|
-
are possible workarounds - that would likely be rejected by an App Store review - and
|
|
69
|
-
desktop-notifier deliberately stays away from those.
|
|
70
|
-
|
|
71
72
|
Where supported by the native platform APIs, `desktop-notifier` allows for:
|
|
72
73
|
|
|
73
74
|
* Clickable notifications with callbacks on user interaction
|
|
@@ -77,16 +78,17 @@ Where supported by the native platform APIs, `desktop-notifier` allows for:
|
|
|
77
78
|
* Notification threads (grouping notifications by topic)
|
|
78
79
|
* Limiting the maximum number of notifications shown in the notification center
|
|
79
80
|
|
|
81
|
+
An example of how some of this looks like on macOS:
|
|
82
|
+
|
|
83
|
+

|
|
84
|
+
|
|
80
85
|
An exhaustive list of features and their platform support is provided in the
|
|
81
86
|
[documentation](https://desktop-notifier.readthedocs.io/en/latest/background/platform_support.html).
|
|
87
|
+
In addition, you can query supported features at runtime with
|
|
88
|
+
`DesktopNotifier.get_capabilities()`.
|
|
82
89
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* Async API: The main API consists of async methods and a running event loop
|
|
86
|
-
is required to respond to user interactions with a notification.
|
|
87
|
-
* Prefer pure Python dependencies over extension modules. We make an exception for
|
|
88
|
-
Windows because interoperability with the Windows Runtime is difficult to achieve
|
|
89
|
-
otherwise.
|
|
90
|
+
Any options or configurations which are not supported by the platform will be silently
|
|
91
|
+
ignored.
|
|
90
92
|
|
|
91
93
|
## Installation
|
|
92
94
|
|
|
@@ -108,71 +110,58 @@ from desktop_notifier import DesktopNotifier
|
|
|
108
110
|
notifier = DesktopNotifier()
|
|
109
111
|
|
|
110
112
|
async def main():
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
await asyncio.sleep(5) # wait a bit before clearing notification
|
|
114
|
-
|
|
115
|
-
await notifier.clear(n) # removes the notification
|
|
116
|
-
await notifier.clear_all() # removes all notifications for this app
|
|
113
|
+
await notifier.send(title="Hello world!", message="Sent from Python")
|
|
117
114
|
|
|
118
115
|
asyncio.run(main())
|
|
119
116
|
```
|
|
120
117
|
|
|
121
|
-
For convenience, there is also a synchronous method ``send_sync()`` to send
|
|
122
|
-
notifications without manually starting an asyncio event loop:
|
|
123
|
-
|
|
124
|
-
```Python
|
|
125
|
-
notifier.send_sync(title="Hello world!", message="Sent from Python")
|
|
126
|
-
```
|
|
127
|
-
|
|
128
118
|
By default, "Python" will be used as the app name for all notifications, but you can
|
|
129
119
|
manually specify an app name and icon in the ``DesktopNotifier`` constructor. Advanced
|
|
130
120
|
usage also allows setting different notification options such as urgency, buttons,
|
|
131
|
-
callbacks, etc.
|
|
132
|
-
the top of the page:
|
|
121
|
+
callbacks, etc. For example, for the gif displayed above:
|
|
133
122
|
|
|
134
123
|
```Python
|
|
135
124
|
import asyncio
|
|
136
|
-
|
|
125
|
+
import signal
|
|
137
126
|
|
|
138
|
-
|
|
127
|
+
from desktop_notifier import DesktopNotifier, Urgency, Button, ReplyField, DEFAULT_SOUND
|
|
139
128
|
|
|
140
|
-
async def main():
|
|
141
|
-
await notifier.send(
|
|
142
|
-
title="Julius Caesar",
|
|
143
|
-
message="Et tu, Brute?",
|
|
144
|
-
urgency=Urgency.Critical,
|
|
145
|
-
buttons=[
|
|
146
|
-
Button(
|
|
147
|
-
title="Mark as read",
|
|
148
|
-
on_pressed=lambda: print("Marked as read")),
|
|
149
|
-
],
|
|
150
|
-
reply_field=ReplyField(
|
|
151
|
-
title="Reply",
|
|
152
|
-
button_title="Send",
|
|
153
|
-
on_replied=lambda text: print("Brutus replied:", text),
|
|
154
|
-
),
|
|
155
|
-
on_clicked=lambda: print("Notification clicked"),
|
|
156
|
-
on_dismissed=lambda: print("Notification dismissed"),
|
|
157
|
-
sound_file=DEFAULT_SOUND,
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
loop = asyncio.get_event_loop()
|
|
162
|
-
loop.create_task(main())
|
|
163
|
-
loop.run_forever()
|
|
164
|
-
```
|
|
165
129
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
130
|
+
async def main() -> None:
|
|
131
|
+
notifier = DesktopNotifier(
|
|
132
|
+
app_name="Sample App",
|
|
133
|
+
notification_limit=10,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
await notifier.send(
|
|
137
|
+
title="Julius Caesar",
|
|
138
|
+
message="Et tu, Brute?",
|
|
139
|
+
urgency=Urgency.Critical,
|
|
140
|
+
buttons=[
|
|
141
|
+
Button(
|
|
142
|
+
title="Mark as read",
|
|
143
|
+
on_pressed=lambda: print("Marked as read"),
|
|
144
|
+
)
|
|
145
|
+
],
|
|
146
|
+
reply_field=ReplyField(
|
|
147
|
+
on_replied=lambda text: print("Brutus replied:", text),
|
|
148
|
+
),
|
|
149
|
+
on_clicked=lambda: print("Notification clicked"),
|
|
150
|
+
on_dismissed=lambda: print("Notification dismissed"),
|
|
151
|
+
sound=DEFAULT_SOUND,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
# Run the event loop forever to respond to user interactions with the notification.
|
|
155
|
+
stop_event = asyncio.Event()
|
|
156
|
+
loop = asyncio.get_running_loop()
|
|
157
|
+
|
|
158
|
+
loop.add_signal_handler(signal.SIGINT, stop_event.set)
|
|
159
|
+
loop.add_signal_handler(signal.SIGTERM, stop_event.set)
|
|
160
|
+
|
|
161
|
+
await stop_event.wait()
|
|
173
162
|
|
|
174
|
-
|
|
175
|
-
|
|
163
|
+
asyncio.run(main())
|
|
164
|
+
```
|
|
176
165
|
|
|
177
166
|
## Event loop integration
|
|
178
167
|
|
|
@@ -190,10 +179,6 @@ from rubicon.objc.eventloop import EventLoopPolicy
|
|
|
190
179
|
|
|
191
180
|
# Install the event loop policy
|
|
192
181
|
asyncio.set_event_loop_policy(EventLoopPolicy())
|
|
193
|
-
|
|
194
|
-
# Get an event loop, and run it!
|
|
195
|
-
loop = asyncio.get_event_loop()
|
|
196
|
-
loop.run_forever()
|
|
197
182
|
```
|
|
198
183
|
|
|
199
184
|
Desktop-notifier itself uses Rubicon Objective-C to interface with Cocoa APIs. A full
|
|
@@ -221,13 +206,26 @@ the resulting app bundle for notifications to work. An ad-hoc signature will be
|
|
|
221
206
|
sufficient but signing with an Apple developer certificate is recommended for
|
|
222
207
|
distribution and may be required on future releases of macOS.
|
|
223
208
|
|
|
224
|
-
##
|
|
209
|
+
## Design choices
|
|
210
|
+
|
|
211
|
+
This package is opinionated in a few ways:
|
|
225
212
|
|
|
226
|
-
*
|
|
227
|
-
|
|
213
|
+
* It does not try to work around platform restrictions, such as changing the app icon on
|
|
214
|
+
macOS. Workarounds would be hacky and likely be rejected by an App Store review.
|
|
215
|
+
* The main API consists of async methods and a running event loop is required to respond
|
|
216
|
+
to user interactions with a notification. This simplifies integration with GUI apps.
|
|
217
|
+
* Dependencies are pure Python packages without extension modules. This simplifies app
|
|
218
|
+
bundling and distribution. We make an exception for Windows because interoperability
|
|
219
|
+
with the Windows Runtime is difficult to achieve without extension modules.
|
|
220
|
+
* If a certain feature is not supported by a platform, using it will not raise an
|
|
221
|
+
exception. This allows clients to use a wide feature set where available without
|
|
222
|
+
worrying about exception handling.
|
|
223
|
+
* If a notification cannot be scheduled, this is logged as a warning and does not raise
|
|
224
|
+
an exception. Most platforms allow the user to control if and how notifications are
|
|
225
|
+
delivered and notification delivery therefore cannot be taken as guaranteed.
|
|
228
226
|
|
|
229
227
|
## Dependencies
|
|
230
228
|
|
|
231
229
|
* [dbus-next](https://github.com/altdesktop/python-dbus-next) on Linux
|
|
232
230
|
* [rubicon-objc](https://github.com/beeware/rubicon-objc) on macOS
|
|
233
|
-
* [
|
|
231
|
+
* [pywinrt](https://github.com/pywinrt/pywinrt) on Windows
|
|
@@ -1,27 +1,19 @@
|
|
|
1
|
+
|
|
2
|
+
# Desktop Notifier
|
|
3
|
+
|
|
1
4
|
[](https://pypi.org/project/desktop-notifier/)
|
|
2
5
|
[](https://pypi.org/pypi/desktop-notifier/)
|
|
3
6
|
[](https://desktop-notifier.readthedocs.io/en/latest/?badge=latest)
|
|
4
7
|
|
|
5
|
-
# Desktop Notifier
|
|
6
|
-
|
|
7
8
|
`desktop-notifier` is a Python library for cross-platform desktop notifications.
|
|
8
9
|
Currently supported platforms are:
|
|
9
10
|
|
|
10
11
|
* Linux via the dbus service org.freedesktop.Notifications
|
|
11
12
|
* macOS and iOS via the Notification Center framework
|
|
12
|
-
*
|
|
13
|
-
|
|
14
|
-

|
|
13
|
+
* Windows via the WinRT / Python bridge
|
|
15
14
|
|
|
16
15
|
## Features
|
|
17
16
|
|
|
18
|
-
`desktop-notifier` aims to be a good citizen of the platforms which it supports. It
|
|
19
|
-
therefore stays within the limits of the native platform APIs and does not try to work
|
|
20
|
-
around limitations which are often deliberate UI choices. For example, on macOS and
|
|
21
|
-
iOS, it is not possible to change the app icon which is shown on notifications. There
|
|
22
|
-
are possible workarounds - that would likely be rejected by an App Store review - and
|
|
23
|
-
desktop-notifier deliberately stays away from those.
|
|
24
|
-
|
|
25
17
|
Where supported by the native platform APIs, `desktop-notifier` allows for:
|
|
26
18
|
|
|
27
19
|
* Clickable notifications with callbacks on user interaction
|
|
@@ -31,16 +23,17 @@ Where supported by the native platform APIs, `desktop-notifier` allows for:
|
|
|
31
23
|
* Notification threads (grouping notifications by topic)
|
|
32
24
|
* Limiting the maximum number of notifications shown in the notification center
|
|
33
25
|
|
|
26
|
+
An example of how some of this looks like on macOS:
|
|
27
|
+
|
|
28
|
+

|
|
29
|
+
|
|
34
30
|
An exhaustive list of features and their platform support is provided in the
|
|
35
31
|
[documentation](https://desktop-notifier.readthedocs.io/en/latest/background/platform_support.html).
|
|
32
|
+
In addition, you can query supported features at runtime with
|
|
33
|
+
`DesktopNotifier.get_capabilities()`.
|
|
36
34
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
* Async API: The main API consists of async methods and a running event loop
|
|
40
|
-
is required to respond to user interactions with a notification.
|
|
41
|
-
* Prefer pure Python dependencies over extension modules. We make an exception for
|
|
42
|
-
Windows because interoperability with the Windows Runtime is difficult to achieve
|
|
43
|
-
otherwise.
|
|
35
|
+
Any options or configurations which are not supported by the platform will be silently
|
|
36
|
+
ignored.
|
|
44
37
|
|
|
45
38
|
## Installation
|
|
46
39
|
|
|
@@ -62,71 +55,58 @@ from desktop_notifier import DesktopNotifier
|
|
|
62
55
|
notifier = DesktopNotifier()
|
|
63
56
|
|
|
64
57
|
async def main():
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
await asyncio.sleep(5) # wait a bit before clearing notification
|
|
68
|
-
|
|
69
|
-
await notifier.clear(n) # removes the notification
|
|
70
|
-
await notifier.clear_all() # removes all notifications for this app
|
|
58
|
+
await notifier.send(title="Hello world!", message="Sent from Python")
|
|
71
59
|
|
|
72
60
|
asyncio.run(main())
|
|
73
61
|
```
|
|
74
62
|
|
|
75
|
-
For convenience, there is also a synchronous method ``send_sync()`` to send
|
|
76
|
-
notifications without manually starting an asyncio event loop:
|
|
77
|
-
|
|
78
|
-
```Python
|
|
79
|
-
notifier.send_sync(title="Hello world!", message="Sent from Python")
|
|
80
|
-
```
|
|
81
|
-
|
|
82
63
|
By default, "Python" will be used as the app name for all notifications, but you can
|
|
83
64
|
manually specify an app name and icon in the ``DesktopNotifier`` constructor. Advanced
|
|
84
65
|
usage also allows setting different notification options such as urgency, buttons,
|
|
85
|
-
callbacks, etc.
|
|
86
|
-
the top of the page:
|
|
66
|
+
callbacks, etc. For example, for the gif displayed above:
|
|
87
67
|
|
|
88
68
|
```Python
|
|
89
69
|
import asyncio
|
|
90
|
-
|
|
70
|
+
import signal
|
|
91
71
|
|
|
92
|
-
|
|
72
|
+
from desktop_notifier import DesktopNotifier, Urgency, Button, ReplyField, DEFAULT_SOUND
|
|
93
73
|
|
|
94
|
-
async def main():
|
|
95
|
-
await notifier.send(
|
|
96
|
-
title="Julius Caesar",
|
|
97
|
-
message="Et tu, Brute?",
|
|
98
|
-
urgency=Urgency.Critical,
|
|
99
|
-
buttons=[
|
|
100
|
-
Button(
|
|
101
|
-
title="Mark as read",
|
|
102
|
-
on_pressed=lambda: print("Marked as read")),
|
|
103
|
-
],
|
|
104
|
-
reply_field=ReplyField(
|
|
105
|
-
title="Reply",
|
|
106
|
-
button_title="Send",
|
|
107
|
-
on_replied=lambda text: print("Brutus replied:", text),
|
|
108
|
-
),
|
|
109
|
-
on_clicked=lambda: print("Notification clicked"),
|
|
110
|
-
on_dismissed=lambda: print("Notification dismissed"),
|
|
111
|
-
sound_file=DEFAULT_SOUND,
|
|
112
|
-
)
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
loop = asyncio.get_event_loop()
|
|
116
|
-
loop.create_task(main())
|
|
117
|
-
loop.run_forever()
|
|
118
|
-
```
|
|
119
74
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
75
|
+
async def main() -> None:
|
|
76
|
+
notifier = DesktopNotifier(
|
|
77
|
+
app_name="Sample App",
|
|
78
|
+
notification_limit=10,
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
await notifier.send(
|
|
82
|
+
title="Julius Caesar",
|
|
83
|
+
message="Et tu, Brute?",
|
|
84
|
+
urgency=Urgency.Critical,
|
|
85
|
+
buttons=[
|
|
86
|
+
Button(
|
|
87
|
+
title="Mark as read",
|
|
88
|
+
on_pressed=lambda: print("Marked as read"),
|
|
89
|
+
)
|
|
90
|
+
],
|
|
91
|
+
reply_field=ReplyField(
|
|
92
|
+
on_replied=lambda text: print("Brutus replied:", text),
|
|
93
|
+
),
|
|
94
|
+
on_clicked=lambda: print("Notification clicked"),
|
|
95
|
+
on_dismissed=lambda: print("Notification dismissed"),
|
|
96
|
+
sound=DEFAULT_SOUND,
|
|
97
|
+
)
|
|
98
|
+
|
|
99
|
+
# Run the event loop forever to respond to user interactions with the notification.
|
|
100
|
+
stop_event = asyncio.Event()
|
|
101
|
+
loop = asyncio.get_running_loop()
|
|
102
|
+
|
|
103
|
+
loop.add_signal_handler(signal.SIGINT, stop_event.set)
|
|
104
|
+
loop.add_signal_handler(signal.SIGTERM, stop_event.set)
|
|
105
|
+
|
|
106
|
+
await stop_event.wait()
|
|
127
107
|
|
|
128
|
-
|
|
129
|
-
|
|
108
|
+
asyncio.run(main())
|
|
109
|
+
```
|
|
130
110
|
|
|
131
111
|
## Event loop integration
|
|
132
112
|
|
|
@@ -144,10 +124,6 @@ from rubicon.objc.eventloop import EventLoopPolicy
|
|
|
144
124
|
|
|
145
125
|
# Install the event loop policy
|
|
146
126
|
asyncio.set_event_loop_policy(EventLoopPolicy())
|
|
147
|
-
|
|
148
|
-
# Get an event loop, and run it!
|
|
149
|
-
loop = asyncio.get_event_loop()
|
|
150
|
-
loop.run_forever()
|
|
151
127
|
```
|
|
152
128
|
|
|
153
129
|
Desktop-notifier itself uses Rubicon Objective-C to interface with Cocoa APIs. A full
|
|
@@ -175,13 +151,26 @@ the resulting app bundle for notifications to work. An ad-hoc signature will be
|
|
|
175
151
|
sufficient but signing with an Apple developer certificate is recommended for
|
|
176
152
|
distribution and may be required on future releases of macOS.
|
|
177
153
|
|
|
178
|
-
##
|
|
154
|
+
## Design choices
|
|
155
|
+
|
|
156
|
+
This package is opinionated in a few ways:
|
|
179
157
|
|
|
180
|
-
*
|
|
181
|
-
|
|
158
|
+
* It does not try to work around platform restrictions, such as changing the app icon on
|
|
159
|
+
macOS. Workarounds would be hacky and likely be rejected by an App Store review.
|
|
160
|
+
* The main API consists of async methods and a running event loop is required to respond
|
|
161
|
+
to user interactions with a notification. This simplifies integration with GUI apps.
|
|
162
|
+
* Dependencies are pure Python packages without extension modules. This simplifies app
|
|
163
|
+
bundling and distribution. We make an exception for Windows because interoperability
|
|
164
|
+
with the Windows Runtime is difficult to achieve without extension modules.
|
|
165
|
+
* If a certain feature is not supported by a platform, using it will not raise an
|
|
166
|
+
exception. This allows clients to use a wide feature set where available without
|
|
167
|
+
worrying about exception handling.
|
|
168
|
+
* If a notification cannot be scheduled, this is logged as a warning and does not raise
|
|
169
|
+
an exception. Most platforms allow the user to control if and how notifications are
|
|
170
|
+
delivered and notification delivery therefore cannot be taken as guaranteed.
|
|
182
171
|
|
|
183
172
|
## Dependencies
|
|
184
173
|
|
|
185
174
|
* [dbus-next](https://github.com/altdesktop/python-dbus-next) on Linux
|
|
186
175
|
* [rubicon-objc](https://github.com/beeware/rubicon-objc) on macOS
|
|
187
|
-
* [
|
|
176
|
+
* [pywinrt](https://github.com/pywinrt/pywinrt) on Windows
|
|
@@ -4,23 +4,38 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "desktop-notifier"
|
|
7
|
-
version = "5.0.
|
|
7
|
+
version = "5.0.1"
|
|
8
8
|
authors = [{name = "Sam Schott", email = "sam.schott@outlook.com"}]
|
|
9
9
|
license = {text = "MIT"}
|
|
10
10
|
description = "Python library for cross-platform desktop notifications"
|
|
11
|
-
keywords = [
|
|
11
|
+
keywords = [
|
|
12
|
+
"desktop-notifier",
|
|
13
|
+
"notifications",
|
|
14
|
+
"Notification Center",
|
|
15
|
+
"push notifications",
|
|
16
|
+
"Toast notifications",
|
|
17
|
+
]
|
|
12
18
|
classifiers = [
|
|
13
|
-
"Development Status ::
|
|
19
|
+
"Development Status :: 5 - Production/Stable",
|
|
14
20
|
"Intended Audience :: Developers",
|
|
15
21
|
"License :: OSI Approved :: MIT License",
|
|
16
22
|
"Natural Language :: English",
|
|
23
|
+
"Operating System :: MacOS :: MacOS X",
|
|
24
|
+
"Operating System :: Microsoft :: Windows",
|
|
25
|
+
"Operating System :: OS Independent",
|
|
17
26
|
"Programming Language :: Python :: 3",
|
|
18
27
|
"Programming Language :: Python :: 3.7",
|
|
19
28
|
"Programming Language :: Python :: 3.8",
|
|
20
29
|
"Programming Language :: Python :: 3.9",
|
|
21
30
|
"Programming Language :: Python :: 3.10",
|
|
22
31
|
"Programming Language :: Python :: 3.11",
|
|
32
|
+
"Programming Language :: Python :: 3.12",
|
|
23
33
|
"Programming Language :: Python :: 3 :: Only",
|
|
34
|
+
"Topic :: Communications",
|
|
35
|
+
"Topic :: Desktop Environment",
|
|
36
|
+
"Topic :: Desktop Environment :: Gnome",
|
|
37
|
+
"Topic :: Desktop Environment :: K Desktop Environment (KDE)",
|
|
38
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
24
39
|
]
|
|
25
40
|
requires-python = ">=3.7"
|
|
26
41
|
dependencies = [
|
|
@@ -15,9 +15,9 @@ from .main import (
|
|
|
15
15
|
DEFAULT_SOUND,
|
|
16
16
|
DEFAULT_ICON,
|
|
17
17
|
)
|
|
18
|
+
from .sync import DesktopNotifierSync
|
|
18
19
|
|
|
19
|
-
|
|
20
|
-
__version__ = "5.0.0.dev1"
|
|
20
|
+
__version__ = "5.0.1"
|
|
21
21
|
__author__ = "Sam Schott"
|
|
22
22
|
__url__ = "https://github.com/samschott/desktop-notifier"
|
|
23
23
|
|
|
@@ -33,6 +33,7 @@ __all__ = [
|
|
|
33
33
|
"Sound",
|
|
34
34
|
"Attachment",
|
|
35
35
|
"DesktopNotifier",
|
|
36
|
+
"DesktopNotifierSync",
|
|
36
37
|
"Capability",
|
|
37
38
|
"DEFAULT_SOUND",
|
|
38
39
|
"DEFAULT_ICON",
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
# -*- coding: utf-8 -*-
|
|
2
2
|
"""
|
|
3
|
-
|
|
3
|
+
Asynchronous desktop notification API
|
|
4
4
|
"""
|
|
5
|
-
|
|
6
5
|
from __future__ import annotations
|
|
7
6
|
|
|
8
7
|
# system imports
|
|
@@ -15,7 +14,6 @@ from pathlib import Path
|
|
|
15
14
|
from typing import (
|
|
16
15
|
Type,
|
|
17
16
|
Callable,
|
|
18
|
-
Coroutine,
|
|
19
17
|
List,
|
|
20
18
|
Any,
|
|
21
19
|
TypeVar,
|
|
@@ -126,11 +124,10 @@ class DesktopNotifier:
|
|
|
126
124
|
Linux, this should correspond to the application name in a desktop entry. On
|
|
127
125
|
macOS, this argument is ignored and the app is identified by the bundle ID of
|
|
128
126
|
the sending program (e.g., Python).
|
|
129
|
-
:param app_icon: Default icon to use for notifications. This should be
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
identified by the bundle ID of the sending program (e.g., Python).
|
|
127
|
+
:param app_icon: Default icon to use for notifications. This should be a
|
|
128
|
+
:class:`desktop_notifier.base.Icon` instance referencing either a file or a
|
|
129
|
+
named system icon. :class:`str` or :class:`pathlib.Path` are also accepted but
|
|
130
|
+
deprecated.
|
|
134
131
|
:param notification_limit: Maximum number of notifications to keep in the system's
|
|
135
132
|
notification center. This may be ignored by some implementations.
|
|
136
133
|
"""
|
|
@@ -140,11 +137,9 @@ class DesktopNotifier:
|
|
|
140
137
|
def __init__(
|
|
141
138
|
self,
|
|
142
139
|
app_name: str = "Python",
|
|
143
|
-
app_icon:
|
|
140
|
+
app_icon: Icon | Path | str | None = DEFAULT_ICON,
|
|
144
141
|
notification_limit: int | None = None,
|
|
145
142
|
) -> None:
|
|
146
|
-
impl_cls = get_implementation_class()
|
|
147
|
-
|
|
148
143
|
if isinstance(app_icon, str):
|
|
149
144
|
warnings.warn(
|
|
150
145
|
message="Pass an Icon instance instead of a string. "
|
|
@@ -166,28 +161,12 @@ class DesktopNotifier:
|
|
|
166
161
|
|
|
167
162
|
self.app_icon = app_icon
|
|
168
163
|
|
|
164
|
+
impl_cls = get_implementation_class()
|
|
169
165
|
self._impl = impl_cls(app_name, notification_limit)
|
|
170
166
|
self._did_request_authorisation = False
|
|
171
167
|
|
|
172
|
-
# Use our own event loop for the sync API so that we don't interfere with any
|
|
173
|
-
# other ansycio event loops / threads, etc.
|
|
174
|
-
self._loop = default_event_loop_policy.new_event_loop()
|
|
175
|
-
|
|
176
168
|
self._capabilities: frozenset[Capability] | None = None
|
|
177
169
|
|
|
178
|
-
def _run_coro_sync(self, coro: Coroutine[None, None, T]) -> T:
|
|
179
|
-
"""
|
|
180
|
-
Runs the given coroutine and returns the result synchronously. This is used as a
|
|
181
|
-
wrapper to conveniently convert the async API calls to synchronous ones.
|
|
182
|
-
"""
|
|
183
|
-
if self._loop.is_running():
|
|
184
|
-
future = asyncio.run_coroutine_threadsafe(coro, self._loop)
|
|
185
|
-
res = future.result()
|
|
186
|
-
else:
|
|
187
|
-
res = self._loop.run_until_complete(coro)
|
|
188
|
-
|
|
189
|
-
return res
|
|
190
|
-
|
|
191
170
|
@property
|
|
192
171
|
def app_name(self) -> str:
|
|
193
172
|
"""The application name"""
|
|
@@ -221,11 +200,17 @@ class DesktopNotifier:
|
|
|
221
200
|
"""
|
|
222
201
|
Sends a desktop notification.
|
|
223
202
|
|
|
224
|
-
This method
|
|
225
|
-
|
|
226
|
-
``
|
|
203
|
+
This method does not raise an exception when scheduling the notification fails
|
|
204
|
+
but logs warnings instead. If the notification was scheduled successfully, its
|
|
205
|
+
``identifier`` will be set to the platform's native notification identifier.
|
|
206
|
+
Otherwise, the ``identifier`` will be ``None``.
|
|
207
|
+
|
|
208
|
+
Note that even a successfully scheduled notification may not be displayed to the
|
|
209
|
+
user, depending on their notification center settings (for instance if "do not
|
|
210
|
+
disturb" is enabled on macOS).
|
|
227
211
|
|
|
228
212
|
:param notification: The notification to send.
|
|
213
|
+
:returns: The passed notification instance with a unique identifier populated.
|
|
229
214
|
"""
|
|
230
215
|
if not notification.icon:
|
|
231
216
|
notification.icon = self.app_icon
|
|
@@ -259,16 +244,9 @@ class DesktopNotifier:
|
|
|
259
244
|
"""
|
|
260
245
|
Sends a desktop notification
|
|
261
246
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
raise an exception when scheduling the notification fails. If the notification
|
|
266
|
-
was scheduled successfully, its ``identifier`` will be set to the platform's
|
|
267
|
-
native notification identifier. Otherwise, the ``identifier`` will be ``None``.
|
|
268
|
-
|
|
269
|
-
Note that even a successfully scheduled notification may not be displayed to the
|
|
270
|
-
user, depending on their notification center settings (for instance if "do not
|
|
271
|
-
disturb" is enabled on macOS).
|
|
247
|
+
This is a convenience function which creates a
|
|
248
|
+
:class:`desktop_notifier.base.Notification` with the provided arguments and then
|
|
249
|
+
calls :meth:`send_notification`.
|
|
272
250
|
|
|
273
251
|
:returns: The scheduled notification instance.
|
|
274
252
|
"""
|
|
@@ -288,52 +266,6 @@ class DesktopNotifier:
|
|
|
288
266
|
)
|
|
289
267
|
return await self.send_notification(notification)
|
|
290
268
|
|
|
291
|
-
def send_sync(
|
|
292
|
-
self,
|
|
293
|
-
title: str,
|
|
294
|
-
message: str,
|
|
295
|
-
urgency: Urgency = Urgency.Normal,
|
|
296
|
-
icon: str | Icon | None = None,
|
|
297
|
-
buttons: Sequence[Button] = (),
|
|
298
|
-
reply_field: ReplyField | None = None,
|
|
299
|
-
on_clicked: Callable[[], Any] | None = None,
|
|
300
|
-
on_dismissed: Callable[[], Any] | None = None,
|
|
301
|
-
attachment: str | Attachment | None = None,
|
|
302
|
-
sound: bool | Sound | None = None,
|
|
303
|
-
thread: str | None = None,
|
|
304
|
-
timeout: int = -1,
|
|
305
|
-
) -> Notification:
|
|
306
|
-
"""
|
|
307
|
-
Synchronous call of :meth:`send`, for use without an asyncio event loop.
|
|
308
|
-
|
|
309
|
-
.. deprecated:: 5.0.0
|
|
310
|
-
Use the async :func:`send` instead and schedule and block on its completion
|
|
311
|
-
if required.
|
|
312
|
-
|
|
313
|
-
:returns: The scheduled notification instance.
|
|
314
|
-
"""
|
|
315
|
-
warnings.warn(
|
|
316
|
-
message="'send_sync' is deprecated and will be removed in a future "
|
|
317
|
-
"version. Use the async 'send' API instead",
|
|
318
|
-
category=DeprecationWarning,
|
|
319
|
-
)
|
|
320
|
-
|
|
321
|
-
coro = self.send(
|
|
322
|
-
title,
|
|
323
|
-
message,
|
|
324
|
-
urgency=urgency,
|
|
325
|
-
icon=icon,
|
|
326
|
-
buttons=buttons,
|
|
327
|
-
reply_field=reply_field,
|
|
328
|
-
on_clicked=on_clicked,
|
|
329
|
-
on_dismissed=on_dismissed,
|
|
330
|
-
attachment=attachment,
|
|
331
|
-
sound=sound,
|
|
332
|
-
thread=thread,
|
|
333
|
-
timeout=timeout,
|
|
334
|
-
)
|
|
335
|
-
return self._run_coro_sync(coro)
|
|
336
|
-
|
|
337
269
|
@property
|
|
338
270
|
def current_notifications(self) -> List[Notification]:
|
|
339
271
|
"""A list of all currently displayed notifications for this app"""
|
|
@@ -354,11 +286,10 @@ class DesktopNotifier:
|
|
|
354
286
|
"""
|
|
355
287
|
await self._impl.clear_all()
|
|
356
288
|
|
|
357
|
-
|
|
358
|
-
def capabilities(self) -> frozenset[Capability]:
|
|
289
|
+
async def get_capabilities(self) -> frozenset[Capability]:
|
|
359
290
|
"""
|
|
360
|
-
Returns which functionality
|
|
291
|
+
Returns which functionality is supported by the implementation.
|
|
361
292
|
"""
|
|
362
293
|
if not self._capabilities:
|
|
363
|
-
self._capabilities = self.
|
|
294
|
+
self._capabilities = await self._impl.get_capabilities()
|
|
364
295
|
return self._capabilities
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
Synchronous desktop notification API
|
|
4
|
+
"""
|
|
5
|
+
from __future__ import annotations
|
|
6
|
+
|
|
7
|
+
# system imports
|
|
8
|
+
import asyncio
|
|
9
|
+
from typing import Callable, Coroutine, Any, Sequence, TypeVar, List
|
|
10
|
+
|
|
11
|
+
# local imports
|
|
12
|
+
from .main import DesktopNotifier
|
|
13
|
+
from .base import (
|
|
14
|
+
Capability,
|
|
15
|
+
Urgency,
|
|
16
|
+
Button,
|
|
17
|
+
ReplyField,
|
|
18
|
+
Icon,
|
|
19
|
+
Sound,
|
|
20
|
+
Attachment,
|
|
21
|
+
Notification,
|
|
22
|
+
DEFAULT_ICON,
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
__all__ = ["DesktopNotifierSync"]
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
T = TypeVar("T")
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
class DesktopNotifierSync:
|
|
32
|
+
"""
|
|
33
|
+
A synchronous counterpart to :class:`desktop_notifier.main.DesktopNotifier`
|
|
34
|
+
|
|
35
|
+
.. warning::
|
|
36
|
+
Callbacks on interaction with the notification will not work on macOS or Linux
|
|
37
|
+
without a running event loop.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
def __init__(
|
|
41
|
+
self,
|
|
42
|
+
app_name: str = "Python",
|
|
43
|
+
app_icon: Icon | None = DEFAULT_ICON,
|
|
44
|
+
notification_limit: int | None = None,
|
|
45
|
+
) -> None:
|
|
46
|
+
self._async_api = DesktopNotifier(app_name, app_icon, notification_limit)
|
|
47
|
+
self._loop = asyncio.new_event_loop()
|
|
48
|
+
|
|
49
|
+
def _run_coro_sync(self, coro: Coroutine[None, None, T]) -> T:
|
|
50
|
+
# Make sure to always use the same loop because async queues, future, etc. are
|
|
51
|
+
# always bound to a loop.
|
|
52
|
+
if self._loop.is_running():
|
|
53
|
+
future = asyncio.run_coroutine_threadsafe(coro, self._loop)
|
|
54
|
+
res = future.result()
|
|
55
|
+
else:
|
|
56
|
+
res = self._loop.run_until_complete(coro)
|
|
57
|
+
|
|
58
|
+
return res
|
|
59
|
+
|
|
60
|
+
@property
|
|
61
|
+
def app_name(self) -> str:
|
|
62
|
+
"""The application name"""
|
|
63
|
+
return self._async_api.app_name
|
|
64
|
+
|
|
65
|
+
@app_name.setter
|
|
66
|
+
def app_name(self, value: str) -> None:
|
|
67
|
+
"""Setter: app_name"""
|
|
68
|
+
self._async_api.app_name = value
|
|
69
|
+
|
|
70
|
+
def request_authorisation(self) -> bool:
|
|
71
|
+
"""See :meth:`desktop_notifier.main.DesktopNotifier.request_authorisation`"""
|
|
72
|
+
coro = self._async_api.request_authorisation()
|
|
73
|
+
return self._run_coro_sync(coro)
|
|
74
|
+
|
|
75
|
+
def has_authorisation(self) -> bool:
|
|
76
|
+
"""See :meth:`desktop_notifier.main.DesktopNotifier.has_authorisation`"""
|
|
77
|
+
coro = self._async_api.has_authorisation()
|
|
78
|
+
return self._run_coro_sync(coro)
|
|
79
|
+
|
|
80
|
+
def send_notification(self, notification: Notification) -> Notification:
|
|
81
|
+
"""See :meth:`desktop_notifier.main.DesktopNotifier.send_notification`"""
|
|
82
|
+
coro = self._async_api.send_notification(notification)
|
|
83
|
+
return self._run_coro_sync(coro)
|
|
84
|
+
|
|
85
|
+
def send(
|
|
86
|
+
self,
|
|
87
|
+
title: str,
|
|
88
|
+
message: str,
|
|
89
|
+
urgency: Urgency = Urgency.Normal,
|
|
90
|
+
icon: Icon | None = None,
|
|
91
|
+
buttons: Sequence[Button] = (),
|
|
92
|
+
reply_field: ReplyField | None = None,
|
|
93
|
+
on_clicked: Callable[[], Any] | None = None,
|
|
94
|
+
on_dismissed: Callable[[], Any] | None = None,
|
|
95
|
+
attachment: Attachment | None = None,
|
|
96
|
+
sound: Sound | None = None,
|
|
97
|
+
thread: str | None = None,
|
|
98
|
+
timeout: int = -1,
|
|
99
|
+
) -> Notification:
|
|
100
|
+
"""See :meth:`desktop_notifier.main.DesktopNotifier.send`"""
|
|
101
|
+
notification = Notification(
|
|
102
|
+
title,
|
|
103
|
+
message,
|
|
104
|
+
urgency=urgency,
|
|
105
|
+
icon=icon,
|
|
106
|
+
buttons=buttons,
|
|
107
|
+
reply_field=reply_field,
|
|
108
|
+
on_clicked=on_clicked,
|
|
109
|
+
on_dismissed=on_dismissed,
|
|
110
|
+
attachment=attachment,
|
|
111
|
+
sound=sound,
|
|
112
|
+
thread=thread,
|
|
113
|
+
timeout=timeout,
|
|
114
|
+
)
|
|
115
|
+
coro = self._async_api.send_notification(notification)
|
|
116
|
+
return self._run_coro_sync(coro)
|
|
117
|
+
|
|
118
|
+
@property
|
|
119
|
+
def current_notifications(self) -> List[Notification]:
|
|
120
|
+
"""A list of all currently displayed notifications for this app"""
|
|
121
|
+
return self._async_api.current_notifications
|
|
122
|
+
|
|
123
|
+
def clear(self, notification: Notification) -> None:
|
|
124
|
+
"""See :meth:`desktop_notifier.main.DesktopNotifier.notification`"""
|
|
125
|
+
coro = self._async_api.clear(notification)
|
|
126
|
+
return self._run_coro_sync(coro)
|
|
127
|
+
|
|
128
|
+
def clear_all(self) -> None:
|
|
129
|
+
"""See :meth:`desktop_notifier.main.DesktopNotifier.clear_all`"""
|
|
130
|
+
coro = self._async_api.clear_all()
|
|
131
|
+
return self._run_coro_sync(coro)
|
|
132
|
+
|
|
133
|
+
def get_capabilities(self) -> frozenset[Capability]:
|
|
134
|
+
"""See :meth:`desktop_notifier.main.DesktopNotifier.get_capabilities`"""
|
|
135
|
+
coro = self._async_api.get_capabilities()
|
|
136
|
+
return self._run_coro_sync(coro)
|
|
@@ -7,7 +7,6 @@ ctypes because the C winapi only supports basic notifications with a title and m
|
|
|
7
7
|
This backend therefore requires interaction with the Windows Runtime and uses the winrt
|
|
8
8
|
package with compiled components.
|
|
9
9
|
"""
|
|
10
|
-
|
|
11
10
|
from __future__ import annotations
|
|
12
11
|
|
|
13
12
|
# system imports
|
{desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1/src/desktop_notifier.egg-info}/PKG-INFO
RENAMED
|
@@ -1,22 +1,31 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: desktop-notifier
|
|
3
|
-
Version: 5.0.
|
|
3
|
+
Version: 5.0.1
|
|
4
4
|
Summary: Python library for cross-platform desktop notifications
|
|
5
5
|
Author-email: Sam Schott <sam.schott@outlook.com>
|
|
6
6
|
License: MIT
|
|
7
7
|
Project-URL: Homepage, https://github.com/samschott/desktop-notifier
|
|
8
|
-
Keywords: desktop-notifier
|
|
9
|
-
Classifier: Development Status ::
|
|
8
|
+
Keywords: desktop-notifier,notifications,Notification Center,push notifications,Toast notifications
|
|
9
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
10
10
|
Classifier: Intended Audience :: Developers
|
|
11
11
|
Classifier: License :: OSI Approved :: MIT License
|
|
12
12
|
Classifier: Natural Language :: English
|
|
13
|
+
Classifier: Operating System :: MacOS :: MacOS X
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
13
16
|
Classifier: Programming Language :: Python :: 3
|
|
14
17
|
Classifier: Programming Language :: Python :: 3.7
|
|
15
18
|
Classifier: Programming Language :: Python :: 3.8
|
|
16
19
|
Classifier: Programming Language :: Python :: 3.9
|
|
17
20
|
Classifier: Programming Language :: Python :: 3.10
|
|
18
21
|
Classifier: Programming Language :: Python :: 3.11
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
23
|
Classifier: Programming Language :: Python :: 3 :: Only
|
|
24
|
+
Classifier: Topic :: Communications
|
|
25
|
+
Classifier: Topic :: Desktop Environment
|
|
26
|
+
Classifier: Topic :: Desktop Environment :: Gnome
|
|
27
|
+
Classifier: Topic :: Desktop Environment :: K Desktop Environment (KDE)
|
|
28
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
20
29
|
Requires-Python: >=3.7
|
|
21
30
|
Description-Content-Type: text/markdown
|
|
22
31
|
License-File: LICENSE
|
|
@@ -44,30 +53,22 @@ Requires-Dist: sphinx==7.3.7; extra == "docs"
|
|
|
44
53
|
Requires-Dist: sphinx-autoapi==3.1.2; extra == "docs"
|
|
45
54
|
Requires-Dist: sphinx-mdinclude==0.6.1; extra == "docs"
|
|
46
55
|
|
|
56
|
+
|
|
57
|
+
# Desktop Notifier
|
|
58
|
+
|
|
47
59
|
[](https://pypi.org/project/desktop-notifier/)
|
|
48
60
|
[](https://pypi.org/pypi/desktop-notifier/)
|
|
49
61
|
[](https://desktop-notifier.readthedocs.io/en/latest/?badge=latest)
|
|
50
62
|
|
|
51
|
-
# Desktop Notifier
|
|
52
|
-
|
|
53
63
|
`desktop-notifier` is a Python library for cross-platform desktop notifications.
|
|
54
64
|
Currently supported platforms are:
|
|
55
65
|
|
|
56
66
|
* Linux via the dbus service org.freedesktop.Notifications
|
|
57
67
|
* macOS and iOS via the Notification Center framework
|
|
58
|
-
*
|
|
59
|
-
|
|
60
|
-

|
|
68
|
+
* Windows via the WinRT / Python bridge
|
|
61
69
|
|
|
62
70
|
## Features
|
|
63
71
|
|
|
64
|
-
`desktop-notifier` aims to be a good citizen of the platforms which it supports. It
|
|
65
|
-
therefore stays within the limits of the native platform APIs and does not try to work
|
|
66
|
-
around limitations which are often deliberate UI choices. For example, on macOS and
|
|
67
|
-
iOS, it is not possible to change the app icon which is shown on notifications. There
|
|
68
|
-
are possible workarounds - that would likely be rejected by an App Store review - and
|
|
69
|
-
desktop-notifier deliberately stays away from those.
|
|
70
|
-
|
|
71
72
|
Where supported by the native platform APIs, `desktop-notifier` allows for:
|
|
72
73
|
|
|
73
74
|
* Clickable notifications with callbacks on user interaction
|
|
@@ -77,16 +78,17 @@ Where supported by the native platform APIs, `desktop-notifier` allows for:
|
|
|
77
78
|
* Notification threads (grouping notifications by topic)
|
|
78
79
|
* Limiting the maximum number of notifications shown in the notification center
|
|
79
80
|
|
|
81
|
+
An example of how some of this looks like on macOS:
|
|
82
|
+
|
|
83
|
+

|
|
84
|
+
|
|
80
85
|
An exhaustive list of features and their platform support is provided in the
|
|
81
86
|
[documentation](https://desktop-notifier.readthedocs.io/en/latest/background/platform_support.html).
|
|
87
|
+
In addition, you can query supported features at runtime with
|
|
88
|
+
`DesktopNotifier.get_capabilities()`.
|
|
82
89
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
* Async API: The main API consists of async methods and a running event loop
|
|
86
|
-
is required to respond to user interactions with a notification.
|
|
87
|
-
* Prefer pure Python dependencies over extension modules. We make an exception for
|
|
88
|
-
Windows because interoperability with the Windows Runtime is difficult to achieve
|
|
89
|
-
otherwise.
|
|
90
|
+
Any options or configurations which are not supported by the platform will be silently
|
|
91
|
+
ignored.
|
|
90
92
|
|
|
91
93
|
## Installation
|
|
92
94
|
|
|
@@ -108,71 +110,58 @@ from desktop_notifier import DesktopNotifier
|
|
|
108
110
|
notifier = DesktopNotifier()
|
|
109
111
|
|
|
110
112
|
async def main():
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
await asyncio.sleep(5) # wait a bit before clearing notification
|
|
114
|
-
|
|
115
|
-
await notifier.clear(n) # removes the notification
|
|
116
|
-
await notifier.clear_all() # removes all notifications for this app
|
|
113
|
+
await notifier.send(title="Hello world!", message="Sent from Python")
|
|
117
114
|
|
|
118
115
|
asyncio.run(main())
|
|
119
116
|
```
|
|
120
117
|
|
|
121
|
-
For convenience, there is also a synchronous method ``send_sync()`` to send
|
|
122
|
-
notifications without manually starting an asyncio event loop:
|
|
123
|
-
|
|
124
|
-
```Python
|
|
125
|
-
notifier.send_sync(title="Hello world!", message="Sent from Python")
|
|
126
|
-
```
|
|
127
|
-
|
|
128
118
|
By default, "Python" will be used as the app name for all notifications, but you can
|
|
129
119
|
manually specify an app name and icon in the ``DesktopNotifier`` constructor. Advanced
|
|
130
120
|
usage also allows setting different notification options such as urgency, buttons,
|
|
131
|
-
callbacks, etc.
|
|
132
|
-
the top of the page:
|
|
121
|
+
callbacks, etc. For example, for the gif displayed above:
|
|
133
122
|
|
|
134
123
|
```Python
|
|
135
124
|
import asyncio
|
|
136
|
-
|
|
125
|
+
import signal
|
|
137
126
|
|
|
138
|
-
|
|
127
|
+
from desktop_notifier import DesktopNotifier, Urgency, Button, ReplyField, DEFAULT_SOUND
|
|
139
128
|
|
|
140
|
-
async def main():
|
|
141
|
-
await notifier.send(
|
|
142
|
-
title="Julius Caesar",
|
|
143
|
-
message="Et tu, Brute?",
|
|
144
|
-
urgency=Urgency.Critical,
|
|
145
|
-
buttons=[
|
|
146
|
-
Button(
|
|
147
|
-
title="Mark as read",
|
|
148
|
-
on_pressed=lambda: print("Marked as read")),
|
|
149
|
-
],
|
|
150
|
-
reply_field=ReplyField(
|
|
151
|
-
title="Reply",
|
|
152
|
-
button_title="Send",
|
|
153
|
-
on_replied=lambda text: print("Brutus replied:", text),
|
|
154
|
-
),
|
|
155
|
-
on_clicked=lambda: print("Notification clicked"),
|
|
156
|
-
on_dismissed=lambda: print("Notification dismissed"),
|
|
157
|
-
sound_file=DEFAULT_SOUND,
|
|
158
|
-
)
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
loop = asyncio.get_event_loop()
|
|
162
|
-
loop.create_task(main())
|
|
163
|
-
loop.run_forever()
|
|
164
|
-
```
|
|
165
129
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
130
|
+
async def main() -> None:
|
|
131
|
+
notifier = DesktopNotifier(
|
|
132
|
+
app_name="Sample App",
|
|
133
|
+
notification_limit=10,
|
|
134
|
+
)
|
|
135
|
+
|
|
136
|
+
await notifier.send(
|
|
137
|
+
title="Julius Caesar",
|
|
138
|
+
message="Et tu, Brute?",
|
|
139
|
+
urgency=Urgency.Critical,
|
|
140
|
+
buttons=[
|
|
141
|
+
Button(
|
|
142
|
+
title="Mark as read",
|
|
143
|
+
on_pressed=lambda: print("Marked as read"),
|
|
144
|
+
)
|
|
145
|
+
],
|
|
146
|
+
reply_field=ReplyField(
|
|
147
|
+
on_replied=lambda text: print("Brutus replied:", text),
|
|
148
|
+
),
|
|
149
|
+
on_clicked=lambda: print("Notification clicked"),
|
|
150
|
+
on_dismissed=lambda: print("Notification dismissed"),
|
|
151
|
+
sound=DEFAULT_SOUND,
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
# Run the event loop forever to respond to user interactions with the notification.
|
|
155
|
+
stop_event = asyncio.Event()
|
|
156
|
+
loop = asyncio.get_running_loop()
|
|
157
|
+
|
|
158
|
+
loop.add_signal_handler(signal.SIGINT, stop_event.set)
|
|
159
|
+
loop.add_signal_handler(signal.SIGTERM, stop_event.set)
|
|
160
|
+
|
|
161
|
+
await stop_event.wait()
|
|
173
162
|
|
|
174
|
-
|
|
175
|
-
|
|
163
|
+
asyncio.run(main())
|
|
164
|
+
```
|
|
176
165
|
|
|
177
166
|
## Event loop integration
|
|
178
167
|
|
|
@@ -190,10 +179,6 @@ from rubicon.objc.eventloop import EventLoopPolicy
|
|
|
190
179
|
|
|
191
180
|
# Install the event loop policy
|
|
192
181
|
asyncio.set_event_loop_policy(EventLoopPolicy())
|
|
193
|
-
|
|
194
|
-
# Get an event loop, and run it!
|
|
195
|
-
loop = asyncio.get_event_loop()
|
|
196
|
-
loop.run_forever()
|
|
197
182
|
```
|
|
198
183
|
|
|
199
184
|
Desktop-notifier itself uses Rubicon Objective-C to interface with Cocoa APIs. A full
|
|
@@ -221,13 +206,26 @@ the resulting app bundle for notifications to work. An ad-hoc signature will be
|
|
|
221
206
|
sufficient but signing with an Apple developer certificate is recommended for
|
|
222
207
|
distribution and may be required on future releases of macOS.
|
|
223
208
|
|
|
224
|
-
##
|
|
209
|
+
## Design choices
|
|
210
|
+
|
|
211
|
+
This package is opinionated in a few ways:
|
|
225
212
|
|
|
226
|
-
*
|
|
227
|
-
|
|
213
|
+
* It does not try to work around platform restrictions, such as changing the app icon on
|
|
214
|
+
macOS. Workarounds would be hacky and likely be rejected by an App Store review.
|
|
215
|
+
* The main API consists of async methods and a running event loop is required to respond
|
|
216
|
+
to user interactions with a notification. This simplifies integration with GUI apps.
|
|
217
|
+
* Dependencies are pure Python packages without extension modules. This simplifies app
|
|
218
|
+
bundling and distribution. We make an exception for Windows because interoperability
|
|
219
|
+
with the Windows Runtime is difficult to achieve without extension modules.
|
|
220
|
+
* If a certain feature is not supported by a platform, using it will not raise an
|
|
221
|
+
exception. This allows clients to use a wide feature set where available without
|
|
222
|
+
worrying about exception handling.
|
|
223
|
+
* If a notification cannot be scheduled, this is logged as a warning and does not raise
|
|
224
|
+
an exception. Most platforms allow the user to control if and how notifications are
|
|
225
|
+
delivered and notification delivery therefore cannot be taken as guaranteed.
|
|
228
226
|
|
|
229
227
|
## Dependencies
|
|
230
228
|
|
|
231
229
|
* [dbus-next](https://github.com/altdesktop/python-dbus-next) on Linux
|
|
232
230
|
* [rubicon-objc](https://github.com/beeware/rubicon-objc) on macOS
|
|
233
|
-
* [
|
|
231
|
+
* [pywinrt](https://github.com/pywinrt/pywinrt) on Windows
|
{desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier.egg-info/SOURCES.txt
RENAMED
|
@@ -9,6 +9,7 @@ src/desktop_notifier/macos.py
|
|
|
9
9
|
src/desktop_notifier/macos_support.py
|
|
10
10
|
src/desktop_notifier/main.py
|
|
11
11
|
src/desktop_notifier/py.typed
|
|
12
|
+
src/desktop_notifier/sync.py
|
|
12
13
|
src/desktop_notifier/winrt.py
|
|
13
14
|
src/desktop_notifier.egg-info/PKG-INFO
|
|
14
15
|
src/desktop_notifier.egg-info/SOURCES.txt
|
|
@@ -17,4 +18,5 @@ src/desktop_notifier.egg-info/requires.txt
|
|
|
17
18
|
src/desktop_notifier.egg-info/top_level.txt
|
|
18
19
|
src/desktop_notifier/resources/__init__.py
|
|
19
20
|
src/desktop_notifier/resources/python.png
|
|
20
|
-
tests/test_api.py
|
|
21
|
+
tests/test_api.py
|
|
22
|
+
tests/test_sync_api.py
|
|
@@ -110,32 +110,6 @@ async def test_attachment_uri(notifier):
|
|
|
110
110
|
)
|
|
111
111
|
|
|
112
112
|
|
|
113
|
-
def test_send_sync(notifier):
|
|
114
|
-
notification = notifier.send_sync(
|
|
115
|
-
title="Julius Caesar",
|
|
116
|
-
message="Et tu, Brute?",
|
|
117
|
-
urgency=Urgency.Critical,
|
|
118
|
-
buttons=[
|
|
119
|
-
Button(
|
|
120
|
-
title="Mark as read",
|
|
121
|
-
on_pressed=lambda: print("Marked as read"),
|
|
122
|
-
)
|
|
123
|
-
],
|
|
124
|
-
reply_field=ReplyField(
|
|
125
|
-
title="Reply",
|
|
126
|
-
button_title="Send",
|
|
127
|
-
on_replied=lambda text: print("Brutus replied:", text),
|
|
128
|
-
),
|
|
129
|
-
on_clicked=lambda: print("Notification clicked"),
|
|
130
|
-
on_dismissed=lambda: print("Notification dismissed"),
|
|
131
|
-
sound=DEFAULT_SOUND,
|
|
132
|
-
thread="test_notifications",
|
|
133
|
-
timeout=5,
|
|
134
|
-
)
|
|
135
|
-
assert notification in notifier.current_notifications
|
|
136
|
-
assert notification.identifier != ""
|
|
137
|
-
|
|
138
|
-
|
|
139
113
|
@pytest.mark.asyncio
|
|
140
114
|
@pytest.mark.skipif(
|
|
141
115
|
sys.platform.startswith("win"),
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import sys
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from desktop_notifier import Urgency, Button, ReplyField, DEFAULT_SOUND
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_send(notifier_sync):
|
|
8
|
+
notification = notifier_sync.send(
|
|
9
|
+
title="Julius Caesar",
|
|
10
|
+
message="Et tu, Brute?",
|
|
11
|
+
urgency=Urgency.Critical,
|
|
12
|
+
buttons=[
|
|
13
|
+
Button(
|
|
14
|
+
title="Mark as read",
|
|
15
|
+
on_pressed=lambda: print("Marked as read"),
|
|
16
|
+
)
|
|
17
|
+
],
|
|
18
|
+
reply_field=ReplyField(
|
|
19
|
+
title="Reply",
|
|
20
|
+
button_title="Send",
|
|
21
|
+
on_replied=lambda text: print("Brutus replied:", text),
|
|
22
|
+
),
|
|
23
|
+
on_clicked=lambda: print("Notification clicked"),
|
|
24
|
+
on_dismissed=lambda: print("Notification dismissed"),
|
|
25
|
+
sound=DEFAULT_SOUND,
|
|
26
|
+
thread="test_notifications",
|
|
27
|
+
timeout=5,
|
|
28
|
+
)
|
|
29
|
+
assert notification in notifier_sync.current_notifications
|
|
30
|
+
assert notification.identifier != ""
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
@pytest.mark.skipif(
|
|
34
|
+
sys.platform.startswith("win"),
|
|
35
|
+
reason="Clearing individual notifications is broken on Windows",
|
|
36
|
+
)
|
|
37
|
+
def test_clear(notifier_sync):
|
|
38
|
+
n0 = notifier_sync.send(
|
|
39
|
+
title="Julius Caesar",
|
|
40
|
+
message="Et tu, Brute?",
|
|
41
|
+
)
|
|
42
|
+
n1 = notifier_sync.send(
|
|
43
|
+
title="Julius Caesar",
|
|
44
|
+
message="Et tu, Brute?",
|
|
45
|
+
)
|
|
46
|
+
assert n0 in notifier_sync.current_notifications
|
|
47
|
+
assert n1 in notifier_sync.current_notifications
|
|
48
|
+
|
|
49
|
+
notifier_sync.clear(n0)
|
|
50
|
+
assert n0 not in notifier_sync.current_notifications
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_clear_all(notifier_sync):
|
|
54
|
+
n0 = notifier_sync.send(
|
|
55
|
+
title="Julius Caesar",
|
|
56
|
+
message="Et tu, Brute?",
|
|
57
|
+
)
|
|
58
|
+
n1 = notifier_sync.send(
|
|
59
|
+
title="Julius Caesar",
|
|
60
|
+
message="Et tu, Brute?",
|
|
61
|
+
)
|
|
62
|
+
assert n0 in notifier_sync.current_notifications
|
|
63
|
+
assert n1 in notifier_sync.current_notifications
|
|
64
|
+
|
|
65
|
+
notifier_sync.clear_all()
|
|
66
|
+
assert len(notifier_sync.current_notifications) == 0
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/resources/__init__.py
RENAMED
|
File without changes
|
{desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier/resources/python.png
RENAMED
|
File without changes
|
|
File without changes
|
{desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier.egg-info/requires.txt
RENAMED
|
File without changes
|
{desktop_notifier-5.0.0.dev1 → desktop_notifier-5.0.1}/src/desktop_notifier.egg-info/top_level.txt
RENAMED
|
File without changes
|