From 87bd5286b95f0fd3c1feae56f1634578a8a06d6f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 31 Mar 2014 00:39:15 +0200 Subject: m doc + do not override fadein_time or fadeout_time with None if fadein_steps or fadeout_steps, respectively, is non-positive MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/__main__.py | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/src/__main__.py b/src/__main__.py index a3ba573..62829b6 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -410,9 +410,14 @@ def continuous_run(): signal_(signal.SIGALRM, signal_SIGALRM) ## Create initial transition + # Fade in trans_delta = -1 + # from clean state. trans_alpha = 1 + with_fadein = lambda : (fadein_steps > 0) and (fadein_time is not None) + with_fadeout = lambda : (fadeout_steps > 0) and (fadeout_time is not None) + while running: if trans_delta == 0: ## Run periodically @@ -421,26 +426,22 @@ def continuous_run(): sleep(wait_period) elif trans_delta < 0: ## Fade in - if fadein_steps <= 0: - fadein_time = None - if not ((fadein_time is None) or panicgate): + if with_fadein() and not panicgate: if trans_alpha == 0: p(now(), 1 - trans_alpha) sleep(fadein_time / fadein_steps) trans_alpha -= 1 / fadein_steps - if (trans_alpha <= 0) or (fadein_time is None) or panicgate: + if not (with_fadein() and not panicgate): trans_alpha = 0 trans_delta = 0 p(now(), 1 - trans_alpha) - if fadein_time is not None: + if with_fadein(): sleep(fadein_time / fadein_steps) else: ## Fade out - if fadeout_steps <= 0: - fadeout_time = None - if not (fadeout_time is None): + if with_fadeout(): trans_alpha += 1 / fadeout_steps - if (trans_alpha >= 1) or (fadeout_time is None): + if (trans_alpha >= 1) or not with_fadeout(): trans_alpha = 1 p(now(), -1 + trans_alpha) if trans_alpha == 1: @@ -450,19 +451,19 @@ def continuous_run(): except KeyboardInterrupt: signal_SIGTERM(0, None) else: - if fadeout_time is not None: + if with_fadeout(): sleep(fadeout_time / fadeout_steps) ## Fade out - if fadeout_steps <= 0: - fadeout_time = None - if not (fadeout_time is None): + if with_fadeout(): while not panic: trans_alpha += 1 / fadeout_steps - if (trans_alpha >= 1) or (fadeout_time is None): + if trans_alpha >= 1: trans_alpha = 1 panic = True p(now(), -1 + trans_alpha) + if not with_fadeout(): + break sleep(fadeout_time / fadeout_steps) ## Reset -- cgit v1.2.3-70-g09d2