ListItems going out of view #4851
-
Hello everyone, I'm posting this question here because I've read the documentation multiple times (EXCELLENT doc and code docstrings by the way, it's a pleasure to read the friendly manual) but I'm having a problem I can't get my head around. I have a custom TaskList widget class that inherits from ListView. And when I scroll down (with "j"), at some point the ListItem object goes out of view. from textual.app import App, ComposeResult
from textual.screen import Screen
from textual.widgets import Header, Footer, Static, ListView, ListItem
class TaskList(ListView):
def __init__(self):
self.items = [ListItem(Static(f"task {i}")) for i in range(100)]
super().__init__(*self.items)
self.index = 0
def next_task(self):
self.index += 1
class MyScreen(Screen):
widgets: list
def __init__(self):
self.widgets = []
self.index_widgets = -1
super().__init__()
def compose(self) -> ComposeResult:
sprint = TaskList()
self.widgets.append(sprint)
yield sprint
def next_task(self):
self.widgets[self.index_widgets].next_task()
class LazyJiraApp(App):
CSS = """
MyScreen {
layout: grid;
}
"""
BINDINGS = [
("q", "quit", "Quit the app"),
("j", "next_task", "Next Task"),
]
def __init__(self):
super().__init__()
self.my_screen = MyScreen()
def compose(self) -> ComposeResult:
yield self.my_screen
def action_next_task(self) -> None:
self.my_screen.next_task()
self.refresh()
if __name__ == "__main__":
app = LazyJiraApp()
app.run() Would you have an idea what I'm missing? If you need more context about the code (work in progress, you can't run it presently): LazyJira. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 14 replies
-
The docs for the
I'm not sure exactly what you are trying to achieve here with your custom ListView? |
Beta Was this translation helpful? Give feedback.
I've only skimmed your trimmed down example, but you shouldn't be yielding screens. making lists of widgets, or explicitly calling refresh.
Hopefully I've shown that Textual has better ways of handling all of this?