### Send a Basic Toast Notification Source: https://windows-toasts.readthedocs.io/en/latest/getting_started A quickstart example demonstrating how to create and display a simple 'Hello, World!' toast notification using the Windows-Toasts library. ```python # We import WindowsToaster and a toast format we want from windows_toasts import WindowsToaster, Toast # Prepare the toaster for bread (or your notification) tool_app_id = 'Python' tool_version = '1.0' toaster = WindowsToaster(tool_app_id, tool_version) # Initialise the toast newToast = Toast() # Set the body of the notification newToast.text_fields = ['Hello, World!'] # And display it! tool_id = 'my_toast' tool_expiration_time = '2024-12-31T23:59:59Z' tool_launch_args = '' tool_scenario = 'reminder' tool_group = '' newToast.launch = tool_launch_args newToast.scenario = tool_scenario newToast.group = tool_group tool_duration = 'long' newToast.duration = tool_duration tool_priority = 'normal' newToast.priority = tool_priority newToast.audio = 'Default' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.scenario = 'reminder' newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' tool_activation_type = 'protocol' tool_arguments = '' tool_display_text = '' tool_scenario = 'reminder' tool_id = 'my_toast' tool_expiration_time = '2024-12-31T23:59:59Z' tool_launch_args = '' tool_group = '' newToast.scenario = tool_scenario newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.launch = tool_launch_args newToast.scenario = tool_scenario newToast.group = tool_group tool_duration = 'long' newToast.duration = tool_duration tool_priority = 'normal' newToast.priority = tool_priority newToast.audio = 'Default' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.scenario = 'reminder' newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' tool_activation_type = 'protocol' tool_arguments = '' tool_display_text = '' tool_scenario = 'reminder' tool_id = 'my_toast' tool_expiration_time = '2024-12-31T23:59:59Z' tool_launch_args = '' tool_group = '' newToast.scenario = tool_scenario newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.launch = tool_launch_args newToast.scenario = tool_scenario newToast.group = tool_group tool_duration = 'long' newToast.duration = tool_duration tool_priority = 'normal' newToast.priority = tool_priority newToast.audio = 'Default' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.scenario = 'reminder' newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' tool_activation_type = 'protocol' tool_arguments = '' tool_display_text = '' tool_scenario = 'reminder' tool_id = 'my_toast' tool_expiration_time = '2024-12-31T23:59:59Z' tool_launch_args = '' tool_group = '' newToast.scenario = tool_scenario newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.launch = tool_launch_args newToast.scenario = tool_scenario newToast.group = tool_group tool_duration = 'long' newToast.duration = tool_duration tool_priority = 'normal' newToast.priority = tool_priority newToast.audio = 'Default' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.scenario = 'reminder' newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' tool_activation_type = 'protocol' tool_arguments = '' tool_display_text = '' tool_scenario = 'reminder' tool_id = 'my_toast' tool_expiration_time = '2024-12-31T23:59:59Z' tool_launch_args = '' tool_group = '' newToast.scenario = tool_scenario newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.launch = tool_launch_args newToast.scenario = tool_scenario newToast.group = tool_group tool_duration = 'long' newToast.duration = tool_duration tool_priority = 'normal' newToast.priority = tool_priority newToast.audio = 'Default' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.scenario = 'reminder' newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' tool_activation_type = 'protocol' tool_arguments = '' tool_display_text = '' tool_scenario = 'reminder' tool_id = 'my_toast' tool_expiration_time = '2024-12-31T23:59:59Z' tool_launch_args = '' tool_group = '' newToast.scenario = tool_scenario newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.launch = tool_launch_args newToast.scenario = tool_scenario newToast.group = tool_group tool_duration = 'long' newToast.duration = tool_duration tool_priority = 'normal' newToast.priority = tool_priority newToast.audio = 'Default' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.scenario = 'reminder' newToast.audio = 'Default' newToast.duration = 'long' newToast.priority = 'normal' newToast.suppress_popup = False newToast.header = ('New App', 'new_app_id', 'New App') newToast.image = 'image.png' newToast.app_logo = 'app_logo.png' newToast.show_toast(newToast) ``` -------------------------------- ### Install Windows-Toasts from Source Source: https://windows-toasts.readthedocs.io/en/latest/_sources/getting_started.rst Installs the Windows-Toasts library directly from its GitHub repository. This involves cloning the repository and then installing it using pip. ```shell git clone https://github.com/DatGuy1/Windows-Toasts.git ``` ```shell cd Windows-Toasts python -m pip install . ``` -------------------------------- ### Display a Toast Notification in Python Source: https://windows-toasts.readthedocs.io/en/latest/_sources/getting_started.rst A quickstart example demonstrating how to display a basic 'Hello, World!' toast notification using the Windows-Toasts library. It involves importing necessary classes, initializing the toaster and toast, setting text fields, and showing the toast. ```python # We import WindowsToaster and a toast format we want from windows_toasts import WindowsToaster, Toast # Prepare the toaster for bread (or your notification) ttoaster = WindowsToaster('Python') # Initialise the toast newToast = Toast() # Set the body of the notification newToast.text_fields = ['Hello, World!'] # And display it! ttoaster.show_toast(newToast) ``` -------------------------------- ### Install Windows-Toasts from Source Source: https://windows-toasts.readthedocs.io/en/latest/getting_started Installs the Windows-Toasts library after cloning the repository. This method allows for development or direct integration into your projects. ```bash cd Windows-Toasts $ python -m pip install . ``` -------------------------------- ### Install Windows-Toasts via Pip Source: https://windows-toasts.readthedocs.io/en/latest/_sources/getting_started.rst Installs the latest stable version of the Windows-Toasts library using pip. Requires Python 3.9+ and Windows 10/11. ```shell python -m pip install windows-toasts ``` -------------------------------- ### Setup Toast with Actions and Inputs Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toasters Configures the toast content, including setting text fields, attributes, inputs, actions, and progress bars. This method is essential for customizing the appearance and interactivity of the toast, especially when using a custom AUMID. ```python def _setup_toast(self, toast, dynamic): toastContent = super()._setup_toast(toast, dynamic) for i, fieldContent in enumerate(toast.text_fields): if fieldContent is None: continue if dynamic: toastContent.SetTextField(i) else: toastContent.SetTextFieldStatic(i, fieldContent) toastContent.SetAttribute(toastContent.bindingNode, "template", "ToastGeneric") toastNode = toastContent.GetElementByTagName("toast") 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 and toast.attribution_text is None: toastContent.SetAttributionText(self.applicationText) for toastInput in toast.inputs: toastContent.AddInput(toastInput) for customAction in toast.actions: toastContent.AddAction(customAction) if toast.progress_bar is not None: if dynamic: toastContent.AddProgressBar() else: toastContent.AddStaticProgressBar(toast.progress_bar) return toastContent ``` -------------------------------- ### Clone Windows-Toasts Repository Source: https://windows-toasts.readthedocs.io/en/latest/getting_started Clones the Windows-Toasts GitHub repository to install from source. This allows for direct use of the code or installation into your Python environment. ```bash $ git clone https://github.com/DatGuy1/Windows-Toasts.git ``` -------------------------------- ### Setup Toast Document for Sending (Python) Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toasters Prepares a ToastDocument from a Toast object, converting its content into an XML format suitable for display. It configures various aspects of the toast, including images, duration, timestamps, audio, attribution text, scenario, and launch actions. This method is typically used internally before showing a toast. ```python def _setup_toast(self, toast: Toast, dynamic: bool) -> ToastDocument: """ Setup toast to send. Should generally be used internally :return: XML built from the toast """ # Should this be done in ToastDocument? toastContent = ToastDocument(toast) for image in toast.images: toastContent.AddImage(image) if toast.duration != ToastDuration.Default: toastContent.SetDuration(toast.duration) if toast.timestamp is not None: toastContent.SetCustomTimestamp(toast.timestamp) 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) if toast.launch_action is not None: toastContent.SetAttribute(toastContent.GetElementByTagName("toast"), "launch", toast.launch_action) toastContent.SetAttribute(toastContent.GetElementByTagName("toast"), "activationType", "protocol") else: toastContent.SetAttribute(toastContent.GetElementByTagName("toast"), "launch", toast.tag) return toastContent ``` -------------------------------- ### Initialize InteractableWindowsToaster Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toasters Initializes the InteractableWindowsToaster with provided application text and an optional notifier AUMID. If no AUMID is provided, it defaults to the Command Prompt's AUMID. This setup is crucial for enabling interactive toast features. ```python def __init__(self, applicationText: str, notifierAUMID: Optional[str] = None): super().__init__(applicationText) if notifierAUMID is None: self.defaultAUMID = True self.notifierAUMID = "{1AC14E77-02E7-4E5D-B744-2EB1AE5198B7}\\cmd.exe" else: self.defaultAUMID = False self.notifierAUMID = notifierAUMID self.toastNotifier = ToastNotificationManager.create_toast_notifier_with_id(self.notifierAUMID) ``` -------------------------------- ### Play Out-of-the-Box Audio in Toast (Python) Source: https://windows-toasts.readthedocs.io/en/latest/advanced_usage This example demonstrates how to play pre-defined Windows audio sounds in a toast notification using `windows_toasts`. It utilizes `ToastAudio` with `AudioSource` and supports looping the audio until the notification is dismissed or expires. ```python from windows_toasts import AudioSource, Toast, ToastAudio, WindowsToaster toster = WindowsToaster('Windows-Toasts') newToast = Toast() newToast.text_fields = ['Ding ding! Ding ding! Ding ding!'] newToast.audio = ToastAudio(AudioSource.IM, looping=True) toster.show_toast(newToast) ``` -------------------------------- ### View Installed AUMIDs - PowerShell Source: https://windows-toasts.readthedocs.io/en/latest/_sources/custom_aumid.rst This PowerShell command retrieves a list of all installed applications for the current user, along with their corresponding Application User Model IDs (AUMIDs). This is useful for identifying existing AUMIDs that might be leveraged or for troubleshooting. ```powershell Get-StartApps ``` -------------------------------- ### Schedule Toast Notification with Python Source: https://windows-toasts.readthedocs.io/en/latest/advanced_usage This code example shows how to schedule a toast notification to appear at a specific future time. It utilizes the `datetime` and `timedelta` objects from Python's standard library along with the `WindowsToaster` and `Toast` classes from `windows-toasts`. The toast is configured with text and a display time set to 10 seconds from the current time. ```python from datetime import datetime, timedelta from windows_toasts import WindowsToaster, Toast ttoaster = WindowsToaster('Python') # Schedule toast to display 10 seconds from now displayTime = datetime.now() + timedelta(seconds=10) newToast = Toast([f'This will pop up at {displayTime}']) ttoaster.schedule_toast(newToast, displayTime) ``` -------------------------------- ### Register Custom AUMID Script - Python Source: https://windows-toasts.readthedocs.io/en/latest/_sources/custom_aumid.rst This script allows for the installation of custom Application User Model IDs (AUMIDs). It registers the AUMID in the Windows Registry, enabling custom titles, icons, and activation listening for notifications. The script accepts arguments that can be viewed using the --help flag. ```python register_hkey_aumid.py ``` -------------------------------- ### Combine Buttons and Input Fields in Toast (Python) Source: https://windows-toasts.readthedocs.io/en/latest/_sources/interactable.rst Illustrates how to create a toast notification that combines text input fields and action buttons. This example sets a text field for the user's name, adds a 'Submit' button, and configures the `on_activated` callback to print the user's input when the submit button is pressed. ```python from windows_toasts import InteractableWindowsToaster, Toast, ToastInputTextBox, ToastButton interactableToaster = InteractableWindowsToaster('Questionnaire') newToast = Toast() newToast.text_fields = ['What\'s your name?'] newToast.AddInput(ToastInputTextBox('name', 'Your name', 'Barack Obama')) newToast.AddAction(ToastButton('Submit', 'submit')) newToast.on_activated = lambda activatedEventArgs: print(activatedEventArgs.input) interactableToaster.show_toast(newToast) ``` -------------------------------- ### Launch Protocols with Toast Buttons (Python) Source: https://windows-toasts.readthedocs.io/en/latest/_sources/migration.rst Shows how to create toasts with buttons that launch specific protocols, such as websites or applications. This feature allows for direct user interaction with external applications or URLs from a toast notification. ```python from windows_toasts import InteractableWindowsToaster, Toast, ToastButton protocol_toast = Toast(['Click the toast to launch google.com', 'or, alternatively'], launch_action='https://google.com') bing_button = ToastButton('Launch Bing', launch='https://bing.com') baidu_button = ToastButton('Launch Baidu', launch='https://baidu.com') protocol_toast.AddAction(bing_button) protocol_toast.AddAction(baidu_button) InteractableWindowsToaster('Browser Launcher').show_toast(protocol_toast) ``` -------------------------------- ### Toast Configuration: v0.x vs v1.0.0 (Python) Source: https://windows-toasts.readthedocs.io/en/latest/migration Demonstrates the differences in configuring toasts between version 0.x and 1.0.0 of the Windows-Toasts library. It shows how to initialize a toast, set text fields, and set duration, highlighting the removal of SetX methods in favor of direct attribute modification. ```python from windows_toasts import WindowsToaster, ToastDuration from windows_toasts import ToastText2 tost = ToastText2() tost.SetHeadline('Hello,') tost.SetBody('World!') tost.SetDuration(ToastDuration.Short) WindowsToaster('Python').show_toast(toast) ``` ```python from windows_toasts import WindowsToaster, ToastDuration from windows_toasts import Toast tost = Toast() tost.text_fields = ['Hello', 'World!'] # Or, directly, toast = Toast(['Hello', 'World!']) tost.duration = ToastDuration.short WindowsToaster('Python').show_toast(toast) ``` ```diff from windows_toasts import WindowsToaster, ToastDuration - from windows_toasts import ToastText2 + from windows_toasts import Toast - toast = ToastText2() + toast = Toast() - toast.SetHeadline('Hello,') - toast.SetBody('World!') + toast.text_fields = ['Hello', 'World!'] - toast.SetDuration(ToastDuration.Short) + toast.duration = ToastDuration.short WindowsToaster('Python').show_toast(toast) ``` -------------------------------- ### Simplify Toast Initialization and Configuration (Python) Source: https://windows-toasts.readthedocs.io/en/latest/_sources/migration.rst Demonstrates the updated method for initializing and configuring Toast objects in Windows-Toasts v1.0.0. It replaces the older ToastText2 class and SetX methods with direct attribute modification and a simplified Toast constructor. ```python from windows_toasts import WindowsToaster, ToastDuration from windows_toasts import Toast trust = Toast() trust.text_fields = ['Hello', 'World!'] # Or, directly, toast = Toast(['Hello', 'World!']) trust.duration = ToastDuration.short WindowsToaster('Python').show_toast(toast) ``` ```diff from windows_toasts import WindowsToaster, ToastDuration - from windows_toasts import ToastText2 + from windows_toasts import Toast - toast = ToastText2() + toast = Toast() - toast.SetHeadline('Hello,') - toast.SetBody('World!') + toast.text_fields = ['Hello', 'World!'] - toast.SetDuration(ToastDuration.Short) + toast.duration = ToastDuration.short WindowsToaster('Python').show_toast(toast) ``` -------------------------------- ### Get XML Element Attribute Value in Python Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toast_document Retrieves the value of a specified attribute from an XML node. This is a static helper method within the ToastDocument class. It takes an IXmlType node and an attribute name as input, returning the attribute's value as a string. ```python @staticmethod def GetAttributeValue(nodeAttribute: IXmlType, attributeName: str) -> str: """ Helper function that returns an attribute's value :param nodeAttribute: Node that has the attribute :type nodeAttribute: IXmlType :param attributeName: Name of the attribute, e.g. "duration" :type attributeName: str :return: The value of the attribute :rtype: str """ return nodeAttribute.attributes.get_named_item(attributeName).inner_text ``` -------------------------------- ### Get XML Element by Tag Name in Python Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toast_document Finds and returns the first XML element that matches the provided tag name. This is a helper method for navigating the XML document structure within ToastDocument. It takes a tag name string and returns an IXmlType object. ```python def GetElementByTagName(self, tagName: str) -> IXmlType: """ Helper function to get the first element by its tag name :param tagName: The name of the tag for the element :type tagName: str :rtype: IXmlType """ # Is this way faster? Or is self.xmlDocument.select_single_node(f"/{tagName}") ? return self.xmlDocument.get_elements_by_tag_name(tagName).item(0) ``` -------------------------------- ### Initialize WindowsToaster (Python) Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toasters Initializes the basic WindowsToaster. This class is used for displaying simple toasts without actions or inputs. It requires the application's display text and creates a toast notifier instance. ```python class WindowsToaster(BaseWindowsToaster): """ Basic toaster, used to display toasts without actions and/or inputs. If you need to use them, see :class:`InteractableWindowsToaster` :param applicationText: Text to display the application as """ __InteractableWarningMessage = ( "{0} are not supported in WindowsToaster. If you'd like to use {0}, " "instantiate a InteractableWindowsToaster class instead" ) def __init__(self, applicationText: str): super().__init__(applicationText) self.notifierAUMID = None # .create_toast_notifier() fails with "Element not found" self.toastNotifier = ToastNotificationManager.create_toast_notifier_with_id(applicationText) ``` -------------------------------- ### Create and Initialize ToastDocument in Python Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toast_document Initializes the ToastDocument by creating an XML document and setting up the basic toast structure. It adds text and image elements as needed based on the provided Toast object. Dependencies include the Toast and wrapper classes from the windows_toasts library. ```python from datetime import datetime from typing import Union from winrt.windows.data.xml.dom import IXmlNode, XmlDocument, XmlElement from .toast import Toast from .toast_audio import ToastAudio from .wrappers import ( ToastButton, ToastButtonColour, ToastDisplayImage, ToastDuration, ToastInputSelectionBox, ToastInputTextBox, ToastProgressBar, ToastScenario, ToastSystemButton, ToastSystemButtonAction, ) IXmlType = Union[IXmlNode, XmlElement] class ToastDocument: """ The XmlDocument wrapper for toasts, which applies all the attributes configured in :class:`~windows_toasts.toast.Toast` """ xmlDocument: XmlDocument bindingNode: IXmlType """Binding node, as to avoid having to find it every time""" _inputFields: int """Tracker of number of input fields""" def __init__(self, toast: Toast) -> None: self.xmlDocument = XmlDocument() self.xmlDocument.load_xml("") self.bindingNode = self.GetElementByTagName("binding") # Unclear whether this leads to issues regarding spacing for i in range(len(toast.text_fields)): textElement = self.xmlDocument.create_element("text") # Needed for WindowsToaster self.SetAttribute(textElement, "id", str(i + 1)) self.bindingNode.append_child(textElement) # Not sure if this is the best way to do this along with the clone bit in AddImage() if len(toast.images) > 0: imageElement = self.xmlDocument.create_element("image") self.SetAttribute(imageElement, "src", "") # Needed for WindowsToaster self.SetAttribute(imageElement, "id", "1") self.bindingNode.append_child(imageElement) self._inputFields = 0 ``` -------------------------------- ### Get Application User Model ID (Python) Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toasters Provides the Application User Model ID (AUMID) for the toast notifier. It returns the custom notifierAUMID if set, otherwise defaults to the applicationText. This is crucial for correctly identifying the application within the Windows notification system. ```python @property def _AUMID(self) -> str: return self.notifierAUMID or self.applicationText ``` -------------------------------- ### Remove Toast Notification with Python Source: https://windows-toasts.readthedocs.io/en/latest/advanced_usage This example demonstrates how to programmatically remove a toast notification using the `windows-toasts` library. The `remove_toast` method is called on the `WindowsToaster` instance. A common use case is to automatically remove a toast when it is dismissed to the action center, achieved by assigning a callback to `on_dismissed`. ```python from windows_toasts import WindowsToaster, Toast ttoaster = WindowsToaster("Python") newToast = Toast(["Disappearing act"]) # Remove the toast when it is dismissed newToast.on_dismissed = lambda _: toaster.remove_toast(newToast) ttoaster.show_toast(newToast) ``` -------------------------------- ### Toast Activated Event Arguments Source: https://windows-toasts.readthedocs.io/en/latest/user/wrappers Provides information about a toast activation event, including arguments and user inputs. ```APIDOC ## ToastActivatedEventArgs ### Description Represents the arguments provided when a toast notification is activated by the user. This includes any custom arguments passed with the toast and any input provided by the user. ### Properties #### `arguments` - **string** - Readonly - The arguments associated with the toast activation. #### `inputs` - **Dictionary** - Readonly - A dictionary containing user inputs from the toast. ### Methods #### `fromWinRt()` - **ToastActivatedEventArgs** - Static method to create a `ToastActivatedEventArgs` object from a WinRT activation event. ### Example ```json { "arguments": "actionId=123", "inputs": { "textBoxId": "User response text" } } ``` ``` -------------------------------- ### Toast Classes Source: https://windows-toasts.readthedocs.io/en/latest/genindex Documentation for core toast-related classes. ```APIDOC ## Toast Class ### Description Represents a toast notification object. ### Class `windows_toasts.toast.Toast` ### Attributes - **scenario** (str) - The scenario of the toast. - **text_fields** (list) - A list of text fields in the toast. - **timestamp** (datetime) - The timestamp of the toast. - **updates** (bool) - Indicates if the toast can be updated. - **suppress_popup** (bool) - Whether to suppress the popup notification. ## ToastActivatedEventArgs Class ### Description Provides arguments for when a toast is activated. ### Class `windows_toasts.events.ToastActivatedEventArgs` ### Attributes Details not specified in the provided text. ## ToastAudio Class ### Description Represents the audio settings for a toast notification. ### Class `windows_toasts.toast_audio.ToastAudio` ### Attributes - **silent** (bool) - Whether the audio is silent. - **sound** (str) - The name of the sound file. - **sound_value** (str) - The value of the sound property. ## ToastButton Class ### Description Represents an action button on a toast notification. ### Class `windows_toasts.wrappers.ToastButton` ### Attributes - **tooltip** (str) - The tooltip text for the button. ## ToastDisplayImage Class ### Description Represents an image to be displayed within a toast notification. ### Class `windows_toasts.wrappers.ToastDisplayImage` ### Attributes Details not specified in the provided text. ## ToastDocument Class ### Description Represents the XML document structure of a toast notification. ### Class `windows_toasts.toast_document.ToastDocument` ### Attributes - **xmlDocument** (xml.etree.ElementTree.Element) - The underlying XML element. ## ToastImage Class ### Description Represents an image associated with a toast notification. ### Class `windows_toasts.wrappers.ToastImage` ### Attributes Details not specified in the provided text. ## ToastInput Class ### Description Represents an input element within a toast notification. ### Class `windows_toasts.toast.ToastInput` ### Attributes Details not specified in the provided text. ## ToastInputSelectionBox Class ### Description Represents a selection box input on a toast notification. ### Class `windows_toasts.wrappers.ToastInputSelectionBox` ### Attributes - **selections** (list) - Available selection options. ## ToastInputTextBox Class ### Description Represents a text box input on a toast notification. ### Class `windows_toasts.wrappers.ToastInputTextBox` ### Attributes Details not specified in the provided text. ## ToastProgressBar Class ### Description Represents a progress bar on a toast notification. ### Class `windows_toasts.wrappers.ToastProgressBar` ### Attributes - **status** (str) - The status of the progress bar. ## ToastSelection Class ### Description Represents a selection option, likely within a `ToastInputSelectionBox`. ### Class `windows_toasts.wrappers.ToastSelection` ### Attributes - **selection_id** (str) - The unique identifier for the selection. ## ToastSystemButton Class ### Description Represents a system-defined button action on a toast notification. ### Class `windows_toasts.wrappers.ToastSystemButton` ### Attributes - **tooltip** (str) - The tooltip text for the button. ## WindowsToaster Class ### Description A concrete implementation of `BaseWindowsToaster` for creating and managing toast notifications. ### Class `windows_toasts.toasters.WindowsToaster` ### Attributes - **toastNotifier** (object) - The underlying toast notifier object. ## ToastDuration Enum ### Description Defines the possible display durations for a toast notification. ### Enum `windows_toasts.wrappers.ToastDuration` ### Members - **Short** - **Long** ## AudioSource Enum ### Description Defines standard audio sources for toast notifications. ### Enum `windows_toasts.toast_audio.AudioSource` ### Members - **SMS** ## Exceptions ### ToastNotFoundError ### Description An exception raised when a requested toast cannot be found. ### UnsupportedOSVersionException ### Description An exception raised when the operating system version is not supported. ``` -------------------------------- ### Open Website on Toast Click (Python) Source: https://windows-toasts.readthedocs.io/en/latest/advanced_usage Shows how to make a toast notification launch a specific website when clicked using the `windows_toasts` library. This is achieved by setting the `launch_action` attribute of the `Toast` object to the desired URL. ```python from windows_toasts import Toast, WindowsToaster toster = WindowsToaster('Rick Astley') newToast = Toast() newToast.text_fields = ['Hello there! You just won a thousand dollars! Click me to claim it!'] # Inline lambda function. This could also be an actual function newToast.launch_action = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ' # Send it toster.show_toast(newToast) ``` -------------------------------- ### Exceptions Module Source: https://windows-toasts.readthedocs.io/en/latest/_sources/user/exceptions.rst This section details the exceptions available in the windows_toasts library. ```APIDOC ## Exceptions Module ### Description This module contains custom exceptions raised by the `windows_toasts` library. ### Classes #### InvalidImageException - **Description**: Raised when an invalid image format is provided for a toast notification. - **Inheritance**: `Exception` #### ToastNotFoundError - **Description**: Raised when a toast notification that is expected to exist cannot be found. - **Inheritance**: `Exception` ``` -------------------------------- ### Create ToastDisplayImage from Path Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/wrappers A factory method to create a ToastDisplayImage object directly from an image path, simplifying instantiation by internally creating the ToastImage object. ```python from dataclasses import dataclass from os import PathLike from typing import Optional, Union from .wrappers import ToastImage, ToastImagePosition @dataclass class ToastDisplayImage: """ Define an image that will be displayed as the icon of the toast """ image: ToastImage """An image file""" altText: Optional[str] = None """A description of the image, for users of assistive technologies""" position: ToastImagePosition = ToastImagePosition.Inline """ Whether to set the image as 'hero' and at the top, or as the 'logo'. Only works on :class:`~windows_toasts.toasters.InteractableWindowsToaster` """ circleCrop: bool = False """ If the image is not positioned as 'hero', whether to crop the image as a circle, or leave it as is """ @classmethod def fromPath( cls, imagePath: Union[str, PathLike], altText: Optional[str] = None, position: ToastImagePosition = ToastImagePosition.Inline, circleCrop: bool = False, ) -> ToastDisplayImage: """ Create a :class:`ToastDisplayImage` object from path without having to create :class:`ToastImage` """ image = ToastImage(imagePath) return cls(image, altText, position, circleCrop) ``` -------------------------------- ### Create Interactable Toast with Buttons - Python Source: https://windows-toasts.readthedocs.io/en/latest/interactable Demonstrates creating an interactable toast notification with two action buttons using the `windows_toasts` library. It shows how to initialize the toaster, create a toast, add buttons with associated arguments, and display the toast. A callback function is also defined to handle the toast activation event and print the arguments. ```python from windows_toasts import InteractableWindowsToaster, Toast, ToastActivatedEventArgs, ToastButton interactableToaster = InteractableWindowsToaster('Questionnaire') newToast = Toast(['How are you?']) # Add two actions (buttons) newToast.AddAction(ToastButton('Decent', 'response=decent')) newToast.AddAction(ToastButton('Not so good', 'response=bad')) # Display it like usual interactableToaster.show_toast(newToast) def activated_callback(activatedEventArgs: ToastActivatedEventArgs): print(activatedEventArgs.arguments) # response=decent/response=bad newToast.on_activated = activated_callback ``` -------------------------------- ### BaseWindowsToaster Class Initialization (Python) Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toasters Initializes the BaseWindowsToaster wrapper, which simplifies interaction with WinRT's ToastNotificationManager. It takes an applicationText parameter to identify the application displaying the toast. This constructor sets up the necessary properties for managing toast notifications. ```python class BaseWindowsToaster: """ Wrapper to simplify WinRT's ToastNotificationManager :param applicationText: Text to display the application as """ applicationText: str notifierAUMID: Optional[str] toastNotifier: ToastNotifier def __init__(self, applicationText: str): self.applicationText = applicationText ``` -------------------------------- ### Create ToastImage from Path Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/wrappers Initializes a ToastImage object from a given file path. It validates that the image exists and handles local paths, raising an InvalidImageException for unsupported online image URIs. ```python from dataclasses import dataclass from os import PathLike from pathlib import Path from typing import Union from urllib.parse import urlparse import urllib from .exceptions import InvalidImageException @dataclass(init=False) class ToastImage: """ Image that can be displayed in various toast elements """ path: str """The URI of the image source""" def __init__(self, imagePath: Union[str, PathLike]): """ Initialise an :class:`ToastImage` class to use in certain classes. Online images are supported only in packaged apps that have the internet capability in their manifest. Unpackaged apps don't support http images; you must download the image to your local app data, and reference it locally. :param imagePath: The path to an image file :type imagePath: Union[str, PathLike] :raises: InvalidImageException: If the path to an online image is supplied """ if isinstance(imagePath, str) and urlparse(imagePath).scheme in ("http", "https"): raise InvalidImageException("Online images are not supported") elif not isinstance(imagePath, Path): imagePath = Path(imagePath) if not imagePath.exists(): raise InvalidImageException(f"Image with path '{imagePath}' could not be found") self.path = urllib.parse.unquote(imagePath.absolute().as_uri()) ``` -------------------------------- ### Scenario Setting API Source: https://windows-toasts.readthedocs.io/en/latest/_modules/windows_toasts/toast_document Sets the scenario for the toast notification, marking it as important if specified. ```APIDOC ## PUT /websites/windows-toasts/scenario ### Description Sets whether the notification should be marked as important. ### Method PUT ### Endpoint /websites/windows-toasts/scenario ### Parameters #### Request Body - **scenario** (string) - Required - The scenario to mark the toast as (e.g., 'important', 'default'). ### Request Example ```json { "scenario": "important" } ``` ### Response #### Success Response (200) - **status** (string) - Indicates successful application of the scenario. #### Response Example ```json { "status": "Scenario applied successfully." } ``` ``` -------------------------------- ### Windows Toasts API Reference Source: https://windows-toasts.readthedocs.io/en/latest/genindex Reference for attributes, methods, and classes within the Windows Toasts library. ```APIDOC ## Default Attributes and Wrappers ### Description Details on default attributes and wrapper classes for toast notifications. ### Method N/A ### Endpoint N/A ### Parameters N/A ### Request Example N/A ### Response N/A ## Attribute Details ### Description Provides details on specific attributes available for toast notifications and their related classes. ### Method N/A ### Endpoint N/A ### Parameters - **windows_toasts.toast_audio.AudioSource attribute**: Represents audio source options. - **windows_toasts.wrappers.ToastButtonColour attribute**: Defines button color options. - **windows_toasts.wrappers.ToastDuration attribute**: Specifies toast duration. - **windows_toasts.wrappers.ToastScenario attribute**: Sets the scenario for the toast. - **windows_toasts.wrappers.ToastInputSelectionBox attribute**: Defines an input selection box. - **windows_toasts.wrappers.ToastSystemButtonAction attribute**: Represents a system button action. - **windows_toasts.toast.Toast attribute**: Core toast notification attribute. - **windows_toasts.events.ToastActivatedEventArgs attribute**: Arguments for toast activation events. - **windows_toasts.wrappers.ToastDisplayImage attribute**: Manages display images for toasts. - **windows_toasts.wrappers.ToastSystemButton attribute**: Represents a system button. - **windows_toasts.toast.Toast attribute**: Core toast notification attribute. - **windows_toasts.wrappers.ToastButton attribute**: Represents a button in the toast. - **windows_toasts.wrappers.ToastInputTextBox attribute**: Defines a text input box. - **windows_toasts.wrappers.ToastProgressBar attribute**: Represents a progress bar. - **windows_toasts.toast_audio.ToastAudio attribute**: Audio settings for toast notifications. ### Request Example N/A ### Response N/A ## Class Methods ### Description Details on class methods available for specific classes within the library. ### Method N/A ### Endpoint N/A ### Parameters - **windows_toasts.wrappers.ToastDisplayImage class method `fromPath()`**: Creates a ToastDisplayImage from a file path. - **windows_toasts.events.ToastActivatedEventArgs class method `fromWinRt()`**: Creates ToastActivatedEventArgs from WinRT event data. - **windows_toasts.toast_document.ToastDocument static method `GetAttributeValue()`**: Retrieves an attribute value from a toast document. - **windows_toasts.toast_document.ToastDocument method `GetElementByTagName()`**: Retrieves an element by its tag name from a toast document. ### Request Example N/A ### Response N/A ## Static Methods and Properties ### Description Details on static methods and properties, including those related to toast document interaction and toast grouping. ### Method N/A ### Endpoint N/A ### Parameters - **windows_toasts.toast_document.ToastDocument static method `GetAttributeValue()`**: Retrieves an attribute value. - **windows_toasts.toast_document.ToastDocument method `GetElementByTagName()`**: Gets an element by tag name. - **windows_toasts.toast.Toast attribute `expiration_time`**: The expiration time of the toast. - **windows_toasts.wrappers.ToastButtonColour attribute `Green`**: Represents the color green for buttons. - **windows_toasts.toast.Toast attribute `group`**: The group the toast belongs to. - **windows_toasts.wrappers.ToastImagePosition attribute `Hero`**: Positions an image in the hero section. - **windows_toasts.toast_audio.AudioSource attribute `IM`**: Represents the IM audio source. - **windows_toasts.wrappers.ToastButton attribute `image`**: The image associated with a button. - **windows_toasts.toast.Toast attribute `images`**: Collection of images for the toast. - **windows_toasts.wrappers.ToastScenario attribute `Important`**: Sets the toast scenario to important. - **windows_toasts.wrappers.ToastScenario attribute `IncomingCall`**: Sets the toast scenario to incoming call. - **windows_toasts.wrappers.ToastButton attribute `inContextMenu`**: Indicates if the button is in the context menu. - **windows_toasts.wrappers.ToastImagePosition attribute `Inline`**: Positions an image inline. - **windows_toasts.events.ToastActivatedEventArgs attribute `inputs`**: Input data from toast activation. - **windows_toasts.toast.Toast attribute `inputs`**: Input data for the toast. - **windows_toasts.toasters.InteractableWindowsToaster class**: A class for interactable Windows Toasters. - **windows_toasts.InvalidImageException**: Exception for invalid image handling. - **windows_toasts.IXmlType (in module windows_toasts.toast_document)**: Interface for XML types. - **windows_toasts.wrappers.ToastButton attribute `launch`**: The launch action for a button. - **windows_toasts.toast.Toast property `launch_action`**: The launch action of the toast. - **windows_toasts.wrappers.ToastDuration attribute `Long`**: Specifies a long duration for the toast. - **windows_toasts.toast_audio.ToastAudio attribute `looping`**: Enables looping for toast audio. - **windows_toasts.toast_audio.AudioSource attribute `Mail`**: Represents the Mail audio source. - **windows_toasts.exceptions module**: Module containing exceptions. - **windows_toasts.toast module**: Module for toast classes. - **windows_toasts.toast_audio module**: Module for toast audio settings. - **windows_toasts.toast_document module**: Module for toast document handling. - **windows_toasts.toasters module**: Module for toaster classes. - **windows_toasts.wrappers module**: Module for wrapper classes. - **windows_toasts.toasters.BaseWindowsToaster attribute `notifierAUMID`**: The App User Model ID of the notifier. - **windows_toasts.toast.Toast attribute `on_activated`**: Callback for toast activation. - **windows_toasts.toast.Toast attribute `on_dismissed`**: Callback for toast dismissal. - **windows_toasts.toast.Toast attribute `on_failed`**: Callback for toast failure. - **windows_toasts.wrappers.ToastImage attribute `path`**: The file path of the toast image. - **windows_toasts.wrappers.ToastInputTextBox attribute `placeholder`**: Placeholder text for an input box. - **windows_toasts.wrappers.ToastDisplayImage attribute `position`**: The position of the display image. - **windows_toasts.wrappers.ToastProgressBar attribute `progress`**: The progress value for a progress bar. - **windows_toasts.toast.Toast attribute `progress_bar`**: The progress bar associated with the toast. - **windows_toasts.wrappers.ToastProgressBar attribute `progress_override`**: Overrides for the progress bar. - **windows_toasts.wrappers.ToastButtonColour attribute `Red`**: Represents the color red for buttons. - **windows_toasts.wrappers.ToastButton attribute `relatedInput`**: Related input for a button. - **windows_toasts.wrappers.ToastSystemButton attribute `relatedInput`**: Related input for a system button. - **windows_toasts.toast_audio.AudioSource attribute `Reminder`**: Represents the Reminder audio source. - **windows_toasts.wrappers.ToastScenario attribute `Reminder`**: Sets the toast scenario to reminder. - **windows_toasts.toasters.BaseWindowsToaster method `remove_toast()`**: Removes a specific toast. - **windows_toasts.toasters.BaseWindowsToaster method `remove_toast_group()`**: Removes a group of toasts. ### Request Example N/A ### Response N/A ```