Skip to content

ABOUT the ListView/ListItem. [Design a File eXplorer] #1928

Answered by davep
Lenbot-QC asked this question in Q&A
Discussion options

You must be logged in to vote

when I select a ListItem, then how to refresh the ListView accordingly?

The ListVIew has both clear and append methods, so I'd probably build such a widget around that. By way of illustration, here's how I think I'd approach what you seem to be doing:

from pathlib import Path
from typing  import Any

from textual.app     import App, ComposeResult
from textual.widgets import Header, Footer, ListView, ListItem, Label

class FSEntry( ListItem ):

    def __init__( self, entry: Path ) -> None:
        super().__init__()
        self.entry = entry

    def compose( self ) -> ComposeResult:
        yield Label(
            self.entry.stem + ( "/" if self.entry.is_dir() else "" )
        )


c…

Replies: 2 comments 4 replies

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
4 replies
@Lenbot-QC
Comment options

@willmcgugan
Comment options

@davep
Comment options

@marcbelmont
Comment options

Answer selected by davep
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
4 participants