From 3ea5b9c15164a15c017a3b3536c13c69e4b8fb5c Mon Sep 17 00:00:00 2001 From: Jan Pochyla Date: Tue, 10 Oct 2017 15:33:54 +0200 Subject: [PATCH] trezor/ui: close backlight slider properly --- src/trezor/ui/__init__.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/trezor/ui/__init__.py b/src/trezor/ui/__init__.py index ff0bf5fcf..1ea31daf4 100644 --- a/src/trezor/ui/__init__.py +++ b/src/trezor/ui/__init__.py @@ -82,21 +82,26 @@ async def alert(count: int=3): display.backlight(current) -async def backlight_slide(val: int, delay: int=20000): +async def backlight_slide(val: int, delay: int=20000, step: int=1): sleep = loop.sleep(delay) current = display.backlight() - for i in range(current, val, -1 if current > val else 1): + for i in range(current, val, -step if current > val else step): display.backlight(i) await sleep def layout(f): + delay = const(1000) + step = const(3) + async def inner(*args, **kwargs): - slider = backlight_slide(BACKLIGHT_NORMAL, 1000) - loop.schedule(slider) - await f(*args, **kwargs) - slider.close() - await backlight_slide(BACKLIGHT_DIM, 1000) + await backlight_slide(BACKLIGHT_DIM, delay, step) + slide = backlight_slide(BACKLIGHT_NORMAL, delay, step) + try: + loop.schedule(slide) + return await f(*args, **kwargs) + finally: + loop.close(slide) return inner