summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-04 18:21:37 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-04 18:21:37 +0100
commit6e0f05cf58db011ea93b838cb2cf6d6d4cfcd01f (patch)
tree3c048800efa0ba9f540989d12906b741b899cff7
parent-r support for continuous mode in comprehensive example (diff)
downloadblueshift-6e0f05cf58db011ea93b838cb2cf6d6d4cfcd01f.tar.gz
blueshift-6e0f05cf58db011ea93b838cb2cf6d6d4cfcd01f.tar.bz2
blueshift-6e0f05cf58db011ea93b838cb2cf6d6d4cfcd01f.tar.xz
add example: stored-settings
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile2
-rw-r--r--examples/stored-settings58
2 files changed, 59 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 0a3540a..f8a943c 100644
--- a/Makefile
+++ b/Makefile
@@ -65,7 +65,7 @@ PYFILES = __main__.py colour.py curve.py monitor.py solar.py icc.py adhoc.py
CBINDINGS = $(foreach B,$(SERVER_BINDINGS),blueshift_$(B).so)
# Configuration script example files
EXAMPLES = comprehensive sleepmode crtc-detection crtc-searching logarithmic \
- xmobar
+ xmobar xpybar stored-settings
# Build rules
diff --git a/examples/stored-settings b/examples/stored-settings
new file mode 100644
index 0000000..e3b45c0
--- /dev/null
+++ b/examples/stored-settings
@@ -0,0 +1,58 @@
+# -*- python -*-
+
+# This example demonstrates how settings can be stored
+# and be transition from later.
+
+import os
+import time
+
+
+uses_adhoc_opts = True
+'''
+:bool `True` if the configuration script parses the ad-hoc settings
+'''
+
+
+# Get --temperature from Blueshift ad-hoc settigns
+temperature_to = int(parser.opts['--temperature'][0])
+
+# Get old temperature setting
+temperature_from = 6500
+storage_file = '/dev/shm/.blueshift-conf-%s-%s' % (os.environ['DISPLAY'], os.environ['USER'])
+if os.path.exists(storage_file):
+ with open(storage_file, 'rb') as file:
+ temperature_from = int(file.read().decode('utf-8', 'replace').split('\n')[0])
+
+# Store new temperature
+with open(storage_file, 'wb') as file:
+ file.write(str(temperature_to).encode('utf-8'))
+ file.flush()
+
+# Calculate transition time
+fadein_time = abs(temperature_to - temperature_from) * 5 / (6500 - 3700)
+fadein_steps = fadein_time * 10
+
+# Function for setting the colour temperature
+def adjust(alpha):
+ temp = temperature_to * alpha + temperature_from * (1 - alpha)
+ start_over()
+ temperature(temp, lambda t : divide_by_maximum(cmf_10deg(t)))
+ randr(0)
+
+# Perform transition
+if not (panicgate or temperature_to == temperature_from):
+ signal.signal(signal.SIGTERM, signal_SIGTERM)
+ dtime = fadein_time / fadein_steps
+ df = 1 / fadein_steps
+ trans = 0
+ while running:
+ try:
+ trans += df
+ if trans > 1:
+ break
+ adjust(trans)
+ time.sleep(dtime)
+ except KeyboardInterrupt:
+ running = False
+adjust(1)
+