diff options
Diffstat (limited to '')
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | TODO | 1 | ||||
-rw-r--r-- | examples/modes | 63 |
3 files changed, 64 insertions, 2 deletions
@@ -68,7 +68,7 @@ CBINDINGS = $(foreach B,$(SERVER_BINDINGS),blueshift_$(B).so) # Configuration script example files EXAMPLES = comprehensive sleepmode crtc-detection crtc-searching logarithmic \ xmobar xpybar stored-settings current-settings xmonad threaded \ - backlight darkroom textconf textconf.conf + backlight darkroom textconf textconf.conf modes # Build rules @@ -6,7 +6,6 @@ Medium priority: Test, demo and document _ICC_PROFILE Add functions to store and restore curves so that we do not need to recalculate all filters before withs that are output specific. - Make an example that loads a configuration script from a directory Make it possible to have settings depend on sky condicitions. (I have a GPL3 implmenetion of wheter observation in xpybar.) diff --git a/examples/modes b/examples/modes new file mode 100644 index 0000000..8cac965 --- /dev/null +++ b/examples/modes @@ -0,0 +1,63 @@ +# -*- python -*- + +# This example can be used to name a mode you want to use, +# and load the script, without having the use Blueshift's -c +# option and give a pathname. You will only need to give a +# filename. In this example, those modes are installed in +# the directory `$XDG_CONFIG_HOME/blueshift-modes`, and the +# default mode is named `default`. + + +# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import os + + +# Name of default mode. +mode = 'default' + +# Directory of mode scripts. +modedir = '%s/blueshift-modes' +modedir_ = os.environ['XDG_CONFIG_HOME'] if 'XDG_CONFIG_HOME' in os.environ else None +if modedir_ is None: + home = os.environ['HOME'] if 'HOME' in os.environ else None + if home is None: + import pwd + home = pwd.getpwuid(os.getuid()).pw_dir + modedir_ = '%s/.config' % home +modedir = (modedir % modedir_) + '/' + +# Get selected mode. +if 'mode' in conf_storage: + mode = conf_storage['mode'] +else: + conf_opts[:] = conf_opts[1:] + if len(conf_opts) > 0: + if not (conf_opts[0].startswith('-') or conf_opts[0].startswith('+')): + mode = conf_opts[0] + conf_opts[:] = conf_opts[1:] + conf_storage['mode'] = mode + conf_opts[:0] = [mode] + +# Exec mode script. +mode_file = modedir + mode +code = None +with open(mode_file, 'rb') as script: + code = script.read() +code = code.decode('utf-8', 'error') + '\n' +code = compile(code, mode_file, 'exec') +exec(code, globals()) + |