fix: solve some mypy errors
This commit is contained in:
@@ -1,5 +1,9 @@
|
|||||||
"""Textual application for the Audible TUI."""
|
"""Textual application for the Audible TUI."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
from typing import TYPE_CHECKING
|
||||||
|
|
||||||
from textual import work
|
from textual import work
|
||||||
from textual.app import App, ComposeResult
|
from textual.app import App, ComposeResult
|
||||||
from textual.events import Key
|
from textual.events import Key
|
||||||
@@ -11,6 +15,10 @@ from .downloads import DownloadManager
|
|||||||
from .library import LibraryClient
|
from .library import LibraryClient
|
||||||
from .playback import PlaybackController
|
from .playback import PlaybackController
|
||||||
|
|
||||||
|
if TYPE_CHECKING:
|
||||||
|
from audible import Authenticator, Client
|
||||||
|
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."""
|
||||||
@@ -43,14 +51,14 @@ class Auditui(App):
|
|||||||
self.current_items: list = []
|
self.current_items: list = []
|
||||||
self.show_all_mode = False
|
self.show_all_mode = False
|
||||||
self.progress_sort_reverse = False
|
self.progress_sort_reverse = False
|
||||||
self.title_column_key = None
|
self.title_column_key: ColumnKey | None = None
|
||||||
self.progress_column_key = None
|
self.progress_column_key: ColumnKey | None = None
|
||||||
self.progress_column_index = 3
|
self.progress_column_index = 3
|
||||||
|
|
||||||
def compose(self) -> ComposeResult:
|
def compose(self) -> ComposeResult:
|
||||||
yield Header()
|
yield Header()
|
||||||
yield Static("Loading...", id="status")
|
yield Static("Loading...", id="status")
|
||||||
table = DataTable()
|
table: DataTable = DataTable()
|
||||||
table.zebra_stripes = True
|
table.zebra_stripes = True
|
||||||
table.cursor_type = "row"
|
table.cursor_type = "row"
|
||||||
yield table
|
yield table
|
||||||
@@ -68,7 +76,8 @@ class Auditui(App):
|
|||||||
self.update_status("Fetching library...")
|
self.update_status("Fetching library...")
|
||||||
self.fetch_library()
|
self.fetch_library()
|
||||||
else:
|
else:
|
||||||
self.update_status("Not authenticated. Please restart and authenticate.")
|
self.update_status(
|
||||||
|
"Not authenticated. Please restart and authenticate.")
|
||||||
|
|
||||||
self.set_interval(1.0, self._check_playback_status)
|
self.set_interval(1.0, self._check_playback_status)
|
||||||
|
|
||||||
@@ -103,7 +112,8 @@ class Auditui(App):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
all_items = self.library_client.fetch_all_items(self._thread_status_update)
|
all_items = self.library_client.fetch_all_items(
|
||||||
|
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))
|
||||||
@@ -181,13 +191,13 @@ class Auditui(App):
|
|||||||
def action_sort(self) -> None:
|
def action_sort(self) -> None:
|
||||||
"""Sort table by title in ascending order."""
|
"""Sort table by title in ascending order."""
|
||||||
table = self.query_one(DataTable)
|
table = self.query_one(DataTable)
|
||||||
if table.row_count > 0:
|
if table.row_count > 0 and self.title_column_key:
|
||||||
table.sort(self.title_column_key)
|
table.sort(self.title_column_key)
|
||||||
|
|
||||||
def action_reverse_sort(self) -> None:
|
def action_reverse_sort(self) -> None:
|
||||||
"""Sort table by title in descending order."""
|
"""Sort table by title in descending order."""
|
||||||
table = self.query_one(DataTable)
|
table = self.query_one(DataTable)
|
||||||
if table.row_count > 0:
|
if table.row_count > 0 and self.title_column_key:
|
||||||
table.sort(self.title_column_key, reverse=True)
|
table.sort(self.title_column_key, reverse=True)
|
||||||
|
|
||||||
def action_sort_by_progress(self) -> None:
|
def action_sort_by_progress(self) -> None:
|
||||||
@@ -218,7 +228,8 @@ 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("Not authenticated. Please restart and authenticate.")
|
self.update_status(
|
||||||
|
"Not authenticated. Please restart and authenticate.")
|
||||||
return
|
return
|
||||||
|
|
||||||
table = self.query_one(DataTable)
|
table = self.query_one(DataTable)
|
||||||
@@ -247,7 +258,8 @@ class Auditui(App):
|
|||||||
def action_toggle_playback(self) -> None:
|
def action_toggle_playback(self) -> None:
|
||||||
"""Toggle pause/resume state."""
|
"""Toggle pause/resume state."""
|
||||||
if not self.playback.toggle_playback():
|
if not self.playback.toggle_playback():
|
||||||
self.update_status("No playback active. Press Enter to play a book.")
|
self.update_status(
|
||||||
|
"No playback active. Press Enter to play a book.")
|
||||||
|
|
||||||
def _check_playback_status(self) -> None:
|
def _check_playback_status(self) -> None:
|
||||||
"""Check if playback process has finished and update state accordingly."""
|
"""Check if playback process has finished and update state accordingly."""
|
||||||
@@ -258,6 +270,8 @@ class Auditui(App):
|
|||||||
@work(exclusive=True, thread=True)
|
@work(exclusive=True, thread=True)
|
||||||
def _start_playback_async(self, asin: str) -> None:
|
def _start_playback_async(self, asin: str) -> None:
|
||||||
"""Start playback asynchronously."""
|
"""Start playback asynchronously."""
|
||||||
|
if not self.download_manager:
|
||||||
|
return
|
||||||
self.playback.prepare_and_start(
|
self.playback.prepare_and_start(
|
||||||
self.download_manager,
|
self.download_manager,
|
||||||
asin,
|
asin,
|
||||||
|
|||||||
Reference in New Issue
Block a user