Skip to content

Commit e87b3ca

Browse files
committed
Update on_cleared event docs
Improve docs of the `ON_CLEARED` capability and update other docs to allow distinguishing between expired and programatically closed notifications in the future. Actually adding support for expiring notifications is out-of-scope here.
1 parent f210474 commit e87b3ca

File tree

6 files changed

+32
-25
lines changed

6 files changed

+32
-25
lines changed

README.md

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,23 @@ async def main() -> None:
8282
buttons=[
8383
Button(
8484
title="Mark as read",
85-
on_pressed=lambda: print("Marked as read"),
86-
)
85+
on_pressed=lambda: print("Button 'Mark as read' was clicked"),
86+
),
87+
Button(
88+
title="Click me!!",
89+
on_pressed=lambda: print("Button 'Click me!!' was clicked"),
90+
),
8791
],
8892
reply_field=ReplyField(
89-
on_replied=lambda text: print("Brutus replied:", text),
93+
title="Reply",
94+
button_title="Send",
95+
on_replied=lambda text: print(f"Received reply '{text}'"),
9096
),
91-
on_dispatched=lambda: print("Notification showing"),
92-
on_cleared=lambda: print("Notification timed out"),
93-
on_clicked=lambda: print("Notification clicked"),
94-
on_dismissed=lambda: print("Notification dismissed"),
97+
on_dispatched=lambda: print("Notification is showing now"),
98+
on_cleared=lambda: print("Notification was closed w/o user interaction"),
99+
on_clicked=lambda: print("Notification was clicked"),
100+
on_dismissed=lambda: print("Notification was dismissed by the user"),
95101
sound=DEFAULT_SOUND,
96-
timeout=10,
97102
)
98103

99104
# Run the event loop forever to respond to user interactions with the notification.

examples/eventloop.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,10 @@ async def main() -> None:
3434
on_replied=lambda text: print(f"Received reply '{text}'"),
3535
),
3636
on_dispatched=lambda: print("Notification is showing now"),
37-
on_cleared=lambda: print("Notification timed out"),
37+
on_cleared=lambda: print("Notification was closed w/o user interaction"),
3838
on_clicked=lambda: print("Notification was clicked"),
39-
on_dismissed=lambda: print("Notification was dismissed"),
39+
on_dismissed=lambda: print("Notification was dismissed by the user"),
4040
sound=DEFAULT_SOUND,
41-
timeout=10,
4241
)
4342

4443
# Run the event loop forever to respond to user interactions with the notification.

examples/eventloop_handlers.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ def on_dispatched(identifier: str) -> None:
1616

1717

1818
def on_cleared(identifier: str) -> None:
19-
print(f"Notification '{identifier}' was cleared without user interaction")
19+
print(f"Notification '{identifier}' was closed w/o user interaction")
2020

2121

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

2525

2626
def on_dismissed(identifier: str) -> None:
27-
print(f"Notification '{identifier}' was dismissed")
27+
print(f"Notification '{identifier}' was dismissed by the user")
2828

2929

3030
def on_button_pressed(identifier: str, button_identifier: str) -> None:
@@ -57,7 +57,6 @@ async def main() -> None:
5757
button_title="Send",
5858
),
5959
sound=DEFAULT_SOUND,
60-
timeout=10,
6160
)
6261

6362
# Run the event loop forever to respond to user interactions with the notification.

examples/synchronous.py

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,21 @@
1515
buttons=[
1616
Button(
1717
title="Mark as read",
18-
on_pressed=lambda: print("Marked as read"),
19-
)
18+
on_pressed=lambda: print("Button 'Mark as read' was clicked"),
19+
),
20+
Button(
21+
title="Click me!!",
22+
on_pressed=lambda: print("Button 'Click me!!' was clicked"),
23+
),
2024
],
2125
reply_field=ReplyField(
2226
title="Reply",
2327
button_title="Send",
24-
on_replied=lambda text: print("Brutus replied:", text),
28+
on_replied=lambda text: print(f"Received reply '{text}'"),
2529
),
26-
on_dispatched=lambda: print("Notification showing"),
27-
on_cleared=lambda: print("Notification timed out"),
28-
on_clicked=lambda: print("Notification clicked"),
29-
on_dismissed=lambda: print("Notification dismissed"),
30+
on_dispatched=lambda: print("Notification is showing now"),
31+
on_cleared=lambda: print("Notification was closed w/o user interaction"),
32+
on_clicked=lambda: print("Notification was clicked"),
33+
on_dismissed=lambda: print("Notification was dismissed by the user"),
3034
sound=DEFAULT_SOUND,
31-
timeout=10,
3235
)

src/desktop_notifier/common.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,9 @@ class Capability(Enum):
304304
"""Supports on-dispatched callbacks"""
305305

306306
ON_CLEARED = auto()
307-
"""Supports distinguishing between an user closing a notification, and clearing a
308-
notification programmatically, and consequently supports on-cleared callbacks"""
307+
"""Supports on-cleared callbacks, which are called if a notification wasn't
308+
cleared by user interaction, but programmatically; platforms not supporting
309+
this distinction will call on-dismissed callbacks instead"""
309310

310311
ON_CLICKED = auto()
311312
"""Supports on-clicked callbacks"""

src/desktop_notifier/main.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ def on_dispatched(self, handler: Callable[[str], Any] | None) -> None:
300300
def on_cleared(self) -> Callable[[str], Any] | None:
301301
"""
302302
A method to call when a notification is cleared without user interaction
303-
(e.g. after a timeout, or if cleared by another process)
303+
(e.g. if cleared by another process)
304304
305305
The method must take the notification identifier as a single argument.
306306

0 commit comments

Comments
 (0)