Created
January 17, 2025 21:45
-
-
Save driscollis/b2435ac95f952321036f1483166be40c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# tree_experiments.py | |
from rich.text import Text | |
from textual.app import App, ComposeResult | |
from textual.widgets import Tree | |
class TreeApp(App): | |
def compose(self) -> ComposeResult: | |
self.top_level_nodes: dict[str, int] = {} | |
nodes = {} | |
leaves = ["one", "two", "three"] | |
tree = Tree("root") | |
tree.root.expand() | |
some_file_tests = tree.root.add(Text("some_file.py", style="green")) | |
self.top_level_nodes["some_file.py"] = some_file_tests.id | |
leaf_nodes = {} | |
for leaf in leaves: | |
leaf_obj = some_file_tests.add_leaf(leaf) | |
leaf_nodes[leaf] = leaf_obj.id | |
nodes["some_file.py"] = leaf_nodes | |
some_more_tests = tree.root.add(Text("another_file.py", style="red")) | |
self.top_level_nodes["another_file.py"] = some_more_tests.id | |
leaf_nodes = {} | |
for leaf in leaves: | |
leaf_obj = some_more_tests.add_leaf(leaf) | |
leaf_nodes[leaf] = leaf_obj.id | |
nodes["another_file.py"] = leaf_nodes | |
print(f"{self.top_level_nodes = } {nodes = }") | |
yield tree | |
if __name__ == "__main__": | |
app = TreeApp() | |
app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment