Skip to content

Commit beb4461

Browse files
authored
Merge pull request #4847 from Textualize/auto-refresh
don't refresh if not visible
2 parents c1fb5df + 81667a4 commit beb4461

File tree

3 files changed

+15
-6
lines changed

3 files changed

+15
-6
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
1212
- Input cursor will no longer jump to the end on focus https://github.com/Textualize/textual/pull/4773
1313
- Removed `Size.cip_size`, which was a clone of `crop_size`
1414
- Widgets with auto dimensions will now grow if there is a scrollbar https://github.com/Textualize/textual/pull/4844
15+
- Don't do automatic refresh when widget is not visible https://github.com/Textualize/textual/pull/4847
16+
- Renamed `DOMNode._automatic_refresh` to `DOMNode.automatic_refresh` to allow for customization https://github.com/Textualize/textual/pull/4847
1517

1618
### Fixed
1719

src/textual/dom.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def auto_refresh(self, interval: float | None) -> None:
414414
self._auto_refresh_timer = None
415415
if interval is not None:
416416
self._auto_refresh_timer = self.set_interval(
417-
interval, self._automatic_refresh, name=f"auto refresh {self!r}"
417+
interval, self.automatic_refresh, name=f"auto refresh {self!r}"
418418
)
419419
self._auto_refresh = interval
420420

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

479-
def _automatic_refresh(self) -> None:
480-
"""Perform an automatic refresh (set with auto_refresh property)."""
481-
self.refresh()
479+
def automatic_refresh(self) -> None:
480+
"""Perform an automatic refresh.
481+
482+
This method is called when you set the `auto_refresh` attribute.
483+
You could implement this method if you want to perform additional work
484+
during an automatic refresh.
485+
486+
"""
487+
if self.display and self.visible:
488+
self.refresh()
482489

483490
def __init_subclass__(
484491
cls,

tests/test_auto_refresh.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@ def on_mount(self):
1414
self.start = time()
1515
self.auto_refresh = 0.1
1616

17-
def _automatic_refresh(self):
17+
def automatic_refresh(self):
1818
self.count += 1
1919
if self.count == 3:
2020
self.exit(time() - self.start)
21-
super()._automatic_refresh()
21+
super().automatic_refresh()
2222

2323

2424
def test_auto_refresh():

0 commit comments

Comments
 (0)