Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
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: 2 additions & 0 deletions src/windows_toasts/toast_document.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ def AddAction(self, action: ToastButton) -> None:
self.SetAttribute(actionNode, "hint-tooltip", action.tooltip)
if action.colour is not ToastButtonColour.Default:
self.SetAttribute(actionNode, "hint-buttonStyle", action.colour.value)
if action.multistep:
self.SetAttribute(actionNode, "afterActivationBehavior", "pendingUpdate")

actionsNode.append_child(actionNode)

Expand Down
2 changes: 2 additions & 0 deletions src/windows_toasts/wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,3 +224,5 @@ class ToastButton:
"""The tooltip for a button, if the button has an empty content string"""
colour: ToastButtonColour = ToastButtonColour.Default
""":class:`ToastButtonColour` for the button"""
multistep: bool = False
"""Whether to consider the button as part of a multistep action, therefore making the button "load" when pressed"""
27 changes: 27 additions & 0 deletions tests/test_toasts.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,3 +292,30 @@ def test_expiration_toasts():
expirationTime = datetime.now() + timedelta(minutes=1)
newToast = ToastText1(body="Hello, World!", group="Test Toasts", expiration_time=expirationTime)
WindowsToaster("Python").show_toast(newToast)


def test_multistep_toast():
from src.windows_toasts import ToastActivatedEventArgs, ToastButton, ToastText2

OUR_CHOICE = "scissors"

newToast = ToastText2(body="Select your weapon")

newToast.AddAction(ToastButton("Rock", "rock", multistep=True))
newToast.AddAction(ToastButton("Paper", "paper", multistep=True))
newToast.AddAction(ToastButton("Scissors", "scissors", multistep=True))

def nextStep(activatedEventArgs: ToastActivatedEventArgs):
newToast.actions = []
newToast.SetHeadline(f"I chose {OUR_CHOICE}")
if activatedEventArgs.arguments == "rock":
newToast.SetBody("Darn! I lost!")
elif activatedEventArgs.arguments == "paper":
newToast.SetBody("Yay! I win!")
elif activatedEventArgs.arguments == "scissors":
newToast.SetBody("Geez, we tied")

InteractableWindowsToaster("Python").show_toast(newToast)

newToast.on_activated = nextStep
InteractableWindowsToaster("Python").show_toast(newToast)