Closed kwevin closed 4 days ago
Yeah, setting loading
mounts a child widget which kind of interferes with ListView
. Unfortunately the loading
attribute is a bit flaky in general at the moment, and this issue is making me think we might need to explore other mechanisms for implementing it (perhaps outwith the DOM, not interfering with children etc).
Anyway, you can still make it work in this case: You want to switch off "loading" which will unmount the LoadingIndicator
as a child of ListView
. We also need to await
this removal to ensure it completes before we try to modify the children of the ListView
using extend
:
from textual._work_decorator import work
from textual.app import App, ComposeResult
from textual.widgets import ListView
class MyApp(App[None]):
def compose(self) -> ComposeResult:
yield ListView()
def on_mount(self) -> None:
list_view = self.query_exactly_one(ListView)
list_view.loading = True
self.populate_table()
@work
async def populate_table(self) -> None:
list_view = self.query_exactly_one(ListView)
await list_view.set_loading(False)
await list_view.clear()
await list_view.extend([])
app = MyApp()
app.run()
Closing this for now as I've validated the above works, but feel free to let us know if you hit any other problems.
Don't forget to star the repository!
Follow @textualizeio for Textual updates.
Setting
loading=True
and updatingListView
inside of a worker with an empty list will cause it to raise anAssertionError
withLoadingIndicator
Textual Diagnostics
Versions
Python
Operating System
Terminal
Rich Console options