Skip to content

Commit

Permalink
refactor(toast)!: simplify toast configuration
Browse files Browse the repository at this point in the history
BREAKING CHANGE: All the SetX methods have been removed

- Toast.first_line/.second_line/.third_line reworked into a text_fields list
- Instead of a multitude of SetX methods, the attributes should now be modified directly
- Updated documentation to fit this
  • Loading branch information
DatGuy1 committed Aug 13, 2023
1 parent b0c5657 commit f955387
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 225 deletions.
26 changes: 12 additions & 14 deletions docs/advanced_usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Lets try out displaying an image
toaster = WindowsToaster('Windows-Toasts')
newToast = Toast()
newToast.SetFirstLine('<--- look, the Windows logo!')
newToast.text_fields = ['<--- look, the Windows logo!']
# str or PathLike
newToast.AddImage(ToastDisplayImage.fromPath('C:/Windows/System32/@WLOGO_96x96.png'))
Expand All @@ -27,19 +27,18 @@ Lets try out displaying an image
Open a website on click
-----------------------

We use :meth:`windows_toasts.toast.Toast.SetLaunchAction` to open a website when the notification is pressed.
We use :meth:`windows_toasts.toast.Toast.launch_action` to open a website when the notification is pressed.

.. code-block:: python
import webbrowser
from windows_toasts import Toast, WindowsToaster
toaster = WindowsToaster('Rick Astley')
newToast = Toast()
newToast.SetFirstLine('Hello there! You just won a thousand dollars! Click me to claim it!')
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.SetLaunchAction('https://www.youtube.com/watch?v=dQw4w9WgXcQ')
newToast.launch_action = 'https://www.youtube.com/watch?v=dQw4w9WgXcQ'
# Send it
toaster.show_toast(newToast)
Expand All @@ -57,8 +56,8 @@ There is a list of available, out-of-the-box audio sources at :class:`windows_to
toaster = WindowsToaster('Windows-Toasts')
newToast = Toast()
newToast.SetFirstLine('Ding ding! Ding ding! Ding ding!')
newToast.SetAudio(ToastAudio(AudioSource.IM, looping=True))
newToast.text_fields = ['Ding ding! Ding ding! Ding ding!']
newToast.audio = ToastAudio(AudioSource.IM, looping=True)
toaster.show_toast(newToast)
Expand Down Expand Up @@ -92,21 +91,20 @@ You can dynamically modify a toast's progress bar or text field
toaster = InteractableWindowsToaster('Python')
newToast = Toast()
newToast.SetFirstLine('Starting.')
newToast = Toast(['Starting.'])
progressBar = ToastProgressBar('Waiting...', progress=0)
newToast.SetProgressBar(progressBar)
newToast.progress_bar = progressBar
toaster.show_toast(newToast)
for i in range(1, 11):
time.sleep(1)
progressBar.progress += 0.1
newToast.SetFirstLine(f'Stage {i}')
newToast.text_fields = [f'Stage {i}']
toaster.update_toast(newToast)
newToast.SetFirstLine('Goodbye!')
newToast.text_fields = ['Goodbye!']
toaster.update_toast(newToast)
Expand All @@ -127,7 +125,7 @@ Since Windows 10, you could always replace a notification by sending a new toast
- Can completely change all content/layout of the toast
- Can only change progress bar and top-level text
* - **Reappearing as popup**
- Can reappear as a toast popup if you leave :meth:`~windows_toasts.toast.Toast.SetSuppressPopup` set to false (or set to true to silently send it to Action Center)
- Can reappear as a toast popup if you leave :meth:`~windows_toasts.toast.Toast.suppress_popup` set to false (or set to true to silently send it to Action Center)
- Won't reappear as a popup; the toast's data is silently updated within Action Center
* - **User dismissed**
- Regardless of whether user dismissed your previous notification, your replacement toast will always be sent
Expand All @@ -146,7 +144,7 @@ You can also schedule a toast to display at a specified time
toaster = WindowsToaster('Python')
displayTime = datetime.now() + timedelta(seconds=10)
newToast = Toast(first_line=f'This will pop up at {displayTime}')
newToast = Toast([f'This will pop up at {displayTime}'])
toaster.schedule_toast(newToast, displayTime)
Expand Down
2 changes: 1 addition & 1 deletion docs/getting_started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ To display a toast notification:
# Initialise the toast
newToast = Toast()
# Set the body of the notification
newToast.SetFirstLine('Hello, World!')
newToast.text_fields = ['Hello, World!']
# And display it!
toaster.show_toast(newToast)
7 changes: 3 additions & 4 deletions docs/interactable.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ We import :class:`~windows_toasts.toasters.InteractableWindowsToaster` instead o
from windows_toasts import InteractableWindowsToaster, ToastActivatedEventArgs, ToastButton, ToastText1
interactableToaster = InteractableWindowsToaster('Questionnaire')
newToast = ToastText1()
newToast = ToastText1(['How are you?'])
newToast.SetBody('How are you?')
# Add two actions (buttons)
newToast.AddAction(ToastButton('Decent', 'response=decent'))
newToast.AddAction(ToastButton('Not so good', 'response=bad'))
Expand Down Expand Up @@ -44,7 +43,7 @@ Windows-Toasts also supports using text fields and selection boxes.
from windows_toasts import InteractableWindowsToaster, ToastInputTextBox, ToastInputSelectionBox, ToastSelection, ToastText1
interactableToaster = InteractableWindowsToaster('Questionnaire')
newToast = ToastText1(body='Please enter your details')
newToast = ToastText1(['Please enter your details'])
# A text input field asking the user for their name
newToast.AddInput(ToastInputTextBox('name', 'Your name', 'Barack Obama'))
Expand Down Expand Up @@ -75,7 +74,7 @@ We can combine the two and a submit button
interactableToaster = InteractableWindowsToaster('Questionnaire')
newToast = ToastText1()
newToast.SetBody('What\'s your name?')
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)
Expand Down
5 changes: 0 additions & 5 deletions docs/user/toast.rst
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,5 @@ API
:exclude-members: Toast, ToastInput

.. autoclass:: windows_toasts.toast.Toast()
:exclude-members: audio, duration, scenario, textFields, timestamp, progress_bar, group, expiration_time,
suppress_popup, actions, images, inputs

..
As this is the ''user'' reference, we skip all the internal use attributes. This may be changes in the future.

.. automethod:: __init__
Loading

0 comments on commit f955387

Please sign in to comment.