Inline some properties, pull condition outside loop

This commit is contained in:
Darren Burns
2022-09-15 12:19:05 +01:00
parent d632091d93
commit 0762fff6bf
3 changed files with 21 additions and 19 deletions

View File

@@ -41,7 +41,7 @@ One such event is the *mount* event which is sent to an application after it ent
!!! info !!! info
You may have noticed we use the term "send" and "sent" in relation to event handler methods in preference to "calling". This is because Textual uses a message passing system where events are passed (or *sent*) between components. We will cover the details in [events][./events.md]. You may have noticed we use the term "send" and "sent" in relation to event handler methods in preference to "calling". This is because Textual uses a message passing system where events are passed (or *sent*) between components. We will cover the details in [events](./events.md).
Another such event is the *key* event which is sent when the user presses a key. The following example contains handlers for both those events: Another such event is the *key* event which is sent when the user presses a key. The following example contains handlers for both those events:
@@ -80,7 +80,7 @@ Widgets are self-contained components responsible for generating the output for
Widgets can be as simple as a piece of text, a button, or a fully-fledge component like a text editor or file browser (which may contain widgets of their own). Widgets can be as simple as a piece of text, a button, or a fully-fledge component like a text editor or file browser (which may contain widgets of their own).
### Composing ### Composing
To add widgets to your app implement a [`compose()`][textual.app.App.compose] method which should return a iterable of Widget instances. A list would work, but it is convenient to yield widgets, making the method a *generator*. To add widgets to your app implement a [`compose()`][textual.app.App.compose] method which should return a iterable of Widget instances. A list would work, but it is convenient to yield widgets, making the method a *generator*.
@@ -103,7 +103,7 @@ While composing is the preferred way of adding widgets when your app starts it i
Here's an app which adds the welcome widget in response to any key press: Here's an app which adds the welcome widget in response to any key press:
```python title="widgets02.py" ```python title="widgets02.py"
--8<-- "docs/examples/app/widgets02.py" --8<-- "docs/examples/app/widgets02.py"
``` ```
@@ -118,7 +118,7 @@ An app will run until you call [App.exit()][textual.app.App.exit] which will exi
The exit method will also accept an optional positional value to be returned by `run()`. The following example uses this to return the `id` (identifier) of a clicked button. The exit method will also accept an optional positional value to be returned by `run()`. The following example uses this to return the `id` (identifier) of a clicked button.
```python title="question01.py" ```python title="question01.py"
--8<-- "docs/examples/app/question01.py" --8<-- "docs/examples/app/question01.py"
``` ```
@@ -159,7 +159,7 @@ The following example sets the `css_path` attribute on the app:
If the path is relative (as it is above) then it is taken as relative to where the app is defined. Hence this example references `"question01.css"` in the same directory as the Python code. Here is that CSS file: If the path is relative (as it is above) then it is taken as relative to where the app is defined. Hence this example references `"question01.css"` in the same directory as the Python code. Here is that CSS file:
```sass title="question02.css" ```sass title="question02.css"
--8<-- "docs/examples/app/question02.css" --8<-- "docs/examples/app/question02.css"
``` ```

View File

@@ -608,8 +608,9 @@ class Compositor:
"""Return True if the widget is (literally) visible by examining various """Return True if the widget is (literally) visible by examining various
properties which affect whether it can be seen or not.""" properties which affect whether it can be seen or not."""
return ( return (
widget.visible widget.styles.visibility != "hidden"
and not widget.is_transparent and not widget.is_scrollable
and widget.styles.background.is_transparent
and widget.styles.opacity > 0 and widget.styles.opacity > 0
) )

View File

@@ -60,24 +60,25 @@ class TextOpacity:
""" """
_Segment = Segment _Segment = Segment
for segment in segments: _from_color = Style.from_color
text, style, control = segment if opacity == 0:
if not style: for text, style, control in segments:
yield segment invisible_style = _from_color(bgcolor=style.bgcolor)
continue yield _Segment(cell_len(text) * " ", invisible_style)
else:
for segment in segments:
text, style, control = segment
if not style:
yield segment
continue
color = style.color color = style.color
bgcolor = style.bgcolor bgcolor = style.bgcolor
if opacity > 0:
if color and color.triplet and bgcolor and bgcolor.triplet: if color and color.triplet and bgcolor and bgcolor.triplet:
color_style = _get_blended_style_cached(bgcolor, color, opacity) color_style = _get_blended_style_cached(bgcolor, color, opacity)
yield _Segment(text, style + color_style) yield _Segment(text, style + color_style)
else: else:
yield segment yield segment
else:
empty_text = cell_len(text) * " "
yield _Segment(empty_text, Style.from_color(bgcolor=bgcolor))
def __rich_console__( def __rich_console__(
self, console: Console, options: ConsoleOptions self, console: Console, options: ConsoleOptions