Can't interact with DataTable after loading state in macOS Terminal.app #3911
-
When mounting a However, this behavior breaks under macOS Terminal.app, after switching the With WezTerm, keyboard input is also inactive after loading, but since it detects the mouse cursor (contrary to Terminal.app), the "focus" can be revived. Reproducible examplefrom asyncio import sleep
from random import randint
from textual import work
from textual.app import App, ComposeResult
from textual.widgets import DataTable
ROWS = [
("lane", "swimmer", "country", "time"),
(4, "Joseph Schooling", "Singapore", 50.39),
(2, "Michael Phelps", "United States", 51.14),
(5, "Chad le Clos", "South Africa", 51.14),
(6, "László Cseh", "Hungary", 51.14),
(3, "Li Zhuhao", "China", 51.26),
(8, "Mehdy Metella", "France", 51.58),
(7, "Tom Shields", "United States", 51.73),
(1, "Aleksandr Sadovnikov", "Russia", 51.84),
(10, "Darren Burns", "Scotland", 51.84),
]
class DataApp(App):
CSS = """
DataTable {
height: 1fr;
}
"""
def compose(self) -> ComposeResult:
yield DataTable()
def on_mount(self) -> None:
data_table = self.query_one(DataTable)
data_table.loading = True
self.load_data()
@work
async def load_data(self) -> None:
await sleep(randint(2, 10))
data_table = self.query_one(DataTable)
data_table.add_columns(*ROWS[0])
data_table.add_rows(ROWS[1:])
data_table.loading = False
if __name__ == "__main__":
app = DataApp()
app.run() Textual DiagnosticsVersions
Python
Operating System
Terminal
Rich Console options
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
You should find that the behaviour you're seeing is the same in any environment; not in some particular terminal or other. The issue here is that you're disabling the only focusable widget in your screen, so once doing that nothing has focus. When you set In your code here, you want to be adding |
Beta Was this translation helpful? Give feedback.
You should find that the behaviour you're seeing is the same in any environment; not in some particular terminal or other. The issue here is that you're disabling the only focusable widget in your screen, so once doing that nothing has focus. When you set
loading
toFalse
again focus won't be "stolen" (if there was more than one focusable widget on the screen you don't want focus pulled away from it just because the loading status of another widget has changed).In your code here, you want to be adding
data_table.focus()
after you've setdata_table.loading = False
.