Skip to content

Commit 6de3f10

Browse files
committed
don't refresh if not visible
1 parent f4cfbc8 commit 6de3f10

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

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)