docstrings

This commit is contained in:
Will McGugan
2022-05-04 11:02:33 +01:00
parent a2da5546bd
commit 4337da8019
2 changed files with 27 additions and 7 deletions

View File

@@ -239,6 +239,9 @@ class App(Generic[ReturnType], DOMNode):
Args:
direction (int, optional): 1 to move forward, -1 to move backward, or
0 to highlight the current focus.
Returns:
Widget | None: Newly focused widget, or None for no focus.
"""
if self._focus_timer:
# Cancel the timer that clears the show focus class
@@ -270,19 +273,36 @@ class App(Generic[ReturnType], DOMNode):
return self.focused
def show_focus(self) -> Widget | None:
"""Highlight the currently focused widget."""
"""Highlight the currently focused widget.
Returns:
Widget | None: Focused widget, or None for no focus.
"""
return self._move_focus(0)
def focus_next(self) -> Widget | None:
"""Focus the next widget."""
"""Focus the next widget.
Returns:
Widget | None: Newly focused widget, or None for no focus.
"""
return self._move_focus(1)
def focus_previous(self) -> Widget | None:
"""Focus the previous widget."""
"""Focus the previous widget.
Returns:
Widget | None: Newly focused widget, or None for no focus.
"""
return self._move_focus(-1)
def hide_focus(self) -> None:
"""Hide the focus."""
"""Hide the focus.
Returns:
Widget | None: Newly focused widget, or None for no focus.
"""
self.remove_class("-show-focus")
def compose(self) -> ComposeResult:

View File

@@ -11,7 +11,7 @@ class NonFocusable(Widget, can_focus=False):
pass
def test_focus_chain():
async def test_focus_chain():
app = App()
app.push_screen(Screen())
@@ -31,7 +31,7 @@ def test_focus_chain():
assert focused == ["foo", "Paul", "baz"]
def test_show_focus():
async def test_show_focus():
app = App()
app.push_screen(Screen())
app.screen.add_children(
@@ -51,7 +51,7 @@ def test_show_focus():
assert app.has_class("-show-focus")
def test_focus_next_and_previous():
async def test_focus_next_and_previous():
app = App()
app.push_screen(Screen())