mirror of
https://github.com/Textualize/textual.git
synced 2025-10-17 02:38:12 +03:00
batch update fix, and optimization
This commit is contained in:
@@ -6,6 +6,12 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
|||||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
|
||||||
|
## [0.12.1] - 2023-02-25
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fix for batch updates
|
||||||
|
|
||||||
## [0.12.0] - 2023-02-24
|
## [0.12.0] - 2023-02-24
|
||||||
|
|
||||||
### Added
|
### Added
|
||||||
|
|||||||
@@ -8,10 +8,10 @@ from rich.segment import Segment
|
|||||||
from rich.style import Style
|
from rich.style import Style
|
||||||
|
|
||||||
from ._border import get_box, render_row
|
from ._border import get_box, render_row
|
||||||
from .filter import LineFilter
|
|
||||||
from ._opacity import _apply_opacity
|
from ._opacity import _apply_opacity
|
||||||
from ._segment_tools import line_pad, line_trim
|
from ._segment_tools import line_pad, line_trim
|
||||||
from .color import Color
|
from .color import Color
|
||||||
|
from .filter import LineFilter
|
||||||
from .geometry import Region, Size, Spacing
|
from .geometry import Region, Size, Spacing
|
||||||
from .renderables.text_opacity import TextOpacity
|
from .renderables.text_opacity import TextOpacity
|
||||||
from .renderables.tint import Tint
|
from .renderables.tint import Tint
|
||||||
@@ -120,13 +120,12 @@ class StylesCache:
|
|||||||
)
|
)
|
||||||
if widget.auto_links:
|
if widget.auto_links:
|
||||||
hover_style = widget.hover_style
|
hover_style = widget.hover_style
|
||||||
link_hover_style = widget.link_hover_style
|
|
||||||
if (
|
if (
|
||||||
link_hover_style
|
hover_style._link_id
|
||||||
and hover_style._link_id
|
|
||||||
and hover_style._meta
|
and hover_style._meta
|
||||||
and "@click" in hover_style.meta
|
and "@click" in hover_style.meta
|
||||||
):
|
):
|
||||||
|
link_hover_style = widget.link_hover_style
|
||||||
if link_hover_style:
|
if link_hover_style:
|
||||||
strips = [
|
strips = [
|
||||||
strip.style_links(hover_style.link_id, link_hover_style)
|
strip.style_links(hover_style.link_id, link_hover_style)
|
||||||
|
|||||||
@@ -460,10 +460,6 @@ class App(Generic[ReturnType], DOMNode):
|
|||||||
self._batch_count -= 1
|
self._batch_count -= 1
|
||||||
assert self._batch_count >= 0, "This won't happen if you use `batch_update`"
|
assert self._batch_count >= 0, "This won't happen if you use `batch_update`"
|
||||||
if not self._batch_count:
|
if not self._batch_count:
|
||||||
try:
|
|
||||||
self.screen.check_idle()
|
|
||||||
except ScreenStackError:
|
|
||||||
pass
|
|
||||||
self.check_idle()
|
self.check_idle()
|
||||||
|
|
||||||
def animate(
|
def animate(
|
||||||
|
|||||||
@@ -9,8 +9,8 @@ from rich.segment import Segment
|
|||||||
from rich.style import Style, StyleType
|
from rich.style import Style, StyleType
|
||||||
|
|
||||||
from ._cache import FIFOCache
|
from ._cache import FIFOCache
|
||||||
from .filter import LineFilter
|
|
||||||
from ._segment_tools import index_to_cell_position
|
from ._segment_tools import index_to_cell_position
|
||||||
|
from .filter import LineFilter
|
||||||
|
|
||||||
|
|
||||||
@rich.repr.auto
|
@rich.repr.auto
|
||||||
@@ -29,6 +29,7 @@ class Strip:
|
|||||||
"_cell_length",
|
"_cell_length",
|
||||||
"_divide_cache",
|
"_divide_cache",
|
||||||
"_crop_cache",
|
"_crop_cache",
|
||||||
|
"_link_ids",
|
||||||
]
|
]
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@@ -38,6 +39,7 @@ class Strip:
|
|||||||
self._cell_length = cell_length
|
self._cell_length = cell_length
|
||||||
self._divide_cache: FIFOCache[tuple[int, ...], list[Strip]] = FIFOCache(4)
|
self._divide_cache: FIFOCache[tuple[int, ...], list[Strip]] = FIFOCache(4)
|
||||||
self._crop_cache: FIFOCache[tuple[int, int], Strip] = FIFOCache(4)
|
self._crop_cache: FIFOCache[tuple[int, int], Strip] = FIFOCache(4)
|
||||||
|
self._link_ids: set[str] | None = None
|
||||||
|
|
||||||
def __rich_repr__(self) -> rich.repr.Result:
|
def __rich_repr__(self) -> rich.repr.Result:
|
||||||
yield self._segments
|
yield self._segments
|
||||||
@@ -48,6 +50,15 @@ class Strip:
|
|||||||
"""Segment text."""
|
"""Segment text."""
|
||||||
return "".join(segment.text for segment in self._segments)
|
return "".join(segment.text for segment in self._segments)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def link_ids(self) -> set[str]:
|
||||||
|
"""A set of the link ids in this Strip."""
|
||||||
|
if self._link_ids is None:
|
||||||
|
self._link_ids = {
|
||||||
|
style._link_id for _, style, _ in self._segments if style is not None
|
||||||
|
}
|
||||||
|
return self._link_ids
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def blank(cls, cell_length: int, style: StyleType | None = None) -> Strip:
|
def blank(cls, cell_length: int, style: StyleType | None = None) -> Strip:
|
||||||
"""Create a blank strip.
|
"""Create a blank strip.
|
||||||
@@ -230,19 +241,18 @@ class Strip:
|
|||||||
Returns:
|
Returns:
|
||||||
New strip (or same Strip if no changes).
|
New strip (or same Strip if no changes).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
_Segment = Segment
|
_Segment = Segment
|
||||||
if not any(
|
if link_id not in self.link_ids:
|
||||||
segment.style._link_id == link_id
|
|
||||||
for segment in self._segments
|
|
||||||
if segment.style
|
|
||||||
):
|
|
||||||
return self
|
return self
|
||||||
segments = [
|
segments = [
|
||||||
_Segment(
|
_Segment(
|
||||||
text,
|
text,
|
||||||
|
(
|
||||||
(style + link_style if style is not None else None)
|
(style + link_style if style is not None else None)
|
||||||
if (style and not style._null and style._link_id == link_id)
|
if (style and not style._null and style._link_id == link_id)
|
||||||
else style,
|
else style
|
||||||
|
),
|
||||||
control,
|
control,
|
||||||
)
|
)
|
||||||
for text, style, control in self._segments
|
for text, style, control in self._segments
|
||||||
|
|||||||
Reference in New Issue
Block a user