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

don't refresh if not visible #4847

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Input cursor will no longer jump to the end on focus https://github.com/Textualize/textual/pull/4773
- Removed `Size.cip_size`, which was a clone of `crop_size`
- Widgets with auto dimensions will now grow if there is a scrollbar https://github.com/Textualize/textual/pull/4844
- Don't do automatic refresh when widget is not visible https://github.com/Textualize/textual/pull/4847
- Renamed `DOMNode._automatic_refresh` to `DOMNode.automatic_refresh` to allow for customization https://github.com/Textualize/textual/pull/4847

### Fixed

Expand Down
15 changes: 11 additions & 4 deletions src/textual/dom.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ def auto_refresh(self, interval: float | None) -> None:
self._auto_refresh_timer = None
if interval is not None:
self._auto_refresh_timer = self.set_interval(
interval, self._automatic_refresh, name=f"auto refresh {self!r}"
interval, self.automatic_refresh, name=f"auto refresh {self!r}"
)
self._auto_refresh = interval

Expand Down Expand Up @@ -476,9 +476,16 @@ def is_modal(self) -> bool:
"""Is the node a modal?"""
return False

def _automatic_refresh(self) -> None:
"""Perform an automatic refresh (set with auto_refresh property)."""
self.refresh()
def automatic_refresh(self) -> None:
"""Perform an automatic refresh.

This method is called when you set the `auto_refresh` attribute.
You could implement this method if you want to perform additional work
during an automatic refresh.

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

def __init_subclass__(
cls,
Expand Down
4 changes: 2 additions & 2 deletions tests/test_auto_refresh.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def on_mount(self):
self.start = time()
self.auto_refresh = 0.1

def _automatic_refresh(self):
def automatic_refresh(self):
self.count += 1
if self.count == 3:
self.exit(time() - self.start)
super()._automatic_refresh()
super().automatic_refresh()


def test_auto_refresh():
Expand Down
Loading