diff options
Diffstat (limited to '')
| -rwxr-xr-x | src/__main__.py | 38 | 
1 files changed, 33 insertions, 5 deletions
| diff --git a/src/__main__.py b/src/__main__.py index d7827cd..86c6866 100755 --- a/src/__main__.py +++ b/src/__main__.py @@ -43,6 +43,9 @@ from monitor import *  config_file = None +''' +:str  The configuration file to load +'''  periodically = None @@ -201,7 +204,7 @@ def signal_SIGUSR2(signum, frame):      paused = not paused      if paused: -        # Fade out +        ## Fade out          if fadeout_time is not None:              dtime = fadeout_time / fadeout_steps              df = 1 / fadeout_steps @@ -217,7 +220,7 @@ def signal_SIGUSR2(signum, frame):                  sleep(dtime)          reset()      else: -        # Fade in +        ## Fade in          if fadein_time is not None:              dtime = fadein_time / fadein_steps              df = 1 / fadein_steps @@ -361,6 +364,7 @@ output = parser.opts['--output']  if output is None:      output = [] +## Verify option correctness  a = lambda opt : 0 if parser.opts[opt] is None else len(parser.opts[opt])  for opt in ('--configurations', '--panicgate', '--reset', '--location'):      if a(opt) > 1: @@ -376,9 +380,13 @@ if (config_file is None) and any([doreset, location] + settings):      ## Use one time configurations      if len(parser.files) > 0:          print('%s: warning: configuration script arguments are not supported in ad-hoc mode' % sys.argv[0]) -    d = lambda a, default : [default, default] if a is None else (a * 2 if len(a) == 1 else a) +     +    ## Determine whether we should run in continuous mode      continuous = any(map(lambda a : (a is not None) and (len(a) == 2), settings))      continuous = continuous or (location is not None) +     +    ## Select default settings when not specified +    d = lambda a, default : [default, default] if a is None else (a * 2 if len(a) == 1 else a)      gammas = d(gammas, "1:1:1")      rgb_brightnesses = d(rgb_brightnesses, "1")      cie_brightnesses = d(cie_brightnesses, "1") @@ -386,11 +394,15 @@ if (config_file is None) and any([doreset, location] + settings):          temperatures = ['3700', '6500']      elif len(temperatures) == 1:          temperatures *= 2 +     +    ## Parse string arrays into floating point matrices      settings = [gammas, rgb_brightnesses, cie_brightnesses, temperatures, [location]]      s = lambda f, v : f(v) if v is not None else None      settings = [s(lambda c : [s(lambda x : [float(y) for y in x.split(':')], x) for x in c], c) for c in settings]      [gammas, rgb_brightnesses, cie_brightnesses, temperatures, location] = settings      location = None if location is None else location[0] +     +    ## Select method for calculating to what degree the adjustments should be applied      alpha = lambda : 1      if continuous:          if location is not None: @@ -405,7 +417,12 @@ if (config_file is None) and any([doreset, location] + settings):                      hh += 22 - 12                  return (hh - 22) / 14 + m / 60              alpha = alpha_ +     +    ## Set monitor control      def reduce(f, items): +        ''' +        https://en.wikipedia.org/wiki/Fold_(higher-order_function) +        '''          if len(items) < 2:              return items          rc = items[0] @@ -414,7 +431,14 @@ if (config_file is None) and any([doreset, location] + settings):          return rc      output = reduce(lambda x, y : x + y, [a.split(',') for a in output])      monitor_controller = lambda : randr(*output) +          def apply(dayness, pureness): +        ''' +        Apply adjustments +         +        @param  dayness:float   The visibility of the sun +        @param  pureness:float  Transitioning progress, 1 for at clean state, 0 for at adjusted state +        '''          start_over()          interpol_ = lambda d, p, a, r : d * r + (p[0] * a + p[1] * (1 - a)) * (1 - r)          interpol = lambda d, p : [interpol_(d, [p[0][i], p[1][i]], dayness, pureness) for i in range(len(p[0]))] @@ -425,10 +449,13 @@ if (config_file is None) and any([doreset, location] + settings):          gamma(*interpol(1, gammas))          clip()          monitor_controller() +          if continuous and not doreset: +        ## Continuous mode          def periodically(year, month, day, hour, minute, second, weekday, fade):              apply(alpha(), 0 if fade is None else 1 - abs(fade))      else: +        ## One shot mode          if not panicgate:              signal.signal(signal.SIGTERM, signal_SIGTERM)              trans = 0 @@ -473,8 +500,8 @@ else:      else:          print('No configuration file found')          sys.exit(1) - -    # Warn about ad-hoc settings +     +    ## Warn about ad-hoc settings      if not uses_adhoc_opts:          if any([doreset, location, gammas, rgb_brightnesses, cie_brightnesses, temperatures, output]):              print('%s: warning: --configurations can only be combined with --panicgate' % sys.argv[0]) @@ -484,5 +511,6 @@ else:  if periodically is not None:      continuous_run() +## Close C bindings to free resource and close connections  close_c_bindings() | 
