Skip to content

Commit

Permalink
Merge branch 'main' into tab-hide-disable
Browse files Browse the repository at this point in the history
  • Loading branch information
rodrigogiraoserrao authored Aug 21, 2023
2 parents 8d83cd4 + eccb6e5 commit fa8f893
Show file tree
Hide file tree
Showing 12 changed files with 375 additions and 107 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- grid-columns and grid-rows now accept an `auto` token to detect the optimal size https://github.com/Textualize/textual/pull/3107

### Fixed

- Fixed auto height container with default grid-rows https://github.com/Textualize/textual/issues/1597
- Fixed `page_up` and `page_down` bug in `DataTable` when `show_header = False` https://github.com/Textualize/textual/pull/3093

## [0.33.0] - 2023-08-15


### Fixed

- Fixed unintuitive sizing behaviour of TabbedContent https://github.com/Textualize/textual/issues/2411
Expand Down Expand Up @@ -58,6 +64,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- Added App.begin_capture_print, App.end_capture_print, Widget.begin_capture_print, Widget.end_capture_print https://github.com/Textualize/textual/issues/2952
- Added the ability to run async methods as thread workers https://github.com/Textualize/textual/pull/2938
- Added `ListView.extend` method to append multiple items https://github.com/Textualize/textual/pull/3012
- Added `App.stop_animation` https://github.com/Textualize/textual/issues/2786
- Added `Widget.stop_animation` https://github.com/Textualize/textual/issues/2786

Expand Down
16 changes: 16 additions & 0 deletions docs/examples/widgets/header_app_title.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from textual.app import App, ComposeResult
from textual.widgets import Header


class HeaderApp(App):
def compose(self) -> ComposeResult:
yield Header()

def on_mount(self) -> None:
self.title = "Header Application"
self.sub_title = "With title and sub-title"


if __name__ == "__main__":
app = HeaderApp()
app.run()
17 changes: 17 additions & 0 deletions docs/widgets/header.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

A simple header widget which docks itself to the top of the parent container.

!!! note

The application title which is shown in the header is taken from the [`title`][textual.app.App.title] and [`sub_title`][textual.app.App.sub_title] of the application.

- [ ] Focusable
- [ ] Container

