Skip to content

Commit d426e69

Browse files
committed
update protocol definition and docs
1 parent 021e8a7 commit d426e69

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

src/textual/visual.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,17 +37,27 @@ def is_visual(obj: object) -> bool:
3737

3838

3939
# Note: not runtime checkable currently, as I've found that to be slow
40-
class SupportsTextualize(Protocol):
40+
class SupportsVisual(Protocol):
4141
"""An object that supports the textualize protocol."""
4242

43-
def textualize(self, obj: object) -> Visual | None: ...
43+
def visualize(self, widget: Widget, obj: object) -> Visual | None:
44+
"""Convert the result of a Widget.render() call in to a Visual, using the Visual protocol.
45+
46+
Args:
47+
widget: The widget that generated the render.
48+
obj: The result of the the render.
49+
50+
Returns:
51+
A Visual instance, or `None` if it wasn't possible.
52+
53+
"""
4454

4555

4656
class VisualError(Exception):
4757
"""An error with the visual protocol."""
4858

4959

50-
VisualType: TypeAlias = "RenderableType | SupportsTextualize | Visual"
60+
VisualType: TypeAlias = "RenderableType | SupportsVisual | Visual"
5161

5262

5363
def visualize(widget: Widget, obj: object) -> Visual:

src/textual/widgets/_static.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
from textual.app import RenderResult
1111

1212
from textual.errors import RenderError
13-
from textual.visual import SupportsTextualize, Visual, visualize
13+
from textual.visual import SupportsVisual, Visual, visualize
1414
from textual.widget import Widget
1515

1616

@@ -50,11 +50,11 @@ class Static(Widget, inherit_bindings=False):
5050
}
5151
"""
5252

53-
_renderable: RenderableType | SupportsTextualize
53+
_renderable: RenderableType | SupportsVisual
5454

5555
def __init__(
5656
self,
57-
content: RenderableType | SupportsTextualize = "",
57+
content: RenderableType | SupportsVisual = "",
5858
*,
5959
expand: bool = False,
6060
shrink: bool = False,
@@ -78,11 +78,11 @@ def visual(self) -> Visual:
7878
return self._visual
7979

8080
@property
81-
def renderable(self) -> RenderableType | SupportsTextualize:
81+
def renderable(self) -> RenderableType | SupportsVisual:
8282
return self._content or ""
8383

8484
@renderable.setter
85-
def renderable(self, renderable: RenderableType | SupportsTextualize) -> None:
85+
def renderable(self, renderable: RenderableType | SupportsVisual) -> None:
8686
if isinstance(renderable, str):
8787
if self.markup:
8888
self._renderable = Text.from_markup(renderable)
@@ -101,7 +101,7 @@ def render(self) -> RenderResult:
101101
"""
102102
return self.visual
103103

104-
def update(self, content: RenderableType | SupportsTextualize = "") -> None:
104+
def update(self, content: RenderableType | SupportsVisual = "") -> None:
105105
"""Update the widget's content area with new text or Rich renderable.
106106
107107
Args:

0 commit comments

Comments
 (0)