diff --git a/src/windows_toasts/toast_document.py b/src/windows_toasts/toast_document.py index c824c39..2da31f4 100644 --- a/src/windows_toasts/toast_document.py +++ b/src/windows_toasts/toast_document.py @@ -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) diff --git a/src/windows_toasts/wrappers.py b/src/windows_toasts/wrappers.py index 259e310..b6e850b 100644 --- a/src/windows_toasts/wrappers.py +++ b/src/windows_toasts/wrappers.py @@ -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""" diff --git a/tests/test_toasts.py b/tests/test_toasts.py index ffd56cb..74061d5 100644 --- a/tests/test_toasts.py +++ b/tests/test_toasts.py @@ -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)