mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
remove copose idea
This commit is contained in:
@@ -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
|
||||
@@ -15,7 +15,6 @@ from typing import Any, Generator, Generic, Iterable, Iterator, Type, TypeVar, c
|
||||
from weakref import WeakSet, WeakValueDictionary
|
||||
|
||||
from ._ansi_sequences import SYNC_END, SYNC_START
|
||||
from ._compose import _compose
|
||||
from ._path import _make_path_object_relative
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
@@ -386,9 +385,6 @@ class App(Generic[ReturnType], DOMNode):
|
||||
return
|
||||
yield
|
||||
|
||||
def _compose(self) -> Iterable[Widget]:
|
||||
return _compose(self.compose())
|
||||
|
||||
def get_css_variables(self) -> dict[str, str]:
|
||||
"""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")
|
||||
|
||||
def _on_mount(self) -> None:
|
||||
widgets = self._compose()
|
||||
widgets = self.compose()
|
||||
if widgets:
|
||||
self.mount_all(widgets)
|
||||
|
||||
|
||||
@@ -18,7 +18,6 @@ from rich.text import Text
|
||||
from . import errors, events, messages
|
||||
from ._animator import BoundAnimator
|
||||
from ._arrange import DockArrangeResult, arrange
|
||||
from ._compose import _compose
|
||||
from ._context import active_app
|
||||
from ._layout import Layout
|
||||
from ._segment_tools import align_lines
|
||||
@@ -268,9 +267,6 @@ class Widget(DOMNode):
|
||||
return
|
||||
yield
|
||||
|
||||
def _compose(self) -> Iterable[Widget]:
|
||||
return _compose(self.compose())
|
||||
|
||||
def _post_register(self, app: App) -> None:
|
||||
"""Called when the instance is registered.
|
||||
|
||||
@@ -1456,7 +1452,7 @@ class Widget(DOMNode):
|
||||
await self.dispatch_key(event)
|
||||
|
||||
def _on_mount(self, event: events.Mount) -> None:
|
||||
widgets = self._compose()
|
||||
widgets = self.compose()
|
||||
self.mount(*widgets)
|
||||
self.screen.refresh(repaint=False, layout=True)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user