don't refresh if not visible

This commit is contained in:
Will McGugan
2024-08-06 10:45:07 +01:00
parent f4cfbc8299
commit 6de3f101d6
2 changed files with 13 additions and 6 deletions

View File

@@ -414,7 +414,7 @@ class DOMNode(MessagePump):
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
@@ -476,9 +476,16 @@ class DOMNode(MessagePump):
"""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,

View File

@@ -14,11 +14,11 @@ class RefreshApp(App[float]):
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():