diff --git a/auditui/app/__init__.py b/auditui/app/__init__.py index e1c10b4..6dd5087 100644 --- a/auditui/app/__init__.py +++ b/auditui/app/__init__.py @@ -2,7 +2,7 @@ from __future__ import annotations -from textual.app import App +from textual.app import App, ComposeResult from ..constants import TABLE_CSS @@ -22,6 +22,9 @@ class Auditui(App, AppProgressMixin, AppActionsMixin, AppLibraryMixin, AppTableM BINDINGS = BINDINGS CSS = TABLE_CSS + def compose(self) -> ComposeResult: + yield from AppLayoutMixin.compose(self) + def __init__(self, auth=None, client=None) -> None: super().__init__() init_auditui_state(self, auth, client) diff --git a/auditui/app/actions.py b/auditui/app/actions.py index 284c61c..bbbe517 100644 --- a/auditui/app/actions.py +++ b/auditui/app/actions.py @@ -15,7 +15,7 @@ class AppActionsMixin: self.update_status( "Not authenticated. Please restart and authenticate.") return None - table = self.query_one(DataTable) + table = self.query_one("#library_table", DataTable) if table.row_count == 0: self.update_status("No books available") return None diff --git a/auditui/app/layout.py b/auditui/app/layout.py index 4348a0c..2f012fd 100644 --- a/auditui/app/layout.py +++ b/auditui/app/layout.py @@ -20,7 +20,7 @@ class AppLayoutMixin: id="top_bar", ) yield Static("Loading...", id="status") - table = DataTable() + table = DataTable(id="library_table") table.zebra_stripes = True table.cursor_type = "row" yield table @@ -32,7 +32,10 @@ class AppLayoutMixin: def on_mount(self) -> None: self.theme = "textual-dark" - table = self.query_one(DataTable) + self.call_after_refresh(self._init_table_and_intervals) + + def _init_table_and_intervals(self) -> None: + table = self.query_one("#library_table", DataTable) for column_name, _ratio in TABLE_COLUMN_DEFS: table.add_column(column_name) self.call_after_refresh(lambda: self._apply_column_widths(table)) @@ -58,7 +61,7 @@ class AppLayoutMixin: def on_resize(self, event: Resize) -> None: del event try: - table = self.query_one(DataTable) + table = self.query_one("#library_table", DataTable) except Exception: return self.call_after_refresh(lambda: self._apply_column_widths(table)) diff --git a/auditui/app/table.py b/auditui/app/table.py index 2faeb92..eeac42a 100644 --- a/auditui/app/table.py +++ b/auditui/app/table.py @@ -15,7 +15,7 @@ from textual.widgets import DataTable, Static class AppTableMixin: def _populate_table(self, items: list[LibraryItem]) -> None: - table = self.query_one(DataTable) + table = self.query_one("#library_table", DataTable) table.clear() if not items or not self.library_client: @@ -51,14 +51,14 @@ class AppTableMixin: self._refresh_filtered_view() def action_sort(self) -> None: - table = self.query_one(DataTable) + table = self.query_one("#library_table", DataTable) if table.row_count > 0 and self.title_column_key: title_key, reverse = create_title_sort_key(self.title_sort_reverse) table.sort(key=title_key, reverse=reverse) self.title_sort_reverse = not self.title_sort_reverse def action_sort_by_progress(self) -> None: - table = self.query_one(DataTable) + table = self.query_one("#library_table", DataTable) if table.row_count > 0: self.progress_sort_reverse = not self.progress_sort_reverse progress_key, reverse = create_progress_sort_key(