From f5e8f14065d39c99d856f9a521b58583c4ba9b0c Mon Sep 17 00:00:00 2001 From: obrusvit Date: Wed, 30 Apr 2025 17:57:35 +0200 Subject: [PATCH] feat(core): animate ProgressLayout in Python - the commit allows for smoother animation of the `ProgressLayout` by stepping through the reported progress --- core/src/trezor/ui/__init__.py | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/core/src/trezor/ui/__init__.py b/core/src/trezor/ui/__init__.py index 9691402d61..6e401636cc 100644 --- a/core/src/trezor/ui/__init__.py +++ b/core/src/trezor/ui/__init__.py @@ -478,6 +478,8 @@ class ProgressLayout: def __init__(self, layout: LayoutObj[UiResult]) -> None: self.layout = layout self.transition_out = None + self.value = 0 + self.progress_step = 10 def is_layout_attached(self) -> bool: return True @@ -495,10 +497,21 @@ class ProgressLayout: if utils.DISABLE_ANIMATION: return - msg = self.layout.progress_event(value, description or "") - assert msg is None - if self.layout.paint(): - refresh() + def do_progress_event(val: int) -> None: + msg = self.layout.progress_event(val, description or "") + assert msg is None + if self.layout.paint(): + refresh() + + # animate the progress bar in a blocking fashion + step = min(self.progress_step, max(value - self.value, 1)) + last_value = self.value + for v in range(self.value, min(value, 1000) + 1, step): + do_progress_event(v) + last_value = v + if value >= 1000 and last_value != 1000: + do_progress_event(1000) + self.value = value def start(self) -> None: global CURRENT_LAYOUT