From 41276555849aafabe0e8082aeb43f763940fe9a4 Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Tue, 20 Jun 2017 13:07:29 +0200 Subject: [PATCH] trezor.ui.loader: make target parametric --- src/trezor/ui/loader.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/trezor/ui/loader.py b/src/trezor/ui/loader.py index eb1289f6e..1dfcea762 100644 --- a/src/trezor/ui/loader.py +++ b/src/trezor/ui/loader.py @@ -17,12 +17,11 @@ DEFAULT_LOADER_ACTIVE = { 'icon-fg-color': None, } -_LOADER_MSEC = const(1000) - class Loader(ui.Widget): - def __init__(self, normal_style=None, active_style=None): + def __init__(self, target_ms=1000, normal_style=None, active_style=None): + self.target_ms = target_ms self.start_ticks_ms = None self.normal_style = normal_style or DEFAULT_LOADER self.active_style = active_style or DEFAULT_LOADER_ACTIVE @@ -35,14 +34,14 @@ class Loader(ui.Widget): ui.display.bar(0, 32, 240, 240 - 80, ui.BLACK) ticks_diff = utime.ticks_ms() - self.start_ticks_ms self.start_ticks_ms = None - return ticks_diff >= _LOADER_MSEC + return ticks_diff >= self.target_ms def is_active(self): return self.start_ticks_ms is not None def render(self): - progress = min(utime.ticks_ms() - self.start_ticks_ms, _LOADER_MSEC) - if progress == _LOADER_MSEC: + progress = min(utime.ticks_ms() - self.start_ticks_ms, self.target_ms) + if progress == self.target_ms: style = self.active_style else: style = self.normal_style