summaryrefslogtreecommitdiff
path: root/alot/settings
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-07-07 13:52:42 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2012-07-07 14:32:43 +0100
commit5ebb57ca4f408d1d098caa9fac2c012f824b8621 (patch)
treea86fefa872ac2617da9c8dc89915552665d986b2 /alot/settings
parenta6f2b93ea477f13d96eaf40fb4dd7cb7b9c97efc (diff)
implement selective threadline theming aka. 'highlighting'
This allows the user to specify alternate 'threadline.*' sections for searchmode: They specify the difference to the default threadline theming. Each of those can contain fields 'query' and 'tagged_with' to determine if they apply: We go through all those threadline sections top down, for each of them check if the conditions query (thread matches querystring) and 'tagged_with' (culmulative tags of messages in thread contain those listed). The first section that matches wins, default is to section 'threadline'.
Diffstat (limited to 'alot/settings')
-rw-r--r--alot/settings/theme.py50
1 files changed, 27 insertions, 23 deletions
diff --git a/alot/settings/theme.py b/alot/settings/theme.py
index b3a47b1b..8b60b2f1 100644
--- a/alot/settings/theme.py
+++ b/alot/settings/theme.py
@@ -2,13 +2,13 @@
# This file is released under the GNU GPL, version 3 or a later revision.
# For further details see the COPYING file
import os
-import logging
from urwid import AttrSpec, AttrSpecError
from utils import read_config
from checks import align_mode
from checks import attr_triple
from checks import width_tuple
+from checks import force_list
from errors import ConfigError
DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..', 'defaults')
@@ -26,19 +26,20 @@ class Theme(object):
self._config = read_config(path, self._spec,
checks={'align': align_mode,
'widthtuple': width_tuple,
+ 'force_list': force_list,
'attrtriple': attr_triple})
self._colours = [1, 16, 256]
# make sure every entry in 'order' lists have their own subsections
+ threadline = self._config['search']['threadline']
for sec in self._config['search']:
if sec.startswith('threadline'):
- logging.debug(sec)
- threadline = self._config['search'][sec]
- logging.debug(threadline)
- if threadline['parts'] is not None:
- listed = set(threadline['parts'])
- present = set(threadline.sections)
- difference = listed.difference(present)
- if difference:
+ tline = self._config['search'][sec]
+ if tline['parts'] is not None:
+ listed = set(tline['parts'])
+ here = set(tline.sections)
+ indefault = set(threadline.sections)
+ diff = listed.difference(here.union(indefault))
+ if diff:
msg = 'missing threadline parts: %s' % difference
raise ConfigError(msg)
@@ -63,35 +64,38 @@ class Theme(object):
return triple[self._colours.index(colourmode)]
def matches(sec, thread):
- if 'tags_contain' in sec.scalars:
- if not set(sec['tags_contain']).issubset(thread.get_tags()):
+ if sec.get('tagged_with') is not None:
+ if not set(sec['tagged_with']).issubset(thread.get_tags()):
return False
- if 'query' in sec.scalars:
+ if sec.get('query') is not None:
if not thread.matches(sec['query']):
return False
return True
- default = self._config['search']['threadline'].copy()
+ default = self._config['search']['threadline']
match = default
- for candidatename in self._config['search'].sections:
+ candidates = self._config['search'].sections
+ for candidatename in candidates:
candidate = self._config['search'][candidatename]
- logging.debug('testing:%s' % candidatename)
if candidatename.startswith('threadline') and\
+ (not candidatename == 'threadline') and\
matches(candidate, thread):
match = candidate
break
# fill in values
res = {}
- res['normal'] = pickcolour(match.get('normal', default['normal']))
- res['focus'] = pickcolour(match.get('focus', default['focus']))
- res['parts'] = match.get('parts', default['parts'])
+ res['normal'] = pickcolour(match.get('normal') or default['normal'])
+ res['focus'] = pickcolour(match.get('focus') or default['focus'])
+ res['parts'] = match.get('parts') or default['parts']
for part in res['parts']:
+ partsec = match.get(part) or default[part]
res[part] = {}
- res[part]['width'] = match[part].get('width') or ('fit', 0, 0)
- res[part]['alignment'] = match[part].get('alignment')
- res[part]['normal'] = pickcolour(match[part].get('normal', default['normal']))
- res[part]['focus'] = pickcolour(match[part].get('focus', default['focus']))
- logging.debug(res)
+ res[part]['width'] = partsec.get('width') or ('fit', 0, 0)
+ res[part]['alignment'] = partsec.get('alignment')
+ normal_triple = partsec.get('normal') or default['normal']
+ res[part]['normal'] = pickcolour(normal_triple)
+ focus_triple = partsec.get('focus') or default['focus']
+ res[part]['focus'] = pickcolour(focus_triple)
return res