Skip to content

Commit

Permalink
Merge pull request #140 from DatGuy1/feat/attribution
Browse files Browse the repository at this point in the history
feat: allow setting attribution text
  • Loading branch information
DatGuy1 authored May 19, 2024
2 parents 6322266 + 8c52e81 commit a9725e7
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
1.1.1 (2024-05-19)
==================
- Allow setting attribution text (#140)
- Added support for winrt v2.0.1 (#138)

1.1.0 (2024-02-13)
Expand Down
4 changes: 4 additions & 0 deletions src/windows_toasts/toast.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ class Toast:
"""A custom timestamp. If you don't provide one, Windows uses the time that your notification was sent"""
progress_bar: Optional[ToastProgressBar]
"""An adjustable progress bar for the toast"""
attribution_text: Optional[str]
"""Text displayed below any text elements, but above inline images"""
on_activated: Optional[Callable[[ToastActivatedEventArgs], None]]
"""Callable to execute when the toast is clicked if basic, or a button is clicked if interactable"""
on_dismissed: Optional[Callable[[ToastDismissedEventArgs], None]]
Expand Down Expand Up @@ -73,6 +75,7 @@ def __init__(
group: Optional[str] = None,
launch_action: Optional[str] = None,
progress_bar: Optional[ToastProgressBar] = None,
attribution_text: Optional[str] = None,
scenario: ToastScenario = ToastScenario.Default,
suppress_popup: bool = False,
timestamp: Optional[datetime.datetime] = None,
Expand All @@ -97,6 +100,7 @@ def __init__(
self.duration = duration
self.scenario = scenario
self.progress_bar = progress_bar
self.attribution_text = attribution_text
self.timestamp = timestamp
self.group = group
self.expiration_time = expiration_time
Expand Down
5 changes: 4 additions & 1 deletion src/windows_toasts/toasters.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,9 @@ def _setup_toast(self, toast: Toast, dynamic: bool) -> ToastDocument:
if toast.audio is not None:
toastContent.SetAudioAttributes(toast.audio)

if toast.attribution_text is not None:
toastContent.SetAttributionText(toast.attribution_text)

if toast.scenario != ToastScenario.Default:
toastContent.SetScenario(toast.scenario)

Expand Down Expand Up @@ -296,7 +299,7 @@ def _setup_toast(self, toast, dynamic):
toastContent.SetAttribute(toastNode, "useButtonStyle", "true")

# If we haven't set up our own AUMID, put our application text in the attribution field
if self.defaultAUMID:
if self.defaultAUMID and toast.attribution_text is None:
toastContent.SetAttributionText(self.applicationText)

for toastInput in toast.inputs:
Expand Down
12 changes: 3 additions & 9 deletions tests/test_toasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,16 +182,10 @@ def test_custom_duration_toast():


def test_attribution_text_toast():
from winrt.windows.ui.notifications import ToastNotification
newToast = Toast(["Incoming Message", "How are you?"])
newToast.attribution_text = "Via FakeMessenger"

newToast = Toast()
newToast.text_fields = ["Hello, World!", "Foobar"]

toaster = WindowsToaster("Python")
toastContent = toaster._setup_toast(newToast, False)
toastContent.SetAttributionText("Windows-Toasts")

toaster.toastNotifier.show(ToastNotification(toastContent.xmlDocument))
InteractableWindowsToaster("Python").show_toast(newToast)


def test_scenario_toast():
Expand Down

0 comments on commit a9725e7

Please sign in to comment.