Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating a TreeNode.label doesn't refresh the tree right away #2698

Closed
davep opened this issue May 31, 2023 · 1 comment · Fixed by #2713
Closed

Updating a TreeNode.label doesn't refresh the tree right away #2698

davep opened this issue May 31, 2023 · 1 comment · Fixed by #2713
Assignees
Labels
bug Something isn't working Task

Comments

@davep
Copy link
Contributor

davep commented May 31, 2023

In this little illustration of how a Tree's nodes' labels can be updated on the fly, the actual updates don't show until some other interaction with the Tree takes place (moving the cursor, causing a mouse hover event, etc):

from textual.app     import App, ComposeResult
from textual.widgets import Header, Footer, Tree

class TreeNodeUpdateApp( App[ None ] ):

    BINDINGS = [
        ( "a", "add", "" ),
    ]

    def compose( self ) -> ComposeResult:
        yield Header()
        yield Tree( "100" )
        yield Footer()

    def on_mount( self ) -> None:
        for n in range( 10 ):
            node = self.query_one( Tree ).root.add( str( n ), expand=True )
            for m in range( 10 ):
                node.add_leaf( str( m ) )

    def action_add( self ):
        node = self.query_one( Tree ).cursor_node
        node.label = str( int( str( node.label ) ) + 1 )

if __name__ == "__main__":
    TreeNodeUpdateApp().run()

adding a self.query_one( Tree ).refresh() to the end of action_add fixes it so the update of the label is reflected right away.

TreeNode.set_label should probably be changed to cause the Tree to perform a refresh.

@davep davep added bug Something isn't working Task labels May 31, 2023
davep added a commit to davep/textual-sandbox that referenced this issue May 31, 2023
@davep davep self-assigned this Jun 1, 2023
davep added a commit to davep/textual that referenced this issue Jun 1, 2023
@github-actions
Copy link

github-actions bot commented Jun 1, 2023

Don't forget to star the repository!

Follow @textualizeio for Textual updates.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Task
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant