mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Merge branch 'main' into tree-node-children-prop
This commit is contained in:
@@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
### Added
|
||||
|
||||
- Added public `TreeNode` label access via `TreeNode.label` https://github.com/Textualize/textual/issues/1396
|
||||
- Added read-only public access to the children of a `TreeNode` via `TreeNode.children` https://github.com/Textualize/textual/issues/1398
|
||||
|
||||
### Changed
|
||||
|
||||
12
FAQ.md
12
FAQ.md
@@ -1,6 +1,7 @@
|
||||
|
||||
# Frequently Asked Questions
|
||||
- [Does Textual support images?](#does-textual-support-images)
|
||||
- [How can I fix ImportError cannot import name ComposeResult from textual.app ?](#how-can-i-fix-importerror-cannot-import-name-composeresult-from-textualapp-)
|
||||
- [How do I center a widget in a screen?](#how-do-i-center-a-widget-in-a-screen)
|
||||
- [How do I pass arguments to an app?](#how-do-i-pass-arguments-to-an-app)
|
||||
|
||||
@@ -11,6 +12,17 @@ Textual doesn't have built in support for images yet, but it is on the [Roadmap]
|
||||
|
||||
See also the [rich-pixels](https://github.com/darrenburns/rich-pixels) project for a Rich renderable for images that works with Textual.
|
||||
|
||||
<a name="how-can-i-fix-importerror-cannot-import-name-composeresult-from-textualapp-"></a>
|
||||
## How can I fix ImportError cannot import name ComposeResult from textual.app ?
|
||||
|
||||
You likely have an older version of Textual. You can install the latest version by adding the `-U` switch which will force pip to upgrade.
|
||||
|
||||
The following should do it:
|
||||
|
||||
```
|
||||
pip install "textual[dev]" -U
|
||||
```
|
||||
|
||||
<a name="how-do-i-center-a-widget-in-a-screen"></a>
|
||||
## How do I center a widget in a screen?
|
||||
|
||||
|
||||
14
questions/compose-result.question.md
Normal file
14
questions/compose-result.question.md
Normal file
@@ -0,0 +1,14 @@
|
||||
---
|
||||
title: "How can I fix ImportError cannot import name ComposeResult from textual.app ?"
|
||||
alt_titles:
|
||||
- "Can't import ComposeResult"
|
||||
- "Error about missing ComposeResult from textual.app"
|
||||
---
|
||||
|
||||
You likely have an older version of Textual. You can install the latest version by adding the `-U` switch which will force pip to upgrade.
|
||||
|
||||
The following should do it:
|
||||
|
||||
```
|
||||
pip install "textual[dev]" -U
|
||||
```
|
||||
@@ -76,7 +76,7 @@ class TreeNode(Generic[TreeDataType]):
|
||||
self._tree = tree
|
||||
self._parent = parent
|
||||
self._id = id
|
||||
self._label = label
|
||||
self._label = tree.process_label(label)
|
||||
self.data = data
|
||||
self._expanded = expanded
|
||||
self._children: list[TreeNode[TreeDataType]] = []
|
||||
@@ -173,6 +173,15 @@ class TreeNode(Generic[TreeDataType]):
|
||||
self._updates += 1
|
||||
self._tree._invalidate()
|
||||
|
||||
@property
|
||||
def label(self) -> TextType:
|
||||
"""TextType: The label for the node."""
|
||||
return self._label
|
||||
|
||||
@label.setter
|
||||
def label(self, new_label: TextType) -> None:
|
||||
self.set_label(new_label)
|
||||
|
||||
def set_label(self, label: TextType) -> None:
|
||||
"""Set a new label for the node.
|
||||
|
||||
|
||||
@@ -2,13 +2,8 @@ import pytest
|
||||
from textual.widgets import Tree, TreeNode
|
||||
|
||||
def label_of(node: TreeNode[None]):
|
||||
"""Get the label of a node.
|
||||
|
||||
TODO: This is just a helper function to reduce the number of type
|
||||
errors, which can and will be remove once this code is merged with a
|
||||
version of main that also has the TreeNode.label PR merged.
|
||||
"""
|
||||
return str(node._label)
|
||||
"""Get the label of a node as a string"""
|
||||
return str(node.label)
|
||||
|
||||
|
||||
def test_tree_node_children() -> None:
|
||||
|
||||
17
tests/tree/test_tree_node_label.py
Normal file
17
tests/tree/test_tree_node_label.py
Normal file
@@ -0,0 +1,17 @@
|
||||
from textual.widgets import Tree, TreeNode
|
||||
from rich.text import Text
|
||||
|
||||
def test_tree_node_label() -> None:
|
||||
"""It should be possible to modify a TreeNode's label."""
|
||||
node = TreeNode(Tree[None]("Xenomorph Lifecycle"), None, 0, "Facehugger")
|
||||
assert node.label == Text("Facehugger")
|
||||
node.label = "Chestbuster"
|
||||
assert node.label == Text("Chestbuster")
|
||||
|
||||
def test_tree_node_label_via_tree() -> None:
|
||||
"""It should be possible to modify a TreeNode's label when created via a Tree."""
|
||||
tree = Tree[None]("Xenomorph Lifecycle")
|
||||
node = tree.root.add("Facehugger")
|
||||
assert node.label == Text("Facehugger")
|
||||
node.label = "Chestbuster"
|
||||
assert node.label == Text("Chestbuster")
|
||||
Reference in New Issue
Block a user