mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
Clean up various warnings in _footer.py
While visiting this for other reasons I noticed a number of warnings about the code that were easy to tidy up. So I tidied them up.
This commit is contained in:
@@ -1,14 +1,14 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
from typing import ClassVar
|
from typing import ClassVar, Optional
|
||||||
|
|
||||||
import rich.repr
|
import rich.repr
|
||||||
from rich.console import RenderableType
|
from rich.console import RenderableType
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
|
|
||||||
from .. import events
|
from .. import events
|
||||||
from ..reactive import Reactive
|
from ..reactive import reactive
|
||||||
from ..widget import Widget
|
from ..widget import Widget
|
||||||
|
|
||||||
|
|
||||||
@@ -53,23 +53,23 @@ class Footer(Widget):
|
|||||||
}
|
}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
highlight_key: Reactive[str | None] = Reactive(None)
|
highlight_key: reactive[str | None] = reactive[Optional[str]](None)
|
||||||
|
|
||||||
def __init__(self) -> None:
|
def __init__(self) -> None:
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self._key_text: Text | None = None
|
self._key_text: Text | None = None
|
||||||
self.auto_links = False
|
self.auto_links = False
|
||||||
|
|
||||||
async def watch_highlight_key(self, value: str | None) -> None:
|
async def watch_highlight_key(self) -> None:
|
||||||
"""If highlight key changes we need to regenerate the text."""
|
"""If highlight key changes we need to regenerate the text."""
|
||||||
self._key_text = None
|
self._key_text = None
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
def _on_mount(self) -> None:
|
def _on_mount(self, _: events.Mount) -> None:
|
||||||
self.watch(self.screen, "focused", self._bindings_changed)
|
self.watch(self.screen, "focused", self._bindings_changed)
|
||||||
self.watch(self.screen, "stack_updates", self._bindings_changed)
|
self.watch(self.screen, "stack_updates", self._bindings_changed)
|
||||||
|
|
||||||
def _bindings_changed(self, focused: Widget | None) -> None:
|
def _bindings_changed(self, _: Widget | None) -> None:
|
||||||
self._key_text = None
|
self._key_text = None
|
||||||
self.refresh()
|
self.refresh()
|
||||||
|
|
||||||
@@ -77,7 +77,7 @@ class Footer(Widget):
|
|||||||
"""Store any key we are moving over."""
|
"""Store any key we are moving over."""
|
||||||
self.highlight_key = event.style.meta.get("key")
|
self.highlight_key = event.style.meta.get("key")
|
||||||
|
|
||||||
def _on_leave(self, event: events.Leave) -> None:
|
def _on_leave(self, _: events.Leave) -> None:
|
||||||
"""Clear any highlight when the mouse leaves the widget"""
|
"""Clear any highlight when the mouse leaves the widget"""
|
||||||
if self.screen.is_current:
|
if self.screen.is_current:
|
||||||
self.highlight_key = None
|
self.highlight_key = None
|
||||||
@@ -101,7 +101,7 @@ class Footer(Widget):
|
|||||||
|
|
||||||
bindings = [
|
bindings = [
|
||||||
binding
|
binding
|
||||||
for (_namespace, binding) in self.app.namespace_bindings.values()
|
for (_, binding) in self.app.namespace_bindings.values()
|
||||||
if binding.show
|
if binding.show
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ class Footer(Widget):
|
|||||||
for binding in bindings:
|
for binding in bindings:
|
||||||
action_to_bindings[binding.action].append(binding)
|
action_to_bindings[binding.action].append(binding)
|
||||||
|
|
||||||
for action, bindings in action_to_bindings.items():
|
for _, bindings in action_to_bindings.items():
|
||||||
binding = bindings[0]
|
binding = bindings[0]
|
||||||
if binding.key_display is None:
|
if binding.key_display is None:
|
||||||
key_display = self.app.get_key_display(binding.key)
|
key_display = self.app.get_key_display(binding.key)
|
||||||
|
|||||||
Reference in New Issue
Block a user