Expand All @@ -20,6 +24,19 @@ The example below shows an app with a `Header`.
--8<-- "docs/examples/widgets/header.py"
```

This example shows how to set the text in the `Header` using `App.title` and `App.sub_title`:

=== "Output"

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

=== "header_app_title.py"

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

## Reactive Attributes

| Name | Type | Default | Description |
Expand Down
17 changes: 5 additions & 12 deletions src/textual/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from rich.console import RenderableType
from rich.json import JSON
from rich.markdown import Markdown
from rich.markup import escape
from rich.pretty import Pretty
from rich.syntax import Syntax
from rich.table import Table
Expand Down Expand Up @@ -269,14 +270,6 @@ class SubTitle(Static):
pass


class Notification(Static):
def on_mount(self) -> None:
self.set_timer(3, self.remove)

def on_click(self) -> None:
self.remove()


class DemoApp(App[None]):
CSS_PATH = "demo.css"
TITLE = "Textual Demo"
Expand All @@ -285,7 +278,7 @@ class DemoApp(App[None]):
("ctrl+t", "app.toggle_dark", "Toggle Dark mode"),
("ctrl+s", "app.screenshot()", "Screenshot"),
("f1", "app.toggle_class('RichLog', '-hidden')", "Notes"),
Binding("ctrl+c,ctrl+q", "app.quit", "Quit", show=True),
Binding("ctrl+q", "app.quit", "Quit", show=True),
]

show_sidebar = reactive(False)
Expand Down Expand Up @@ -390,9 +383,9 @@ def action_screenshot(self, filename: str | None = None, path: str = "./") -> No
"""
self.bell()
path = self.save_screenshot(filename, path)
message = Text.assemble("Screenshot saved to ", (f"'{path}'", "bold green"))
self.add_note(message)
self.screen.mount(Notification(message))
message = f"Screenshot saved to [bold green]'{escape(str(path))}'[/]"
self.add_note(Text.from_markup(message))
self.notify(message)


app = DemoApp()
Expand Down
4 changes: 2 additions & 2 deletions src/textual/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,15 +535,15 @@ class Leave(Event, bubble=False, verbose=True):
class Focus(Event, bubble=False):
"""Sent when a widget is focussed.
- [X] Bubbles
- [ ] Bubbles
- [ ] Verbose
"""


class Blur(Event, bubble=False):
"""Sent when a widget is blurred (un-focussed).
- [X] Bubbles
- [ ] Bubbles
- [ ] Verbose
"""

Expand Down
4 changes: 3 additions & 1 deletion src/textual/layouts/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ def arrange(
self, parent: Widget, children: list[Widget], size: Size
) -> ArrangeResult:
styles = parent.styles
row_scalars = styles.grid_rows or [Scalar.parse("1fr")]
row_scalars = styles.grid_rows or (
[Scalar.parse("1fr")] if size.height else [Scalar.parse("auto")]
)
column_scalars = styles.grid_columns or [Scalar.parse("1fr")]
gutter_horizontal = styles.grid_gutter_horizontal
gutter_vertical = styles.grid_gutter_vertical
Expand Down
10 changes: 4 additions & 6 deletions src/textual/widgets/_data_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -2205,9 +2205,8 @@ async def _on_click(self, event: events.Click) -> None:
def action_page_down(self) -> None:
"""Move the cursor one page down."""
self._set_hover_cursor(False)
cursor_type = self.cursor_type
if self.show_cursor and (cursor_type == "cell" or cursor_type == "row"):
height = self.size.height - self.header_height if self.show_header else 0
if self.show_cursor and self.cursor_type in ("cell", "row"):
height = self.size.height - (self.header_height if self.show_header else 0)

# Determine how many rows constitutes a "page"
offset = 0
Expand All @@ -2228,9 +2227,8 @@ def action_page_down(self) -> None:
def action_page_up(self) -> None:
"""Move the cursor one page up."""
self._set_hover_cursor(False)
cursor_type = self.cursor_type
if self.show_cursor and (cursor_type == "cell" or cursor_type == "row"):
height = self.size.height - self.header_height if self.show_header else 0
if self.show_cursor and self.cursor_type in ("cell", "row"):
height = self.size.height - (self.header_height if self.show_header else 0)

# Determine how many rows constitutes a "page"
offset = 0
Expand Down
22 changes: 17 additions & 5 deletions src/textual/widgets/_list_view.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from typing import ClassVar, Optional
from typing import ClassVar, Iterable, Optional

from textual.await_remove import AwaitRemove
from textual.binding import Binding, BindingType
Expand Down Expand Up @@ -172,6 +172,21 @@ def watch_index(self, old_index: int, new_index: int) -> None:
self._scroll_highlighted_region()
self.post_message(self.Highlighted(self, new_child))

def extend(self, items: Iterable[ListItem]) -> AwaitMount:
"""Append multiple new ListItems to the end of the ListView.
Args:
items: The ListItems to append.
Returns:
An awaitable that yields control to the event loop
until the DOM has been updated with the new child items.
"""
await_mount = self.mount(*items)
if len(self) == 1:
self.index = 0
return await_mount

def append(self, item: ListItem) -> AwaitMount:
"""Append a new ListItem to the end of the ListView.
Expand All @@ -182,10 +197,7 @@ def append(self, item: ListItem) -> AwaitMount:
An awaitable that yields control to the event loop
until the DOM has been updated with the new child item.
"""
await_mount = self.mount(item)
if len(self) == 1:
self.index = 0
return await_mount
return self.extend([item])

def clear(self) -> AwaitRemove:
"""Clear all items from the ListView.
Expand Down
Loading

0 comments on commit fa8f893

Please sign in to comment.