From 0987dc5a7a611747eddbad73b302e416d8e23ace Mon Sep 17 00:00:00 2001 From: Olivier Gayot Date: Mon, 18 Mar 2024 14:25:20 +0100 Subject: [PATCH] spinner: add the ability to redraw after spinning Every time a spinner "spins", it changes its visual representation. In order for the user to see a smooth animation, we need to redraw the spinner after each iteration. Hopefully this is not too much when multiple spinners are visible at the same time. For that, we give the option to pass the application to the spinner, so that we can request a screen redraw after each iteration. Alternatively, the user can decide not to pass the application to the spinner, and to manage the animation themselves using calls to .spin() Signed-off-by: Olivier Gayot --- subiquitycore/ui/spinner.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/subiquitycore/ui/spinner.py b/subiquitycore/ui/spinner.py index b36c5685..f17bb2c3 100644 --- a/subiquitycore/ui/spinner.py +++ b/subiquitycore/ui/spinner.py @@ -52,11 +52,12 @@ class Spinner(Text): event loop is closed (even if the spinner is no longer visible on the screen).""" - def __init__(self, style="spin", align="center", *, debug=False): + def __init__(self, style="spin", align="center", *, debug=False, app=None): self.debug = debug self.spin_index = 0 self.spin_text = styles[style]["texts"] self.rate = styles[style]["rate"] + self.app = app super().__init__("", align=align) self._spin_task = None @@ -65,6 +66,8 @@ class Spinner(Text): log.debug("spinning spinner %s", id(self)) self.spin_index = (self.spin_index + 1) % len(self.spin_text) self.set_text(self.spin_text[self.spin_index]) + if self.app is not None: + self.app.request_screen_redraw() async def _spin(self): while True: