Skip to content

Commit

Permalink
Footer refactor.
Browse files Browse the repository at this point in the history
  • Loading branch information
joce committed Jan 9, 2024
1 parent c2f458f commit bc66428
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
27 changes: 27 additions & 0 deletions src/appui/_footer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
"""A simple footer with a clock, that can also have its bindings refreshed."""

from textual.app import ComposeResult
from textual.widgets import Footer as TextualFooter

from ._clock import Clock


class Footer(TextualFooter):
"""
The footer for the stockyard app.
This is required to be able to call the `refresh_bindings` method without
triggering pyright errors.
"""

def __init__(self) -> None:
super().__init__()
self._clock: Clock = Clock()

def compose(self) -> ComposeResult:
yield self._clock

def refresh_bindings(self) -> None:
"""Expose the binding refresh for the footer."""

self._bindings_changed(None)
25 changes: 5 additions & 20 deletions src/appui/stockyardapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@
from textual import work
from textual.app import App, ComposeResult
from textual.binding import BindingType
from textual.containers import Horizontal
from textual.css.query import NoMatches
from textual.logging import TextualHandler
from textual.widgets import Footer, LoadingIndicator
from textual.widgets import LoadingIndicator
from textual.worker import Worker

from yfinance import YFinance

from ._clock import Clock
from ._footer import Footer
from ._quote_table import QuoteTable
from .stockyardapp_state import StockyardAppState

Expand All @@ -45,19 +44,6 @@ class StockyardApp(App[None]):
("q", "exit", "Exit"),
]

class Footer(Footer):
"""
The footer for the stockyard app.
This is required to be able to call the `refresh_bindings` method without
triggering pyright errors.
"""

def refresh_bindings(self) -> None:
"""Expose the binding refresh for the footer."""

self._bindings_changed(None)

def __init__(self) -> None:
"""Initialize the app."""

Expand All @@ -68,13 +54,12 @@ def __init__(self) -> None:
self._priming_worker: Optional[Worker[None]] = None

# Widgets
self._footer: StockyardApp.Footer = StockyardApp.Footer()
self._clock: Clock = Clock()
self._footer: Footer = Footer()

@override
def compose(self) -> ComposeResult:
yield LoadingIndicator()
yield Horizontal(self._footer, self._clock, id="clock-footer")
yield self._footer

def on_unmount(self) -> None:
"""Handle unmount events."""
Expand Down Expand Up @@ -162,7 +147,7 @@ def _finish_loading(self) -> None:
logging.exception("No loading indicator found")

qt: QuoteTable = QuoteTable(self._state.quote_table_state)
self.mount(qt, before="#clock-footer")
self.mount(qt, before="Footer")

# Set the focus to the quote table
qt.focus()
Expand Down
5 changes: 0 additions & 5 deletions src/appui/stockyardapp.tcss
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,6 @@ LoadingIndicator {
height: 1fr;
}

#clock-footer {
height: 1;
dock: bottom;
}

QuoteTable {
height: 1fr;
}
Expand Down

0 comments on commit bc66428

Please sign in to comment.