summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2012-02-19 12:31:48 +0000
committerPatrick Totzke <patricktotzke@gmail.com>2012-02-19 12:31:48 +0000
commit98d59b557ea96d85d20259462840c1ef752af198 (patch)
tree09d04a4fb62d8d1823bfaf6e68b1a2dea5415860
parent4bd55e5c1fa669fb98ba11eae46b250915937ac1 (diff)
read attrspecs in theme's init
this makes Theme objects check the integrity of their given configs by instanciating urwid.AttrSpec objects in ther constructor, so that invalid attribute strings don't raise errors at runtime
-rw-r--r--alot/defaults/default.theme14
-rw-r--r--alot/defaults/theme.spec22
-rw-r--r--alot/settings.py42
3 files changed, 38 insertions, 40 deletions
diff --git a/alot/defaults/default.theme b/alot/defaults/default.theme
index aecf381e..269bf856 100644
--- a/alot/defaults/default.theme
+++ b/alot/defaults/default.theme
@@ -1,4 +1,4 @@
-[1c]
+[1]
[[global]]
[[[footer]]]
fg = 'standout'
@@ -21,7 +21,6 @@
fg = 'underline'
[[[title]]]
fg = 'standout'
-
[[bufferlist]]
[[[focus]]]
fg = 'standout'
@@ -29,7 +28,6 @@
fg = 'default'
[[[results_odd]]]
fg = 'default'
-
[[search]]
[[[thread]]]
fg = 'default'
@@ -67,7 +65,6 @@
fg = 'bold'
[[[thread_tags_focus]]]
fg = 'standout'
-
[[thread]]
[[[attachment]]]
fg = 'default'
@@ -88,7 +85,7 @@
[[[summary_odd]]]
fg = 'default'
-[16c]
+[16]
[[global]]
[[[footer]]]
bg = 'dark blue'
@@ -202,8 +199,8 @@
[[[thread_tags_focus]]]
bg = 'dark gray'
fg = 'yellow,bold'
-[256c]
+[256]
[[global]]
# attributes used in all modi
[[[footer]]]
@@ -224,8 +221,6 @@
[[[tag_focus]]]
bg = '#68a'
fg = '#ffa'
-
-
[[help]]
# formating of the `help bindings` overlay
[[[text]]]
@@ -237,7 +232,6 @@
[[[title]]]
bg = 'g35'
fg = 'white,bold,underline'
-
# mode specific attributes
[[bufferlist]]
[[[focus]]]
@@ -249,7 +243,6 @@
[[[results_odd]]]
bg = 'default'
fg = 'default'
-
[[search]]
[[[thread]]]
bg = 'default'
@@ -294,7 +287,6 @@
[[[thread_tags_focus]]]
bg = '#68a'
fg = '#ff8'
-
[[thread]]
[[[attachment]]]
bg = 'dark gray'
diff --git a/alot/defaults/theme.spec b/alot/defaults/theme.spec
index 19964a12..d1ea47ab 100644
--- a/alot/defaults/theme.spec
+++ b/alot/defaults/theme.spec
@@ -1,4 +1,4 @@
-[1c]
+[1]
[[global]]
[[[footer]]]
fg = string(default='default')
@@ -14,7 +14,6 @@
fg = string(default='default')
[[[tag_draft]]]
fg = string(default='default')
-
[[help]]
[[[text]]]
fg = string(default='default')
@@ -22,7 +21,6 @@
fg = string(default='default')
[[[title]]]
fg = string(default='default')
-
[[bufferlist]]
[[[focus]]]
fg = string(default='default')
@@ -30,7 +28,6 @@
fg = string(default='default')
[[[results_odd]]]
fg = string(default='default')
-
[[search]]
[[[thread]]]
fg = string(default='default')
@@ -68,7 +65,6 @@
fg = string(default='default')
[[[thread_tags_focus]]]
fg = string(default='default')
-
[[thread]]
[[[attachment]]]
fg = string(default='default')
@@ -89,7 +85,7 @@
[[[summary_odd]]]
fg = string(default='default')
-[16c]
+[16]
[[global]]
[[[footer]]]
bg = string(default='default')
@@ -112,8 +108,6 @@
[[[tag_draft]]]
bg = string(default='default')
fg = string(default='default')
-
-
[[help]]
[[[text]]]
bg = string(default='default')
@@ -134,8 +128,6 @@
[[[results_odd]]]
bg = string(default='default')
fg = string(default='default')
-
-
[[thread]]
[[[attachment]]]
bg = string(default='default')
@@ -164,7 +156,6 @@
[[[summary_odd]]]
bg = string(default='default')
fg = string(default='default')
-
[[search]]
[[[thread]]]
bg = string(default='default')
@@ -209,9 +200,7 @@
bg = string(default='default')
fg = string(default='default')
-
-[256c]
-
+[256]
[[global]]
# attributes used in all modi
[[[footer]]]
@@ -232,8 +221,6 @@
[[[tag_focus]]]
bg = string(default=None)
fg = string(default=None)
-
-
[[help]]
# formating of the `help bindings` overlay
[[[text]]]
@@ -245,7 +232,6 @@
[[[title]]]
bg = string(default=None)
fg = string(default=None)
-
# mode specific attributes
[[bufferlist]]
[[[focus]]]
@@ -257,7 +243,6 @@
[[[results_odd]]]
bg = string(default=None)
fg = string(default=None)
-
[[search]]
[[[thread]]]
fg = string(default=None)
@@ -300,7 +285,6 @@
[[[thread_tags_focus]]]
bg = string(default=None)
fg = string(default=None)
-
[[thread]]
[[[attachment]]]
bg = string(default=None)
diff --git a/alot/settings.py b/alot/settings.py
index 14fe1308..59ba9ad1 100644
--- a/alot/settings.py
+++ b/alot/settings.py
@@ -7,6 +7,7 @@ import mailcap
import codecs
import logging
import urwid
+from urwid import AttrSpec, AttrSpecError
from configobj import ConfigObj, ConfigObjError, flatten_errors, Section
from validate import Validator
@@ -46,18 +47,39 @@ class Theme(object):
def __init__(self, path):
self._spec = os.path.join(DEFAULTSPATH, 'theme.spec')
self._config = read_config(path, self._spec)
- self.path = path
+ self.attributes = self.parse_attributes(self._config)
+
+ def parse_attributes(self, c):
+ attributes = {}
+ for sec in c.sections:
+ try:
+ colours = int(sec)
+ except ValueError:
+ err_msg='section %s is not an integer indicating a 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):
- fg = self._config['%dc' % colourmode][mode][name]['fg']
- if colourmode == 1:
- bg = 'default'
- else:
- bg = self._config['%dc' % colourmode][mode][name]['bg']
- if colourmode == 256:
- fg = fg or self._config['16c'][mode][name][fg]
- bg = bg or self._config['16c'][mode][name][bg]
- return urwid.AttrSpec(fg, bg, colourmode)
+ return self.attributes[colourmode][mode][name]
class SettingsManager(object):