summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rwxr-xr-xsrc/__main__.py29
-rw-r--r--src/curve.py28
-rw-r--r--src/monitor.py3
3 files changed, 36 insertions, 24 deletions
diff --git a/src/__main__.py b/src/__main__.py
index f8db7a2..8fd4235 100755
--- a/src/__main__.py
+++ b/src/__main__.py
@@ -20,6 +20,12 @@ import time
import signal
import datetime
+
+## Set global variables
+global DATADIR, i_size, o_size, r_curve, g_curve, b_curve, clip_result
+global periodically, wait_period, monitor_controller, running
+
+
from solar import *
from curve import *
from colour import *
@@ -29,11 +35,6 @@ from monitor import *
config_file = None
-## Set globals variables
-global DATADIR, i_size, o_size, r_curve, g_curve, b_curve, clip_result
-global periodically, wait_period, monitor_controller, running
-
-
def periodically(year, month, day, hour, minute, second, weekday, fade):
fadein_time = None
fadeout_time = None
@@ -133,23 +134,27 @@ if config_file is None:
for file in ('$XDG_CONFIG_HOME/%/%rc', '$HOME/.config/%/%rc', '$HOME/.%rc', '/etc/%rc'):
file = file.replace('%', 'blueshift')
for arg in ('XDG_CONFIG_HOME', 'HOME'):
- if arg in os.environ:
- print(arg)
- file = file.replace('$' + arg, os.environ[arg].replace('$', '\0'))
- else:
- file = None
- break
+ if '$' + arg in file:
+ if arg in os.environ:
+ file = file.replace('$' + arg, os.environ[arg].replace('$', '\0'))
+ else:
+ file = None
+ break
if file is not None:
file = file.replace('\0', '$')
if os.path.exists(file):
config_file = file
+ break
if config_file is not None:
code = None
with open(file, 'rb') as script:
code = script.read()
code = code.decode('utf8', 'error') + '\n'
code = compile(code, file, 'exec')
- exec(code, globals)
+ g, l = globals(), dict(locals())
+ for key in l:
+ g[key] = l[key]
+ exec(code, g)
else:
print('No configuration file found')
sys.exit(1)
diff --git a/src/curve.py b/src/curve.py
index 34adf29..9721da8 100644
--- a/src/curve.py
+++ b/src/curve.py
@@ -101,23 +101,25 @@ def cmf_2deg(temperature):
@param temperature:float The blackbody temperature in kelvins, clipped to [1000, 40000]
@return :(float, float, float) The red, green and blue components of the white point
'''
+ global cmf_2deg_cache
if cmf_2deg_cache is None:
with open(DATADIR + '/2deg', 'rb') as file:
cmf_2deg_cache = file.read()
- cmf_2deg_cache.decode('utf-8', 'error').split('\n')
+ cmf_2deg_cache = cmf_2deg_cache.decode('utf-8', 'error').split('\n')
+ cmf_2deg_cache = filter(lambda x : not x == '', cmf_2deg_cache)
cmf_2deg_cache = [[float(x) for x in x_y.split(' ')] for x_y in cmf_2deg_cache]
- temperature = min(max(0, temperature), 1000)
+ temp = min(max(1000, temperature), 40000)
x, y = 0, 0
if (temp % 100) == 0:
- (x, y) = temperature[(temp - 1000) // 100]
+ (x, y) = cmf_2deg_cache[(temp - 1000) // 100]
else:
temp -= 1000
- (x1, y1) = temperature[temp // 100]
- (x2, y2) = temperature[temp // 100 + 1]
+ (x1, y1) = cmf_2deg_cache[temp // 100]
+ (x2, y2) = cmf_2deg_cache[temp // 100 + 1]
temp = (temp % 100) / 100
x = x1 * temp + x2 * (1 - temp)
y = y1 * temp + y2 * (1 - temp)
- return ciexy_to_srgb(x, y, 1.0)
+ return ciexyy_to_srgb(x, y, 1.0)
cmf_10deg_cache = None
@@ -128,23 +130,25 @@ def cmf_10deg(temperature):
@param temperature:float The blackbody temperature in kelvins, clipped to [1000, 40000]
@return :(float, float, float) The red, green and blue components of the white point
'''
+ global cmf_10deg_cache
if cmf_10deg_cache is None:
with open(DATADIR + '/10deg', 'rb') as file:
cmf_10deg_cache = file.read()
- cmf_10deg_cache.decode('utf-8', 'error').split('\n')
+ cmf_10deg_cache = cmf_10deg_cache.decode('utf-8', 'error').split('\n')
+ cmf_10deg_cache = filter(lambda x : not x == '', cmf_10deg_cache)
cmf_10deg_cache = [[float(x) for x in x_y.split(' ')] for x_y in cmf_10deg_cache]
- temperature = min(max(0, temperature), 1000)
+ temp = min(max(1000, temperature), 40000)
x, y = 0, 0
if (temp % 100) == 0:
- (x, y) = temperature[(temp - 1000) // 100]
+ (x, y) = cmf_10deg_cache[(temp - 1000) // 100]
else:
temp -= 1000
- (x1, y1) = temperature[temp // 100]
- (x2, y2) = temperature[temp // 100 + 1]
+ (x1, y1) = cmf_10deg_cache[temp // 100]
+ (x2, y2) = cmf_10deg_cache[temp // 100 + 1]
temp = (temp % 100) / 100
x = x1 * temp + x2 * (1 - temp)
y = y1 * temp + y2 * (1 - temp)
- return ciexy_to_srgb(x, y, 1.0)
+ return ciexyy_to_srgb(x, y, 1.0)
diff --git a/src/monitor.py b/src/monitor.py
index b8f5cff..b2bfa84 100644
--- a/src/monitor.py
+++ b/src/monitor.py
@@ -17,6 +17,8 @@
import sys
+from curve import *
+
# /usr/lib
LIBDIR = 'bin'
sys.path.append(LIBDIR)
@@ -43,6 +45,7 @@ def translate_to_integers():
def close_c_bindings():
global randr_opened
if randr_opened:
+ randr_opened = False
randr_close()