Skip to content

Commit

Permalink
Merge branch 'main' into fix-listview-update-index-after-items-removed
Browse files Browse the repository at this point in the history
  • Loading branch information
darrenburns authored Nov 28, 2024
2 parents 25901b7 + 79df474 commit e507eb3
Show file tree
Hide file tree
Showing 10 changed files with 377 additions and 154 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- `ListView.pop` now returns `AwaitComplete` rather than `AwaitRemove` https://github.com/Textualize/textual/pull/5135
- `ListView.remove_items` now returns `AwaitComplete` rather than `AwaitRemove` https://github.com/Textualize/textual/pull/5135
- Fixed ListView focus styling rule being too broad https://github.com/Textualize/textual/pull/5304
- Fixed issue with auto-generated tab IDs https://github.com/Textualize/textual/pull/5298

## [0.87.1] - 2024-11-24

Expand Down
7 changes: 1 addition & 6 deletions examples/theme_sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,12 +190,7 @@ class ChangingThemeApp(App[None]):
}
ListView {
height: auto;
& > ListItem {
width: 1fr;
& > Label {
width: 1fr;
}
}
}
Tree {
height: 5;
Expand Down
66 changes: 48 additions & 18 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 8 additions & 9 deletions src/textual/widgets/_list_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@ class ListView(VerticalScroll, can_focus=True, can_focus_children=False):
DEFAULT_CSS = """
ListView {
background: $surface;
&:focus-within {
background-tint: $foreground 5%;
}
& > ListItem {
color: $foreground;
height: auto;
Expand All @@ -52,12 +48,15 @@ class ListView(VerticalScroll, can_focus=True, can_focus_children=False):
}
}
&:focus > ListItem.-highlight > Widget {
width: 1fr;
color: $block-cursor-foreground;
background: $block-cursor-background;
text-style: $block-cursor-text-style;
&:focus {
background-tint: $foreground 5%;
& > ListItem.-highlight {
color: $block-cursor-foreground;
background: $block-cursor-background;
text-style: $block-cursor-text-style;
}
}
}
"""

Expand Down
14 changes: 12 additions & 2 deletions src/textual/widgets/_tabbed_content.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,7 @@ def __init__(
self.titles = [self.render_str(title) for title in titles]
self._tab_content: list[Widget] = []
self._initial = initial
self._tab_counter = 0
super().__init__(name=name, id=id, classes=classes, disabled=disabled)

@property
Expand All @@ -357,6 +358,15 @@ def _set_id(content: TabPane, new_id: int) -> TabPane:
content.id = f"tab-{new_id}"
return content

def _generate_tab_id(self) -> int:
"""Auto generate a new tab id.
Returns:
An auto-incrementing integer.
"""
self._tab_counter += 1
return self._tab_counter

def compose(self) -> ComposeResult:
"""Compose the tabbed content."""

Expand All @@ -368,7 +378,7 @@ def compose(self) -> ComposeResult:
if isinstance(content, TabPane)
else TabPane(title or self.render_str(f"Tab {index}"), content)
),
index,
self._generate_tab_id(),
)
for index, (title, content) in enumerate(
zip_longest(self.titles, self._tab_content), 1
Expand Down Expand Up @@ -424,7 +434,7 @@ def add_pane(
if isinstance(after, TabPane):
after = after.id
tabs = self.get_child_by_type(ContentTabs)
pane = self._set_id(pane, tabs.tab_count + 1)
pane = self._set_id(pane, self._generate_tab_id())
assert pane.id is not None
pane.display = False
return AwaitComplete(
Expand Down
2 changes: 1 addition & 1 deletion src/textual/widgets/_tree.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def add(
before: Optional index or `TreeNode` to add the node before.
after: Optional index or `TreeNode` to add the node after.
expand: Node should be expanded.
allow_expand: Allow use to expand the node via keyboard or mouse.
allow_expand: Allow user to expand the node via keyboard or mouse.
Returns:
A new Tree node
Expand Down
Loading

0 comments on commit e507eb3

Please sign in to comment.