From 174481a048cdb9d4f39e2dd593c10ec8dd8e8d43 Mon Sep 17 00:00:00 2001 From: Anton Khirnov Date: Tue, 7 Mar 2023 23:20:12 +0100 Subject: settings/utils: move resolve_att to the only place where it's used --- alot/settings/manager.py | 28 +++++++++++++++++++++------- alot/settings/utils.py | 16 ---------------- 2 files changed, 21 insertions(+), 23 deletions(-) diff --git a/alot/settings/manager.py b/alot/settings/manager.py index 5d2098b0..2945c125 100644 --- a/alot/settings/manager.py +++ b/alot/settings/manager.py @@ -13,10 +13,10 @@ import os import re from configobj import ConfigObj, Section +from urwid import AttrSpec from .errors import ConfigError, NoMatchingAccount from .utils import read_config -from .utils import resolve_att from .theme import Theme from ..account import SendmailAccount @@ -29,6 +29,20 @@ DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..', 'defaults') DATA_DIRS = get_xdg_env('XDG_DATA_DIRS', '/usr/local/share:/usr/share').split(':') +def _resolve_att(a, fallback): + """ replace '' and 'default' by fallback values """ + if a is None: + return fallback + if a.background in ['default', '']: + bg = fallback.background + else: + bg = a.background + if a.foreground in ['default', '']: + fg = fallback.foreground + else: + fg = a.foreground + return AttrSpec(fg, bg) + def _pretty_datetime(d): """ translates :class:`datetime` `d` to a "sup-style" human readable string. @@ -428,15 +442,15 @@ class SettingsManager: default_focus = theme.get_attribute(colourmode, 'global', 'tag_focus') # local defaults for tagstring attributes. depend on next lower widget - fallback_normal = resolve_att(onebelow_normal, default_normal) - fallback_focus = resolve_att(onebelow_focus, default_focus) + fallback_normal = _resolve_att(onebelow_normal, default_normal) + fallback_focus = _resolve_att(onebelow_focus, default_focus) for sec in cfg['tags'].sections: if re.match('^{}$'.format(sec), tag): - normal = resolve_att(colourpick(cfg['tags'][sec]['normal']), - fallback_normal) - focus = resolve_att(colourpick(cfg['tags'][sec]['focus']), - fallback_focus) + normal = _resolve_att(colourpick(cfg['tags'][sec]['normal']), + fallback_normal) + focus = _resolve_att(colourpick(cfg['tags'][sec]['focus']), + fallback_focus) translated = cfg['tags'][sec]['translated'] if translated is None: diff --git a/alot/settings/utils.py b/alot/settings/utils.py index e830fafc..316083aa 100644 --- a/alot/settings/utils.py +++ b/alot/settings/utils.py @@ -6,7 +6,6 @@ import logging from configobj import (ConfigObj, ConfigObjError, flatten_errors, get_extra_values) -from urwid import AttrSpec from validate import Validator from .errors import ConfigError @@ -81,18 +80,3 @@ def read_config(configpath=None, specpath=None, checks=None, msg.append(str(val)) logging.info('\n'.join(msg)) return config - - -def resolve_att(a, fallback): - """ replace '' and 'default' by fallback values """ - if a is None: - return fallback - if a.background in ['default', '']: - bg = fallback.background - else: - bg = a.background - if a.foreground in ['default', '']: - fg = fallback.foreground - else: - fg = a.foreground - return AttrSpec(fg, bg) -- cgit v1.2.3