Skip to content

Commit 3aaa4d3

Browse files
authored
Merge pull request #1170 from Textualize/new-tree
New Tree Control
2 parents 0cf7b08 + cf53929 commit 3aaa4d3

29 files changed

+3481
-579
lines changed

CHANGELOG.md

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,22 @@
11
# Change Log
22

3-
43
All notable changes to this project will be documented in this file.
54

65
The format is based on [Keep a Changelog](http://keepachangelog.com/)
76
and this project adheres to [Semantic Versioning](http://semver.org/).
87

8+
9+
## [0.6.0] - Unreleased
10+
11+
### Added
12+
13+
- Added "inherited bindings" -- BINDINGS classvar will be merged with base classes, unless inherit_bindings is set to False
14+
- Added `Tree` widget which replaces `TreeControl`.
15+
16+
### Changed
17+
18+
- Rebuilt `DirectoryTree` with new `Tree` control.
19+
920
## [0.5.0] - 2022-11-20
1021

1122
### Added

docs/api/directory_tree.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: textual.widgets.DirectoryTree

docs/api/tree.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: textual.widgets.Tree

docs/api/tree_node.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
::: textual.widgets.TreeNode
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from textual.app import App, ComposeResult
2+
from textual.widgets import DirectoryTree
3+
4+
5+
class DirectoryTreeApp(App):
6+
def compose(self) -> ComposeResult:
7+
yield DirectoryTree("./")
8+
9+
10+
if __name__ == "__main__":
11+
app = DirectoryTreeApp()
12+
app.run()

docs/examples/widgets/tree.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
from textual.app import App, ComposeResult
2+
from textual.widgets import Tree
3+
4+
5+
class TreeApp(App):
6+
def compose(self) -> ComposeResult:
7+
tree: Tree = Tree("Dune")
8+
tree.root.expand()
9+
characters = tree.root.add("Characters", expand=True)
10+
characters.add_leaf("Paul")
11+
characters.add_leaf("Jessica")
12+
characters.add_leaf("Channi")
13+
yield tree
14+
15+
16+
if __name__ == "__main__":
17+
app = TreeApp()
18+
app.run()

docs/widgets/directory_tree.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# DirectoryTree
2+
3+
A tree control to navigate the contents of your filesystem.
4+
5+
- [x] Focusable
6+
- [ ] Container
7+
8+
9+
## Example
10+
11+
The example below creates a simple tree to navigate the current working directory.
12+
13+
```python
14+
--8<-- "docs/examples/widgets/directory_tree.py"
15+
```
16+
17+
## Messages
18+
19+
### FileSelected
20+
21+
The `DirectoryTree.FileSelected` message is sent when the user selects a file in the tree
22+
23+
- [x] Bubbles
24+
25+
#### Attributes
26+
27+
| attribute | type | purpose |
28+
| --------- | ----- | ----------------- |
29+
| `path` | `str` | Path of the file. |
30+
31+
## Reactive Attributes
32+
33+
| Name | Type | Default | Description |
34+
| ------------- | ------ | ------- | ----------------------------------------------- |
35+
| `show_root` | `bool` | `True` | Show the root node. |
36+
| `show_guides` | `bool` | `True` | Show guide lines between levels. |
37+
| `guide_depth` | `int` | `4` | Amount of indentation between parent and child. |
38+
39+
40+
## See Also
41+
42+
* [Tree][textual.widgets.DirectoryTree] code reference
43+
* [Tree][textual.widgets.Tree] code reference

docs/widgets/tree.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
# Tree
2+
3+
A tree control widget.
4+
5+
- [x] Focusable
6+
- [ ] Container
7+
8+
9+
## Example
10+
11+
The example below creates a simple tree.
12+
13+
=== "Output"
14+
15+
```{.textual path="docs/examples/widgets/tree.py"}
16+
```
17+
18+
=== "tree.py"
19+
20+
```python
21+
--8<-- "docs/examples/widgets/tree.py"
22+
```
23+
24+
A each tree widget has a "root" attribute which is an instance of a [TreeNode][textual.widgets.TreeNode]. Call [add()][textual.widgets.TreeNode.add] or [add_leaf()][textual.widgets.TreeNode.add_leaf] to add new nodes underneath the root. Both these methods return a TreeNode for the child, so you can add more levels.
25+
26+
27+
## Reactive Attributes
28+
29+
| Name | Type | Default | Description |
30+
| ------------- | ------ | ------- | ----------------------------------------------- |
31+
| `show_root` | `bool` | `True` | Show the root node. |
32+
| `show_guides` | `bool` | `True` | Show guide lines between levels. |
33+
| `guide_depth` | `int` | `4` | Amount of indentation between parent and child. |
34+
35+
36+
37+
## Messages
38+
39+
### NodeSelected
40+
41+
The `Tree.NodeSelected` message is sent when the user selects a tree node.
42+
43+
44+
#### Attributes
45+
46+
| attribute | type | purpose |
47+
| --------- | ------------------------------------ | -------------- |
48+
| `node` | [TreeNode][textual.widgets.TreeNode] | Selected node. |
49+
50+
51+
### NodeExpanded
52+
53+
The `Tree.NodeExpanded` message is sent when the user expands a node in the tree.
54+
55+
#### Attributes
56+
57+
| attribute | type | purpose |
58+
| --------- | ------------------------------------ | -------------- |
59+
| `node` | [TreeNode][textual.widgets.TreeNode] | Expanded node. |
60+
61+
62+
### NodeCollapsed
63+
64+
65+
The `Tree.NodeCollapsed` message is sent when the user expands a node in the tree.
66+
67+
68+
#### Attributes
69+
70+
| attribute | type | purpose |
71+
| --------- | ------------------------------------ | --------------- |
72+
| `node` | [TreeNode][textual.widgets.TreeNode] | Collapsed node. |
73+
74+
75+
76+
77+
## See Also
78+
79+
* [Tree][textual.widgets.Tree] code reference
80+
* [TreeNode][textual.widgets.TreeNode] code reference

docs/widgets/tree_control.md

Lines changed: 0 additions & 1 deletion
This file was deleted.

examples/code_browser.css

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,19 @@ Screen {
33
}
44

55
#tree-view {
6-
display: none;
6+
display: none;
77
scrollbar-gutter: stable;
8-
width: auto;
8+
overflow: auto;
9+
width: auto;
10+
height: 100%;
11+
dock: left;
912
}
1013

1114
CodeBrowser.-show-tree #tree-view {
12-
display: block;
13-
dock: left;
14-
height: 100%;
15+
display: block;
1516
max-width: 50%;
16-
background: #151C25;
1717
}
1818

19-
DirectoryTree {
20-
padding-right: 1;
21-
}
2219

2320
#code-view {
2421
overflow: auto scroll;

0 commit comments

Comments
 (0)