From ea08bce7e7cc57e78858e46712d33209f21066e8 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Mon, 31 Mar 2014 00:59:11 +0200 Subject: document 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, 27 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/__main__.py b/src/__main__.py index 62829b6..49334e6 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -415,14 +415,26 @@ def continuous_run(): # from clean state. trans_alpha = 1 + ## Used to test if fading should still be used with_fadein = lambda : (fadein_steps > 0) and (fadein_time is not None) with_fadeout = lambda : (fadeout_steps > 0) and (fadeout_time is not None) + ## Run until we get a signal to exit + # When the program start we are fading in, + # than we run in normal periodical state. + # But if we get a SIGUSR2 signal we start + # fading out until we get another at which + # point we start fading in. When we get a + # SIGUSR2 we set `panicgate` to be false. while running: if trans_delta == 0: ## Run periodically + # Apply adjustments p(now(), None) + # and, assuming that we should not exit, if running: + # sleep for a time interval selected + # by the configuration script. sleep(wait_period) elif trans_delta < 0: ## Fade in @@ -432,8 +444,7 @@ def continuous_run(): sleep(fadein_time / fadein_steps) trans_alpha -= 1 / fadein_steps if not (with_fadein() and not panicgate): - trans_alpha = 0 - trans_delta = 0 + trans_alpha = trans_delta = 0 p(now(), 1 - trans_alpha) if with_fadein(): sleep(fadein_time / fadein_steps) @@ -449,6 +460,7 @@ def continuous_run(): with sleep_condition: sleep_condition.wait() except KeyboardInterrupt: + # Emulate `kill -TERM` on Control+c signal_SIGTERM(0, None) else: if with_fadeout(): @@ -456,14 +468,27 @@ def continuous_run(): ## Fade out if with_fadeout(): + # If we should fade, fade will we have not got + # two SIGTERM signals or keyboard interrupts while not panic: + # Step towards clean adjustments trans_alpha += 1 / fadeout_steps + # If we have clean adjustments (or hyperclean), if trans_alpha >= 1: + # set the adjustments to clean (in case they where hyperclean) trans_alpha = 1 + # and signal that want should stop after this stop. panic = True + # Apply adjustments. If `trans_alpha` is 0, we have `fade = -1` + # which means that we are fading away from adjustements but are + # still at 100 % adjustments, moving towards `fade = 0` we are + # removing the adjustments gradually. p(now(), -1 + trans_alpha) + # Stop if we should no longer fade, if not with_fadeout(): break + # before we sleep. If we did not break + # would would run into errors. sleep(fadeout_time / fadeout_steps) ## Reset -- cgit v1.2.3-70-g09d2