Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up various warnings in _footer.py #2328

Merged
merged 1 commit into from
Apr 19, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/textual/widgets/_footer.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
from __future__ import annotations

from collections import defaultdict
from typing import ClassVar
from typing import ClassVar, Optional

import rich.repr
from rich.console import RenderableType
from rich.text import Text

from .. import events
from ..reactive import Reactive
from ..reactive import reactive
from ..widget import Widget


Expand Down Expand Up @@ -53,31 +53,31 @@ class Footer(Widget):
}
"""

highlight_key: Reactive[str | None] = Reactive(None)
highlight_key: reactive[str | None] = reactive[Optional[str]](None)

def __init__(self) -> None:
super().__init__()
self._key_text: Text | None = None
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."""
self._key_text = None
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, "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.refresh()

def _on_mouse_move(self, event: events.MouseMove) -> None:
"""Store any key we are moving over."""
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"""
if self.screen.is_current:
self.highlight_key = None
Expand All @@ -101,15 +101,15 @@ def _make_key_text(self) -> Text:

bindings = [
binding
for (_namespace, binding) in self.app.namespace_bindings.values()
for (_, binding) in self.app.namespace_bindings.values()
if binding.show
]

action_to_bindings = defaultdict(list)
for binding in bindings:
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]
if binding.key_display is None:
key_display = self.app.get_key_display(binding.key)
Expand Down