Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notifications #2866

Merged
merged 45 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
bb9e90e
Add a notification class and a class to hold notifications
davep Jun 29, 2023
699af22
WiP: End of day/week commit to pick up post-holiday
davep Jun 29, 2023
595c90d
Ask permission rather than forgiveness
davep Jun 30, 2023
6cf8517
Move the handling of "I've seen this" into the toast rack
davep Jun 30, 2023
c1cb120
Add a notify method to all widgets
davep Jun 30, 2023
eaa06ac
The removal time for a toast should be the time left
davep Jun 30, 2023
d4e4796
Carry notifications between screens
davep Jun 30, 2023
0b47d65
Remove the test code
davep Jun 30, 2023
31caf83
Drop the borders from the toasts
davep Jun 30, 2023
e5d6078
Provide access to the notification timeout
davep Jun 30, 2023
1f73f51
Remove the title panel from a Toast if the title is empty
davep Jun 30, 2023
660280d
Make the Toast CSS classes "private"
davep Jun 30, 2023
de73de6
Refresh a docstring
davep Jun 30, 2023
7a0bb66
Stop widget leakage
davep Jun 30, 2023
048e875
Make the alignment container hidden
davep Jun 30, 2023
b1874da
Merge branch 'main' into notifications-redux
davep Jul 10, 2023
67a1781
:truck: Rename the toast container
davep Jul 11, 2023
53f5302
Improve ToastRack._toast_id
davep Jul 11, 2023
43907fb
Add some initial low-level notification testing
davep Jul 11, 2023
6cd021d
Add initial testing of notifications within an application
davep Jul 11, 2023
864564a
Add tests for notifying from the 3 main levels within the DOM
davep Jul 11, 2023
9f4f82c
Add a toast example to the docs and a snapshot test
davep Jul 11, 2023
69cafaa
Add a snapshot test for notifications persisting between screens
davep Jul 11, 2023
1d3ea62
Add some documentation for a Toast
davep Jul 12, 2023
d552f6e
Flesh out the docstrings for the notify methods
davep Jul 12, 2023
90d7da1
Add a missing docstring to the Notifications __init__ method
davep Jul 12, 2023
1a3a5e9
Add snapshot tests for persisting notifications through mode switches
davep Jul 12, 2023
413844c
Merge branch 'main' into notifications-redux
davep Jul 12, 2023
b093538
Remove unused import
davep Jul 12, 2023
2c13949
Correct the Toast severity level classes in the docs
davep Jul 12, 2023
e353cbd
Make the removal of notifications/toasts a two way thing
davep Jul 13, 2023
f57af07
Remove an unhelpful comment
davep Jul 13, 2023
3fd5950
Add in support to the notification collection
davep Jul 13, 2023
159789a
Change the toast rack adder to be a general "show" method
davep Jul 13, 2023
89f590e
Add a method to clear notifications
davep Jul 13, 2023
85c55ee
Add an App method for clearing all existing notifications
davep Jul 13, 2023
a38a049
Add a missing docstring to _refresh_notifications
davep Jul 13, 2023
3f64ac8
Return the notification from the notify methods
davep Jul 13, 2023
ca94359
Add some more notifications unit testing
davep Jul 13, 2023
3280a5a
Add some more app-level notification unit testing
davep Jul 13, 2023
7fc7ef2
Style tweaks
willmcgugan Jul 17, 2023
b8282fb
docs
willmcgugan Jul 17, 2023
b07a660
added notifications
willmcgugan Jul 17, 2023
2f6a57f
snapshots
willmcgugan Jul 17, 2023
d45fb54
merge
willmcgugan Jul 17, 2023
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
5 changes: 3 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Added `DataTable.remove_column` method https://github.com/Textualize/textual/pull/2899
- Added notifications https://github.com/Textualize/textual/pull/2866

### Fixed

Expand All @@ -26,9 +27,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Added

- Updated `DataTable.get_cell` type hints to accept string keys https://github.com/Textualize/textual/issues/2586
- Added `DataTable.get_cell_coordinate` method
- Added `DataTable.get_cell_coordinate` method
- Added `DataTable.get_row_index` method https://github.com/Textualize/textual/issues/2587
- Added `DataTable.get_column_index` method
- Added `DataTable.get_column_index` method
- Added can-focus pseudo-class to target widgets that may receive focus
- Make `Markdown.update` optionally awaitable https://github.com/Textualize/textual/pull/2838
- Added `default` parameter to `DataTable.add_column` for populating existing rows https://github.com/Textualize/textual/pull/2836
Expand Down
26 changes: 26 additions & 0 deletions docs/examples/widgets/toast.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from textual.app import App


class ToastApp(App[None]):
def on_mount(self) -> None:
# Show an information notification.
self.notify("It's an older code, sir, but it checks out.")

# Show a warning. Note that Textual's notification system allows
# for the use of Rich console markup.
self.notify(
"Now witness the firepower of this fully "
"[b]ARMED[/b] and [i][b]OPERATIONAL[/b][/i] battle station!",
title="Possible trap detected",
severity="warning",
)

# Show an error. Set a longer timeout so it's noticed.
self.notify("It's a trap!", severity="error", timeout=10)

# Show an information notification, but without any sort of title.
self.notify("It's against my programming to impersonate a deity.", title="")


if __name__ == "__main__":
ToastApp().run()
79 changes: 79 additions & 0 deletions docs/widgets/toast.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# Toast

!!! tip "Added in version 0.30.0"

A widget which displays a notification message.

- [ ] Focusable
- [ ] Container

Note that `Toast` isn't designed to be used directly in your applications,
but it is instead used by [`notify`][textual.app.App.notify] to
display a message when using Textual's built-in notification system.

## Styling

You can customize the style of Toasts by targeting the `Toast` [CSS type](/guide/CSS/#type-selector).
For example:


```scss
Toast {
padding: 3;
}
```

The three severity levels also have corresponding
[classes](/guide/CSS/#class-name-selector), allowing you to target the
different styles of notification. They are:

- `-information`
- `-warning`
- `-error`

If you wish to tailor the notifications for your application you can add
rules to your CSS like this:

```scss
Toast.-information {
/* Styling here. */
}

Toast.-warning {
/* Styling here. */
}

Toast.-error {
/* Styling here. */
}
```

You can customize just the title wih the `toast--title` class.
The following would make the title italic for an information toast:

```scss
Toast.-information .toast--title {
text-style: italic;
}

```

## Example

=== "Output"

```{.textual path="docs/examples/widgets/toast.py"}
```

=== "toast.py"

```python
--8<-- "docs/examples/widgets/toast.py"
```

---

::: textual.widgets._toast
options:
show_root_heading: true
show_root_toc_entry: true
Loading