You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the attached App, pressing the button will indicate the highlighted and the selected node from the tree. In order to accomplish this, I needed to fetch the highlighted and selected event, and store the specific nodes in self.SEL_node and self.HIGH_node.
Isn't there an easier way to use an attribute from the tree variable itself? It removes the need for storing into instance variables.
from textual.app import App
from textual.widgets import Tree, Button, Log
from textual.message import Message
class MyApp(App):
def compose(self):
self.tree_panel = Tree("Root",id="boom")
# Create the log panel
self.log_panel = Log()
# Create the start and stop buttons
self.start_button = Button("Start", id="start_button")
yield self.tree_panel
yield self.log_panel
yield self.start_button
def on_tree_node_highlighted( self, event: Tree.NodeHighlighted ) -> None:
"""Called when the user click a file in the directory tree."""
event.stop()
nd = event.node
self.HIGH_node = nd
self.log_panel.write(f"Node highlighted {nd.label}\n")
def on_tree_node_selected( self, event: Tree.NodeSelected ) -> None:
"""Called when the user click a file in the directory tree."""
event.stop()
nd = event.node
self.SEL_node = nd
self.log_panel.write(f"Node selected {nd.label}\n")
def on_mount(self):
# Populate the tree
tree= self.tree_panel
node = tree.root
node = node.add("AAA")
node = node.add("BBB" )
async def on_button_pressed(self, message: Message):
button_id = message.control.id
high_node = self.HIGH_node
if high_node:
self.log_panel.write(f"Start action highlighted for {high_node.label}\n")
selected_node = self.SEL_node
if selected_node:
self.log_panel.write(f"Start action selected for {selected_node.label}\n")
app = MyApp()
app.run()
The text was updated successfully, but these errors were encountered:
There's the Tree.cursor_node property, but that docstring might be a bit misleading as this returns the node currently under the cursor. I don't think the Tree stores any state of the last selected node.
In the attached App, pressing the button will indicate the highlighted and the selected node from the tree. In order to accomplish this, I needed to fetch the highlighted and selected event, and store the specific nodes in self.SEL_node and self.HIGH_node.
Isn't there an easier way to use an attribute from the tree variable itself? It removes the need for storing into instance variables.
The text was updated successfully, but these errors were encountered: