mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
examples: json_tree: Use public attributes (#2138)
This commit is contained in:
@@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
- `TextLog`: `write`, `clear`
|
||||
- `TreeNode`: `expand`, `expand_all`, `collapse`, `collapse_all`, `toggle`, `toggle_all`
|
||||
- `Tree`: `clear`, `reset`
|
||||
- Replaced some private attributes with public ones in the json tree example. https://github.com/Textualize/textual/pull/2138
|
||||
|
||||
### Added
|
||||
|
||||
|
||||
@@ -43,24 +43,24 @@ class TreeApp(App):
|
||||
data (object): Data associated with the node.
|
||||
"""
|
||||
if isinstance(data, dict):
|
||||
node._label = Text(f"{{}} {name}")
|
||||
node.set_label(Text(f"{{}} {name}"))
|
||||
for key, value in data.items():
|
||||
new_node = node.add("")
|
||||
add_node(key, new_node, value)
|
||||
elif isinstance(data, list):
|
||||
node._label = Text(f"[] {name}")
|
||||
node.set_label(Text(f"[] {name}"))
|
||||
for index, value in enumerate(data):
|
||||
new_node = node.add("")
|
||||
add_node(str(index), new_node, value)
|
||||
else:
|
||||
node._allow_expand = False
|
||||
node.allow_expand = False
|
||||
if name:
|
||||
label = Text.assemble(
|
||||
Text.from_markup(f"[b]{name}[/b]="), highlighter(repr(data))
|
||||
)
|
||||
else:
|
||||
label = Text(repr(data))
|
||||
node._label = label
|
||||
node.set_label(label)
|
||||
|
||||
add_node("JSON", node, json_data)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user