Skip to content

Desktop Notifier v7.0 #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
6fb4630
Remove Notification.__repr__()
PhrozenByte Nov 25, 2024
bbaf049
Make Notification.buttons_dict public utilizing `immutabledict`
PhrozenByte Nov 25, 2024
16d6c46
Allow Notification(identifier=None) and Button(identifier=None) init
PhrozenByte Nov 25, 2024
d0dfd82
DBusDesktopNotifier: Fix lazy DBus bus initialization
PhrozenByte Nov 25, 2024
7a45433
DBusDesktopNotifier: Fix sending notifications with named sounds
PhrozenByte Nov 19, 2024
d440869
DesktopNotifier: Fix docstring of on_button_pressed()
PhrozenByte Nov 19, 2024
bc915a2
README.md: Remove DesktopNotifier(notification_limit=10) from example…
PhrozenByte Nov 19, 2024
ca212a3
DesktopNotifierBackend: Drop `notification` param from `handle_*()` m…
PhrozenByte Nov 25, 2024
13638cd
Move DesktopNotifier.app_icon to DesktopNotifierBackend.app_icon
PhrozenByte Nov 26, 2024
639971a
DesktopNotifierSync: Pass `notification_limit` to show warning
PhrozenByte Nov 26, 2024
90e7460
DesktopNotifierSync: Add `on_*` properties for class-level events
PhrozenByte Nov 26, 2024
48678af
Add cross-platform notification timeouts
PhrozenByte Nov 26, 2024
c539338
Unit tests: Fix check_supported() message
PhrozenByte Nov 26, 2024
4968441
Add on_cleared event
PhrozenByte Nov 26, 2024
fc660b2
Add on_dispatched event
PhrozenByte Nov 26, 2024
a7eea9b
Merge branch 'enhancement/backend_app_icon' into desktop-notifier-v7.0
PhrozenByte Nov 27, 2024
8b80c17
Merge branch 'enhancement/qol-notification-class' into desktop-notifi…
PhrozenByte Nov 27, 2024
8c2b3f3
Merge branch 'bugfix/misc-20241125' into desktop-notifier-v7.0
PhrozenByte Nov 27, 2024
6ed5fd0
Merge branch 'enhancement/event-handling-obj' into desktop-notifier-v7.0
PhrozenByte Nov 27, 2024
d265330
Merge branch 'enhancement/universal-timeout' into desktop-notifier-v7.0
PhrozenByte Nov 27, 2024
d9747dd
Merge branch 'enhancement/global-event-callbacks-sync' into desktop-n…
PhrozenByte Nov 27, 2024
a8f1e33
Merge branch 'enhancement/event-on_cleared' into desktop-notifier-v7.0
PhrozenByte Nov 27, 2024
22c28dc
Merge branch 'enhancement/event-on_dispatched' into desktop-notifier-…
PhrozenByte Nov 27, 2024
7fedc24
Add DispatchedNotification class
PhrozenByte Nov 27, 2024
33b5f88
Update unit tests for DispatchedNotification
PhrozenByte Nov 27, 2024
da74e40
Improve CI
PhrozenByte Nov 27, 2024
51067ee
Update CHANGES.md
PhrozenByte Nov 26, 2024
95ef1ea
WIP
PhrozenByte Nov 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
flake8 src tests examples
- name: isort
run: |
isort src tests examples
isort --check --diff src tests examples

mypy:
runs-on: ${{ matrix.os }}
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ venv/
.installed.cfg
*.egg

# pytest / coverage
.coverage
coverage.xml

# IntelliJ Idea family of suites
.idea
*.iml
Expand Down
31 changes: 31 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
# v7.0.0

## Added:

* New `DispatchedNotification` class with the platform native notification identifier
and runtime-updated status information about that notification
* New cross-platform implementation for `timeout`
* New `on_dispatched` event that is triggered when a notification was sent to the
notifications server.
* New `on_cleared` event that is triggered when a notification is closed without
user interaction (e.g. because it expired).
* Add class-level callbacks to `DesktopNotifierSync` as well

## Changed:

* `send` methods now return `DispatchedNotification` instances.
* `send` methods now also accept `DispatchedNotification` instances, allowing one to
replace existing notifications with updated information; to do so simply create a
new `DispatchedNotification` instance with the same `identifier`, but a different
`Notification` instance
* `Notification` now accepts floats as `timeout`
* `Notification` and `Button` instances can now be initialized with `identifier=None`
* Interaction callbacks at the `DesktopNotifier` level now truly receive all events
the notifications server signals; depending on the platform this might include
interactions with notifications of other applications as well

## Fixed:

* Fixed sending notifications with a named sound resource on Linux
(given that the notifications server has that capability)

# v6.0.0

## Added:
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,7 @@ from desktop_notifier import DesktopNotifier, Urgency, Button, ReplyField, DEFAU


async def main() -> None:
notifier = DesktopNotifier(
app_name="Sample App",
notification_limit=10,
)
notifier = DesktopNotifier(app_name="Sample App")

await notifier.send(
title="Julius Caesar",
Expand All @@ -91,9 +88,12 @@ async def main() -> None:
reply_field=ReplyField(
on_replied=lambda text: print("Brutus replied:", text),
),
on_dispatched=lambda: print("Notification showing"),
on_cleared=lambda: print("Notification timed out"),
on_clicked=lambda: print("Notification clicked"),
on_dismissed=lambda: print("Notification dismissed"),
sound=DEFAULT_SOUND,
timeout=10,
)

# Run the event loop forever to respond to user interactions with the notification.
Expand Down
2 changes: 1 addition & 1 deletion docs/background/platform_support.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Please refer to the platform documentation for more detailed information:
"sound", "Play a sound with the notification", "✓ [#f2]_", "✓ [#f5]_", "✓"
"thread", "An identifier to group notifications together", "--", "✓", "✓"
"attachment", "File attachment, e.g., an image", "✓ [#f2]_ [#f6]_", "✓ [#f6]_", "✓ [#f6]_"
"timeout", "Duration in seconds until notification auto-dismissal", "✓", "--", "--"
"timeout", "Duration in seconds until notification auto-dismissal", "✓", "", ""

.. [#f1] App name and icon on macOS and Windows are automatically determined by the
calling application.
Expand Down
3 changes: 3 additions & 0 deletions examples/eventloop.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,12 @@ async def main() -> None:
button_title="Send",
on_replied=lambda text: print("Brutus replied:", text),
),
on_dispatched=lambda: print("Notification showing"),
on_cleared=lambda: print("Notification timed out"),
on_clicked=lambda: print("Notification clicked"),
on_dismissed=lambda: print("Notification dismissed"),
sound=DEFAULT_SOUND,
timeout=10,
)

# Run the event loop forever to respond to user interactions with the notification.
Expand Down
11 changes: 11 additions & 0 deletions examples/eventloop_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@
asyncio.set_event_loop_policy(EventLoopPolicy())


def on_dispatched(identifier: str) -> None:
print(f"Notification '{identifier}' is showing now")


def on_cleared(identifier: str) -> None:
print(f"Notification '{identifier}' was cleared without user interaction")


def on_clicked(identifier: str) -> None:
print(f"Notification '{identifier}' was clicked")

Expand All @@ -29,6 +37,8 @@ def on_replied(identifier: str, reply: str) -> None:

async def main() -> None:
notifier = DesktopNotifier(app_name="Sample App")
notifier.on_dispatched = on_dispatched
notifier.on_cleared = on_cleared
notifier.on_clicked = on_clicked
notifier.on_dismissed = on_dismissed
notifier.on_button_pressed = on_button_pressed
Expand All @@ -47,6 +57,7 @@ async def main() -> None:
button_title="Send",
),
sound=DEFAULT_SOUND,
timeout=10,
)

# Run the event loop forever to respond to user interactions with the notification.
Expand Down
3 changes: 3 additions & 0 deletions examples/synchronous.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,10 @@
button_title="Send",
on_replied=lambda text: print("Brutus replied:", text),
),
on_dispatched=lambda: print("Notification showing"),
on_cleared=lambda: print("Notification timed out"),
on_clicked=lambda: print("Notification clicked"),
on_dismissed=lambda: print("Notification dismissed"),
sound=DEFAULT_SOUND,
timeout=10,
)
6 changes: 2 additions & 4 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ classifiers = [
]
requires-python = ">=3.9"
dependencies = [
"bidict",
"packaging",
"immutabledict",
"dbus-fast;sys_platform=='linux'",
"rubicon-objc;sys_platform=='darwin'",
"winrt-windows.applicationmodel.core;sys_platform=='win32'",
Expand Down Expand Up @@ -81,9 +81,7 @@ docs = [
desktop_notifier = ["**/*.png"]

[tool.flake8]
ignore = "E203,E501,W503,H306"
per-file-ignores = """
__init__.py: F401"""
ignore = "E501,W503"
statistics = "True"

[tool.mypy]
Expand Down
2 changes: 2 additions & 0 deletions src/desktop_notifier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Button,
Capability,
DesktopNotifier,
DispatchedNotification,
Icon,
Notification,
ReplyField,
Expand Down Expand Up @@ -37,4 +38,5 @@
"Capability",
"DEFAULT_SOUND",
"DEFAULT_ICON",
"DispatchedNotification",
]
Loading
Loading