Dynamically changing items in a List #14
|
I'm trying to modify the items visible in a List when the user clicks on something in that list. Is it possible to do that? I think it's possible to add new widgets to the UI at runtime (and remove them as well?), if so I suppose I could fall back on deleting the old list and adding back a new one with contents I want to show, but that seems less elegant than clearing the list items and adding new values. |
Replies: 2 comments
|
Ok, so it feels like I can get rid of ui elements since the existence of the on_unmount callback implies that things can be unmounted before the program exits. And maybe components can be added to the ui after the app starts since on_mount might imply that doesn't have to happen just at app initiaization. But... how do I make on_unmount get called? What method/function does this? The component lifecycle section of concepts.md stops short showing how they get called. |
|
This is addressed in the example app in the tests directory. It's called taskflow.py and has supporting files in the taskflow_app folder. Essentially, you make a ui.Frame instance which has a layout. When you want to update the visible ui, you clear that Frame's layout and then add new versions of the children you want to see in that Frame. This involves various states, bind_tos, and subscribes. As I said, see the code for the taskflow app. PS - The tasks in the app have a Boolean attribute called "completed", the appearance of the task varies depending on whether the task has been completed, but there is no way, via the ui, to change that status. I guess that's an exercise for the reader. |
This is addressed in the example app in the tests directory. It's called taskflow.py and has supporting files in the taskflow_app folder.
Essentially, you make a ui.Frame instance which has a layout. When you want to update the visible ui, you clear that Frame's layout and then add new versions of the children you want to see in that Frame. This involves various states, bind_tos, and subscribes. As I said, see the code for the taskflow app.
PS - The tasks in the app have a Boolean attribute called "completed", the appearance of the task varies depending on whether the task has been completed, but there is no way, via the ui, to change that status. I guess that's an exercise for the reader.