diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-03-11 14:47:46 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-03-11 14:47:46 +0000 |
commit | 42a0466cafa979513f4e0efe6d81bcec953bc711 (patch) | |
tree | 1b55928642330591d2edda0d24fc1915826a0aec /alot | |
parent | 6cc3e22eaa6a16e597c051484844d7f13102e4f7 (diff) |
cleanup: moved Theme to separate file
Diffstat (limited to 'alot')
-rw-r--r-- | alot/settings/__init__.py | 63 | ||||
-rw-r--r-- | alot/settings/theme.py | 71 |
2 files changed, 72 insertions, 62 deletions
diff --git a/alot/settings/__init__.py b/alot/settings/__init__.py index 593fbae2..86d4d9b4 100644 --- a/alot/settings/__init__.py +++ b/alot/settings/__init__.py @@ -12,72 +12,11 @@ from alot.account import SendmailAccount, MatchSdtoutAddressbook, AbookAddressBo from errors import ConfigError from utils import read_config from checks import mail_container +from theme import Theme DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..', 'defaults') -class Theme(object): - """Colour theme""" - def __init__(self, path): - """ - :param path: path to theme file - :type path: str - """ - self._spec = os.path.join(DEFAULTSPATH, 'theme.spec') - self._config = read_config(path, self._spec) - self.attributes = self._parse_attributes(self._config) - - def _parse_attributes(self, c): - """ - parse a (previously validated) valid theme file - into urwid AttrSpec attributes for internal use. - - :param c: config object for theme file - :type c: `configobj.ConfigObj` - :raises: `ConfigError` - """ - - attributes = {} - for sec in c.sections: - try: - colours = int(sec) - except ValueError: - err_msg = 'section name %s is not a valid colour mode' - raise ConfigError(err_msg % sec) - attributes[colours] = {} - for mode in c[sec].sections: - attributes[colours][mode] = {} - for themable in c[sec][mode].sections: - block = c[sec][mode][themable] - fg = block['fg'] - if colours == 1: - bg = 'default' - else: - bg = block['bg'] - if colours == 256: - fg = fg or c['16'][mode][themable][fg] - bg = bg or c['16'][mode][themable][bg] - try: - att = AttrSpec(fg, bg, colours) - except AttrSpecError, e: - raise ConfigError(e) - attributes[colours][mode][themable] = att - return attributes - - def get_attribute(self, mode, name, colourmode): - """ - returns requested attribute - - :param mode: ui-mode (e.g. `search`,`thread`...) - :type mode: str - :param name: identifier of the atttribute - :type name: str - :param colourmode: colour mode; in [1, 16, 256] - :type colourmode: int - """ - return self.attributes[colourmode][mode][name] - - class SettingsManager(object): """Organizes user settings""" def __init__(self, alot_rc=None, notmuch_rc=None, theme=None): diff --git a/alot/settings/theme.py b/alot/settings/theme.py new file mode 100644 index 00000000..301cc547 --- /dev/null +++ b/alot/settings/theme.py @@ -0,0 +1,71 @@ +import os +from urwid import AttrSpec, AttrSpecError + +from utils import read_config +from errors import ConfigError + +DEFAULTSPATH = os.path.join(os.path.dirname(__file__), '..', 'defaults') + + +class Theme(object): + """Colour theme""" + def __init__(self, path): + """ + :param path: path to theme file + :type path: str + """ + self._spec = os.path.join(DEFAULTSPATH, 'theme.spec') + self._config = read_config(path, self._spec) + self.attributes = self._parse_attributes(self._config) + + def _parse_attributes(self, c): + """ + parse a (previously validated) valid theme file + into urwid AttrSpec attributes for internal use. + + :param c: config object for theme file + :type c: `configobj.ConfigObj` + :raises: `ConfigError` + """ + + attributes = {} + for sec in c.sections: + try: + colours = int(sec) + except ValueError: + err_msg = 'section name %s is not a valid colour mode' + raise ConfigError(err_msg % sec) + attributes[colours] = {} + for mode in c[sec].sections: + attributes[colours][mode] = {} + for themable in c[sec][mode].sections: + block = c[sec][mode][themable] + fg = block['fg'] + if colours == 1: + bg = 'default' + else: + bg = block['bg'] + if colours == 256: + fg = fg or c['16'][mode][themable][fg] + bg = bg or c['16'][mode][themable][bg] + try: + att = AttrSpec(fg, bg, colours) + except AttrSpecError, e: + raise ConfigError(e) + attributes[colours][mode][themable] = att + return attributes + + def get_attribute(self, mode, name, colourmode): + """ + returns requested attribute + + :param mode: ui-mode (e.g. `search`,`thread`...) + :type mode: str + :param name: identifier of the atttribute + :type name: str + :param colourmode: colour mode; in [1, 16, 256] + :type colourmode: int + """ + return self.attributes[colourmode][mode][name] + + |