fix: align app with textual 8 api
This commit is contained in:
@@ -31,13 +31,12 @@ from .search_utils import build_search_text, filter_items
|
|||||||
from .ui import FilterScreen, HelpScreen, StatsScreen
|
from .ui import FilterScreen, HelpScreen, StatsScreen
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from textual.widgets._data_table import ColumnKey
|
from textual.widgets.data_table import ColumnKey
|
||||||
|
|
||||||
|
|
||||||
class Auditui(App):
|
class Auditui(App):
|
||||||
"""Main application class for the Audible TUI app."""
|
"""Main application class for the Audible TUI app."""
|
||||||
|
|
||||||
theme = "textual-dark"
|
|
||||||
SHOW_PALETTE = False
|
SHOW_PALETTE = False
|
||||||
|
|
||||||
BINDINGS = [
|
BINDINGS = [
|
||||||
@@ -72,8 +71,7 @@ class Auditui(App):
|
|||||||
self.download_manager = (
|
self.download_manager = (
|
||||||
DownloadManager(auth, client) if auth and client else None
|
DownloadManager(auth, client) if auth and client else None
|
||||||
)
|
)
|
||||||
self.playback = PlaybackController(
|
self.playback = PlaybackController(self.update_status, self.library_client)
|
||||||
self.update_status, self.library_client)
|
|
||||||
|
|
||||||
self.all_items: list[dict] = []
|
self.all_items: list[dict] = []
|
||||||
self.current_items: list[dict] = []
|
self.current_items: list[dict] = []
|
||||||
@@ -105,6 +103,7 @@ class Auditui(App):
|
|||||||
|
|
||||||
def on_mount(self) -> None:
|
def on_mount(self) -> None:
|
||||||
"""Initialize the table and start fetching library data."""
|
"""Initialize the table and start fetching library data."""
|
||||||
|
self.theme = "textual-dark"
|
||||||
table = self.query_one(DataTable)
|
table = self.query_one(DataTable)
|
||||||
for column_name, _ratio in TABLE_COLUMN_DEFS:
|
for column_name, _ratio in TABLE_COLUMN_DEFS:
|
||||||
table.add_column(column_name)
|
table.add_column(column_name)
|
||||||
@@ -116,8 +115,7 @@ class Auditui(App):
|
|||||||
self.update_status("Fetching library...")
|
self.update_status("Fetching library...")
|
||||||
self.fetch_library()
|
self.fetch_library()
|
||||||
else:
|
else:
|
||||||
self.update_status(
|
self.update_status("Not authenticated. Please restart and authenticate.")
|
||||||
"Not authenticated. Please restart and authenticate.")
|
|
||||||
|
|
||||||
self.set_interval(1.0, self._check_playback_status)
|
self.set_interval(1.0, self._check_playback_status)
|
||||||
self.set_interval(0.5, self._update_progress)
|
self.set_interval(0.5, self._update_progress)
|
||||||
@@ -210,8 +208,7 @@ class Auditui(App):
|
|||||||
|
|
||||||
remainder = distributable - sum(widths)
|
remainder = distributable - sum(widths)
|
||||||
if remainder > 0:
|
if remainder > 0:
|
||||||
indices = sorted(
|
indices = sorted(range(num_cols), key=lambda i: ratios[i], reverse=True)
|
||||||
range(num_cols), key=lambda i: ratios[i], reverse=True)
|
|
||||||
for i in range(remainder):
|
for i in range(remainder):
|
||||||
widths[indices[i % num_cols]] += 1
|
widths[indices[i % num_cols]] += 1
|
||||||
|
|
||||||
@@ -233,8 +230,7 @@ class Auditui(App):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
all_items = self.library_client.fetch_all_items(
|
all_items = self.library_client.fetch_all_items(self._thread_status_update)
|
||||||
self._thread_status_update)
|
|
||||||
self.call_from_thread(self.on_library_loaded, all_items)
|
self.call_from_thread(self.on_library_loaded, all_items)
|
||||||
except (OSError, ValueError, KeyError) as exc:
|
except (OSError, ValueError, KeyError) as exc:
|
||||||
self.call_from_thread(self.on_library_error, str(exc))
|
self.call_from_thread(self.on_library_error, str(exc))
|
||||||
@@ -267,8 +263,7 @@ class Auditui(App):
|
|||||||
title, author, runtime, progress, downloaded = format_item_as_row(
|
title, author, runtime, progress, downloaded = format_item_as_row(
|
||||||
item, self.library_client, self.download_manager
|
item, self.library_client, self.download_manager
|
||||||
)
|
)
|
||||||
table.add_row(title, author, runtime,
|
table.add_row(title, author, runtime, progress, downloaded, key=title)
|
||||||
progress, downloaded, key=title)
|
|
||||||
|
|
||||||
self.current_items = items
|
self.current_items = items
|
||||||
status = self.query_one("#status", Static)
|
status = self.query_one("#status", Static)
|
||||||
@@ -330,8 +325,7 @@ class Auditui(App):
|
|||||||
def action_play_selected(self) -> None:
|
def action_play_selected(self) -> None:
|
||||||
"""Start playing the selected book."""
|
"""Start playing the selected book."""
|
||||||
if not self.download_manager:
|
if not self.download_manager:
|
||||||
self.update_status(
|
self.update_status("Not authenticated. Please restart and authenticate.")
|
||||||
"Not authenticated. Please restart and authenticate.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
table = self.query_one(DataTable)
|
table = self.query_one(DataTable)
|
||||||
@@ -435,8 +429,7 @@ class Auditui(App):
|
|||||||
is_currently_finished = self.library_client.is_finished(selected_item)
|
is_currently_finished = self.library_client.is_finished(selected_item)
|
||||||
|
|
||||||
if is_currently_finished:
|
if is_currently_finished:
|
||||||
self.call_from_thread(self.update_status,
|
self.call_from_thread(self.update_status, "Already marked as finished")
|
||||||
"Already marked as finished")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
success = self.library_client.mark_as_finished(asin, selected_item)
|
success = self.library_client.mark_as_finished(asin, selected_item)
|
||||||
@@ -479,9 +472,9 @@ class Auditui(App):
|
|||||||
self._refresh_filtered_view()
|
self._refresh_filtered_view()
|
||||||
self.update_status("Filter cleared")
|
self.update_status("Filter cleared")
|
||||||
|
|
||||||
def _apply_filter(self, filter_text: str) -> None:
|
def _apply_filter(self, filter_text: str | None) -> None:
|
||||||
"""Apply the filter to the library."""
|
"""Apply the filter to the library."""
|
||||||
self.filter_text = filter_text
|
self.filter_text = filter_text or ""
|
||||||
self._refresh_filtered_view()
|
self._refresh_filtered_view()
|
||||||
|
|
||||||
def _refresh_filtered_view(self) -> None:
|
def _refresh_filtered_view(self) -> None:
|
||||||
@@ -492,11 +485,9 @@ class Auditui(App):
|
|||||||
items = self.all_items
|
items = self.all_items
|
||||||
|
|
||||||
if self.filter_text:
|
if self.filter_text:
|
||||||
items = filter_items(items, self.filter_text,
|
items = filter_items(items, self.filter_text, self._get_search_text)
|
||||||
self._get_search_text)
|
|
||||||
self._populate_table(items)
|
self._populate_table(items)
|
||||||
self.update_status(
|
self.update_status(f"Filter: '{self.filter_text}' ({len(items)} books)")
|
||||||
f"Filter: '{self.filter_text}' ({len(items)} books)")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
if not self.show_all_mode and self.library_client:
|
if not self.show_all_mode and self.library_client:
|
||||||
@@ -544,8 +535,7 @@ class Auditui(App):
|
|||||||
|
|
||||||
progress_info = self.query_one("#progress_info", Static)
|
progress_info = self.query_one("#progress_info", Static)
|
||||||
progress_bar = self.query_one("#progress_bar", ProgressBar)
|
progress_bar = self.query_one("#progress_bar", ProgressBar)
|
||||||
progress_bar_container = self.query_one(
|
progress_bar_container = self.query_one("#progress_bar_container", Horizontal)
|
||||||
"#progress_bar_container", Horizontal)
|
|
||||||
|
|
||||||
progress_percent = min(
|
progress_percent = min(
|
||||||
100.0, max(0.0, (chapter_elapsed / chapter_total) * 100.0)
|
100.0, max(0.0, (chapter_elapsed / chapter_total) * 100.0)
|
||||||
@@ -562,8 +552,7 @@ class Auditui(App):
|
|||||||
def _hide_progress(self) -> None:
|
def _hide_progress(self) -> None:
|
||||||
"""Hide the progress widget."""
|
"""Hide the progress widget."""
|
||||||
progress_info = self.query_one("#progress_info", Static)
|
progress_info = self.query_one("#progress_info", Static)
|
||||||
progress_bar_container = self.query_one(
|
progress_bar_container = self.query_one("#progress_bar_container", Horizontal)
|
||||||
"#progress_bar_container", Horizontal)
|
|
||||||
progress_info.display = False
|
progress_info.display = False
|
||||||
progress_bar_container.display = False
|
progress_bar_container.display = False
|
||||||
|
|
||||||
@@ -574,8 +563,7 @@ class Auditui(App):
|
|||||||
def action_toggle_download(self) -> None:
|
def action_toggle_download(self) -> None:
|
||||||
"""Toggle download/remove for the selected book."""
|
"""Toggle download/remove for the selected book."""
|
||||||
if not self.download_manager:
|
if not self.download_manager:
|
||||||
self.update_status(
|
self.update_status("Not authenticated. Please restart and authenticate.")
|
||||||
"Not authenticated. Please restart and authenticate.")
|
|
||||||
return
|
return
|
||||||
|
|
||||||
table = self.query_one(DataTable)
|
table = self.query_one(DataTable)
|
||||||
@@ -608,11 +596,9 @@ class Auditui(App):
|
|||||||
return
|
return
|
||||||
|
|
||||||
if self.download_manager.is_cached(asin):
|
if self.download_manager.is_cached(asin):
|
||||||
self.download_manager.remove_cached(
|
self.download_manager.remove_cached(asin, self._thread_status_update)
|
||||||
asin, self._thread_status_update)
|
|
||||||
else:
|
else:
|
||||||
self.download_manager.get_or_download(
|
self.download_manager.get_or_download(asin, self._thread_status_update)
|
||||||
asin, self._thread_status_update)
|
|
||||||
|
|
||||||
self.call_from_thread(self._refresh_table)
|
self.call_from_thread(self._refresh_table)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user