Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refreshing invisible widgets is a no-op #5063

Merged
merged 15 commits into from
Sep 30, 2024
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,23 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [0.81.1] - 2024-09-26

### Fixed

- Fixed issue with screen not updating when auto_refresh was enabled https://github.com/Textualize/textual/pull/5063

### Added

- Added `DOMNode.is_on_screen` property https://github.com/Textualize/textual/pull/5063

## [0.81.0] - 2024-09-25

### Added

- Added `x_axis` and `y_axis` parameters to `Widget.scroll_to_region` https://github.com/Textualize/textual/pull/5047
- Added `Tree.move_cursor_to_line` https://github.com/Textualize/textual/pull/5052
- Added `DOMNode.is_on_screen` property
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Duplicate line?


### Changed

Expand Down Expand Up @@ -2406,6 +2417,7 @@ https://textual.textualize.io/blog/2022/11/08/version-040/#version-040
- New handler system for messages that doesn't require inheritance
- Improved traceback handling

[0.81.1]: https://github.com/Textualize/textual/compare/v0.81.0...v0.81.1
[0.81.0]: https://github.com/Textualize/textual/compare/v0.80.1...v0.81.0
[0.80.1]: https://github.com/Textualize/textual/compare/v0.80.0...v0.80.1
[0.80.0]: https://github.com/Textualize/textual/compare/v0.79.0...v0.80.0
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "textual"
version = "0.81.0"
version = "0.81.1"
homepage = "https://github.com/Textualize/textual"
repository = "https://github.com/Textualize/textual"
documentation = "https://textual.textualize.io/"
Expand Down
7 changes: 1 addition & 6 deletions src/textual/_compositor.py
Original file line number Diff line number Diff line change
Expand Up @@ -311,9 +311,6 @@ def __init__(self) -> None:
# Mapping of line numbers on to lists of widget and regions
self._layers_visible: list[list[tuple[Widget, Region, Region]]] | None = None

# New widgets added between updates
self._new_widgets: set[Widget] = set()

def clear(self) -> None:
"""Remove all references to widgets (used when the screen closes)."""
self._full_map.clear()
Expand Down Expand Up @@ -392,8 +389,7 @@ def reflow(self, parent: Widget, size: Size) -> ReflowResult:
new_widgets = map.keys()

# Newly visible widgets
shown_widgets = (new_widgets - old_widgets) | self._new_widgets
self._new_widgets.clear()
shown_widgets = new_widgets - old_widgets

# Newly hidden widgets
hidden_widgets = self.widgets - widgets
Expand Down Expand Up @@ -490,7 +486,6 @@ def full_map(self) -> CompositorMap:
self._full_map_invalidated = False
map, _widgets = self._arrange_root(self.root, self.size, visible_only=False)
# Update any widgets which became visible in the interim
self._new_widgets.update(map.keys() - self._full_map.keys())
self._full_map = map
self._visible_widgets = None
self._visible_map = None
Expand Down
7 changes: 6 additions & 1 deletion src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,11 @@ def is_modal(self) -> bool:
"""Is the node a modal?"""
return False

@property
def is_on_screen(self) -> bool:
"""Check if the node was displayed in the last screen update."""
return False

def automatic_refresh(self) -> None:
"""Perform an automatic refresh.

Expand All @@ -497,7 +502,7 @@ def automatic_refresh(self) -> None:
during an automatic refresh.

"""
if self.display and self.visible:
if self.is_on_screen:
self.refresh()

def __init_subclass__(
Expand Down
11 changes: 7 additions & 4 deletions src/textual/screen.py
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ class Screen(Generic[ScreenResultType], Widget):

DEFAULT_CSS = """
Screen {

layout: vertical;
overflow-y: auto;
background: $surface;
Expand All @@ -162,11 +163,11 @@ class Screen(Generic[ScreenResultType], Widget):
background: ansi_default;
color: ansi_default;

&.-screen-suspended {
&.-screen-suspended {
text-style: dim;
ScrollBar {
text-style: not dim;
}
text-style: dim;
}
}
}
Expand Down Expand Up @@ -1124,8 +1125,10 @@ async def _on_update(self, message: messages.Update) -> None:
widget = message.widget
assert isinstance(widget, Widget)

self._dirty_widgets.add(widget)
self.check_idle()
compositor = self._compositor
if widget in compositor.widgets or widget in compositor.full_map:
self._dirty_widgets.add(widget)
self.check_idle()

async def _on_layout(self, message: messages.Layout) -> None:
message.stop()
Expand Down
9 changes: 9 additions & 0 deletions src/textual/widget.py
Original file line number Diff line number Diff line change
Expand Up @@ -1927,6 +1927,15 @@ def _has_relative_children_height(self) -> bool:
return True
return False

@property
def is_on_screen(self) -> bool:
"""Check if the node was displayed in the last screen update."""
try:
self.screen.find_widget(self)
except (NoScreen, errors.NoWidget):
return False
return True

def animate(
self,
attribute: str,
Expand Down
Loading
Loading