Can I reload a TreeControl's list of items? #151
-
I've been tinkering with Textual to build with a TUI that can be used to view details about hardware devices connected to my computer. On the left is the list of devices in Screen.Recording.2021-10-15.at.8.44.05.AM.movWhat's stumped me now is, how can I display a new list of items in the tree? I want to offer a "Reload" command that will rescan for hardware devices and then display the new list in place of the old. Unfortunately all I've been able to manage is adding additional items, with the unfortunate side effect of the app crashing with an Screen.Recording.2021-10-19.at.8.37.55.AM.movI'm attempting to reload the items like this, with a method on my subclass of async def on_reload_authenticators(
self, new_authenticators: List[AuthenticatorViewModel]
) -> None:
self.authenticators = new_authenticators
for auth_view_model in self.authenticators:
tree_data = AuthenticatorListData(authenticator=auth_view_model)
await self.add(self.root.id, auth_view_model.aaguid, tree_data.dict())
self.refresh(layout=True) But this clearly isn't the complete formula. What I think I want is the ability to specify async Has anyone tackled this before? Will said he was inspired by VueJS for some of Textual's inner workings, and I'm coming at this from a predominantly web dev background; I was hoping Textual might emulate some of the magic of the "one-way data flow" of front end SPA frameworks with automatic re-renderings. In this case |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
Hey @MasterKale , this is how I do it: I've got a refresh method in the works that will remove the need to init a new version of the tree. |
Beta Was this translation helpful? Give feedback.
Hey @MasterKale , this is how I do it:
https://github.com/chelnak/jenkins-tui/blob/016958abe639e97daa02d63535fcdfde7f1b97cd/src/jenkins_tui/app.py#L100
I've got a refresh method in the works that will remove the need to init a new version of the tree.