Apply suggestions from code review

Co-authored-by: darrenburns <darrenburns@users.noreply.github.com>
This commit is contained in:
Will McGugan
2022-08-26 10:58:17 +01:00
committed by GitHub
parent 732af87936
commit f7d8c6ad4a
7 changed files with 13 additions and 13 deletions

View File

@@ -335,7 +335,7 @@ If you run "stopwatch04.py" now you will be able to toggle between the two state
## Reactive attributes
A reoccurring theme in Textual is that you rarely need to explicitly update a widget. It is possible: you can call [`refresh()`][textual.widget.Widget.refresh] to display new data. However, Textual prefers to do this automatically via _reactive_ attributes.
A recurring theme in Textual is that you rarely need to explicitly update a widget. It is possible: you can call [`refresh()`][textual.widget.Widget.refresh] to display new data. However, Textual prefers to do this automatically via _reactive_ attributes.
You can declare a reactive attribute with `textual.reactive.Reactive`. Let's use this feature to create a timer that displays elapsed time and keeps it updated.
@@ -343,7 +343,7 @@ You can declare a reactive attribute with `textual.reactive.Reactive`. Let's use
--8<-- "docs/examples/introduction/stopwatch05.py"
```
We have added two reactive attributes: `start_time` will contain the time in seconds when the stopwatch was started, and `time` will contain time to be displayed on the Stopwatch.
We have added two reactive attributes: `start_time` will contain the time in seconds when the stopwatch was started, and `time` will contain the time to be displayed on the Stopwatch.
Both attributes will be available on `self` as if you had assigned them in `__init__`. If you write to either of these attributes the widget will update automatically.
@@ -358,7 +358,7 @@ The `time` attribute has a simple float as the default value, so `self.time` wil
!!! info
The `time` attribute is created with `Reactive.init` which calls watch methods when the widget is mounted. See below for an explanation of watch methods.
The `time` attribute is created with `Reactive.init` which calls _watch methods_ when the widget is mounted. See below for an explanation of watch methods.
In the `on_mount` method the call to `set_interval` creates a timer object which runs `self.update_time` sixty times a second. This `update_time` method calculates the time elapsed since the widget started and assigns it to `self.time`. Which brings us to one of Reactive's super-powers.
@@ -371,7 +371,7 @@ The end result is that the `Stopwatch` widgets show the time elapsed since the w
```{.textual path="docs/examples/introduction/stopwatch05.py" title="stopwatch05.py"}
```
We've seen how we can update widgets with a timer. But we still need to wire up the buttons so we can operate Stopwatches independently.
We've seen how we can update widgets with a timer, but we still need to wire up the buttons so we can operate Stopwatches independently.
### Wiring buttons

View File

@@ -138,7 +138,7 @@ class App(Generic[ReturnType], DOMNode):
driver_class (Type[Driver] | None, optional): Driver class or ``None`` to auto-detect. Defaults to None.
log_path (str | PurePath, optional): Path to log file, or "" to disable. Defaults to "".
log_verbosity (int, optional): Log verbosity from 0-3. Defaults to 1.
title (str, optional): Default title of the application. Defaults to "Textual Application".
title (str | None, optional): Title of the application. If ``None``, the title is set to the name of the ``App`` subclass. Defaults to ``None``.
css_path (str | PurePath | None, optional): Path to CSS or ``None`` for no CSS file. Defaults to None.
watch_css (bool, optional): Watch CSS for changes. Defaults to False.
@@ -476,7 +476,7 @@ class App(Generic[ReturnType], DOMNode):
"""Get the size of the terminal.
Returns:
Size: SIze of the terminal
Size: Size of the terminal
"""
return Size(*self.console.size)
@@ -618,7 +618,7 @@ class App(Generic[ReturnType], DOMNode):
to run forever. Defaults to None.
headless (bool, optional): Run in "headless" mode (don't write to stdout).
press (str, optional): An iterable of keys to simulate being pressed.
screenshot (str, optional): Take a screenshot after pressing keys (svg data stored in self._screenshot). Defaults to False.
screenshot (bool, optional): Take a screenshot after pressing keys (svg data stored in self._screenshot). Defaults to False.
screenshot_title (str | None, optional): Title of screenshot, or None to use App title. Defaults to None.
Returns:

View File

@@ -314,7 +314,7 @@ class DOMNode(MessagePump):
@property
def display(self) -> bool:
"""
Check if this widget should display or note.
Check if this widget should display or not.
Returns:
bool: ``True`` if this DOMNode is displayed (``display != "none"``) otherwise ``False`` .

View File

@@ -214,7 +214,7 @@ class MessagePump(metaclass=MessagePumpMeta):
Args:
delay (float): Time to wait before invoking callback.
callback (TimerCallback | None, optional): Callback to call after time has expired.. Defaults to None.
callback (TimerCallback | None, optional): Callback to call after time has expired. Defaults to None.
name (str | None, optional): Name of the timer (for debug). Defaults to None.
pause (bool, optional): Start timer paused. Defaults to False.

View File

@@ -70,7 +70,7 @@ class Reactive(Generic[ReactiveType]):
repaint (bool, optional): Perform a repaint on change. Defaults to True.
Returns:
Reactive: _description_
Reactive: A Reactive instance which calls watchers or initialize.
"""
return cls(default, layout=layout, repaint=repaint, init=True)

View File

@@ -41,7 +41,7 @@ class Timer:
sender (MessageTarget): The sender of the event.
name (str | None, optional): A name to assign the event (for debugging). Defaults to None.
callback (TimerCallback | None, optional): A optional callback to invoke when the event is handled. Defaults to None.
repeat (int | None, optional): The number of times to repeat the timer, or None for no repeat. Defaults to None.
repeat (int | None, optional): The number of times to repeat the timer, or None to repeat forever. Defaults to None.
skip (bool, optional): Enable skipping of scheduled events that couldn't be sent in time. Defaults to True.
pause (bool, optional): Start the timer paused. Defaults to False.
"""

View File

@@ -189,7 +189,7 @@ class Widget(DOMNode):
@property
def _allow_scroll(self) -> bool:
"""Check if both axis may be scrolled.
"""Check if both axes may be scrolled.
Returns:
bool: True if horizontal and vertical scrolling is enabled.
@@ -668,7 +668,7 @@ class Widget(DOMNode):
@property
def _focus_sort_key(self) -> tuple[int, int]:
"""Key function to sort widgets in to tfocus order."""
"""Key function to sort widgets in to focus order."""
x, y, _, _ = self.virtual_region
top, _, _, left = self.styles.margin
return y - top, x - left