remove copose idea

This commit is contained in:
Will McGugan
2022-09-06 10:23:28 +01:00
parent e8a4f2e806
commit f1a8c74649
3 changed files with 2 additions and 54 deletions

View File

@@ -1,44 +0,0 @@
from __future__ import annotations
from types import GeneratorType
from typing import TYPE_CHECKING, Iterable
if TYPE_CHECKING:
from .app import ComposeResult
from .widget import Widget
def _compose(compose_result: ComposeResult) -> Iterable[Widget]:
"""Turns a compose result in to an iterable of Widgets.
If `compose_result` is a generator, this will run the generator and send
back the yielded widgets. This allows you to write code such as this:
```python
yes = yield Button("Yes")
yes.variant = "success"
```
Otherwise `compose_result` is assumed to already be an iterable of Widgets
and will be returned unmodified.
Args:
compose_result (ComposeResult): Either an iterator of widgets,
or a generator.
Returns:
Iterable[Widget]: An iterable if widgets.
"""
if isinstance(compose_result, GeneratorType):
try:
widget = next(compose_result)
send = compose_result.send
while True:
yield widget
widget = send(widget)
except StopIteration:
pass
else:
yield from compose_result

View File

@@ -15,7 +15,6 @@ from typing import Any, Generator, Generic, Iterable, Iterator, Type, TypeVar, c
from weakref import WeakSet, WeakValueDictionary from weakref import WeakSet, WeakValueDictionary
from ._ansi_sequences import SYNC_END, SYNC_START from ._ansi_sequences import SYNC_END, SYNC_START
from ._compose import _compose
from ._path import _make_path_object_relative from ._path import _make_path_object_relative
if sys.version_info >= (3, 8): if sys.version_info >= (3, 8):
@@ -386,9 +385,6 @@ class App(Generic[ReturnType], DOMNode):
return return
yield yield
def _compose(self) -> Iterable[Widget]:
return _compose(self.compose())
def get_css_variables(self) -> dict[str, str]: def get_css_variables(self) -> dict[str, str]:
"""Get a mapping of variables used to pre-populate CSS. """Get a mapping of variables used to pre-populate CSS.
@@ -1149,7 +1145,7 @@ class App(Generic[ReturnType], DOMNode):
self.set_timer(screenshot_timer, on_screenshot, name="screenshot timer") self.set_timer(screenshot_timer, on_screenshot, name="screenshot timer")
def _on_mount(self) -> None: def _on_mount(self) -> None:
widgets = self._compose() widgets = self.compose()
if widgets: if widgets:
self.mount_all(widgets) self.mount_all(widgets)

View File

@@ -18,7 +18,6 @@ from rich.text import Text
from . import errors, events, messages from . import errors, events, messages
from ._animator import BoundAnimator from ._animator import BoundAnimator
from ._arrange import DockArrangeResult, arrange from ._arrange import DockArrangeResult, arrange
from ._compose import _compose
from ._context import active_app from ._context import active_app
from ._layout import Layout from ._layout import Layout
from ._segment_tools import align_lines from ._segment_tools import align_lines
@@ -268,9 +267,6 @@ class Widget(DOMNode):
return return
yield yield
def _compose(self) -> Iterable[Widget]:
return _compose(self.compose())
def _post_register(self, app: App) -> None: def _post_register(self, app: App) -> None:
"""Called when the instance is registered. """Called when the instance is registered.
@@ -1456,7 +1452,7 @@ class Widget(DOMNode):
await self.dispatch_key(event) await self.dispatch_key(event)
def _on_mount(self, event: events.Mount) -> None: def _on_mount(self, event: events.Mount) -> None:
widgets = self._compose() widgets = self.compose()
self.mount(*widgets) self.mount(*widgets)
self.screen.refresh(repaint=False, layout=True) self.screen.refresh(repaint=False, layout=True)