summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpazz <patricktotzke@gmail.com>2011-06-08 20:55:28 +0100
committerpazz <patricktotzke@gmail.com>2011-06-08 20:55:28 +0100
commit44a00af6875030e5d1290e03a8b519293950d2cf (patch)
tree9c8c2bcaf82e1fe6c11751e7372f2707adec1198
parent6cf5111820ea7b4a745994dd9166c292919bb5cc (diff)
read colour theme from config file
-rw-r--r--alot/__init__.py12
-rw-r--r--alot/command.py2
-rwxr-xr-xalot/init.py3
-rw-r--r--alot/settings.py227
-rw-r--r--alot/ui.py4
-rw-r--r--data/example.rc140
6 files changed, 326 insertions, 62 deletions
diff --git a/alot/__init__.py b/alot/__init__.py
index d6895eb4..c13d4971 100644
--- a/alot/__init__.py
+++ b/alot/__init__.py
@@ -17,10 +17,10 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>.
Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com>
"""
__productname__ = 'alot'
-__version__ = "0.0.1"
-__copyright__ = "Copyright (C) 2011 Patrick Totzke"
-__author__ = "Patrick Totzke"
-__author_email__= "patricktotzke@gmail.com"
+__version__ = '0.0.1'
+__copyright__ = "Copyright (C) 2011 Patrick Totzke"
+__author__ = "Patrick Totzke"
+__author_email__ = "patricktotzke@gmail.com"
__description__ = "Terminal User Interface for notmuch mail (notmuchmail.org)"
-__url__ = "https://github.com/pazz/notmuch-gui"
-__license__ = "Licensed under the GNU GPL v3+."
+__url__ = "https://github.com/pazz/notmuch-gui"
+__license__ = "Licensed under the GNU GPL v3+."
diff --git a/alot/command.py b/alot/command.py
index 86e8cc9a..c248834b 100644
--- a/alot/command.py
+++ b/alot/command.py
@@ -116,7 +116,7 @@ class EditCommand(Command):
def afterwards():
ui.logger.info('Editor was closed')
editor_cmd = config.get('general', 'editor_cmd')
- cmd = ExternalCommand(editor_cmd + ' ' +self.path,
+ cmd = ExternalCommand(editor_cmd + ' ' + self.path,
spawn=self.spawn,
onExit=afterwards)
ui.apply_command(cmd)
diff --git a/alot/init.py b/alot/init.py
index 085eeeed..e6e19a73 100755
--- a/alot/init.py
+++ b/alot/init.py
@@ -20,9 +20,9 @@ import argparse
import logging
import os
+import settings
from db import DBManager
from ui import UI
-import settings
def parse_args():
@@ -60,7 +60,6 @@ def main():
configfilename = os.path.expanduser(args.configfile)
settings.setup(configfilename)
-
# setup logging
numeric_loglevel = getattr(logging, args.debug_level.upper(), None)
logging.basicConfig(level=numeric_loglevel, filename=args.logfile)
diff --git a/alot/settings.py b/alot/settings.py
index 3ade500c..a70c276a 100644
--- a/alot/settings.py
+++ b/alot/settings.py
@@ -19,64 +19,193 @@ Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com>
from ConfigParser import SafeConfigParser
-class ListConfigParser(SafeConfigParser):
+DEFAULTS = {
+ 'general': {
+ 'colourmode': '16',
+ 'editor_cmd': "/usr/bin/vim -f -c 'set filetype=mail' ",
+ 'pager_cmd': "/usr/bin/view -f -c 'set filetype=mail' ",
+ 'terminal_cmd': 'urxvt -T notmuch -e',
+ 'spawn_editor': 'True',
+ 'spawn_pager': 'True',
+ 'displayed_headers': 'From,To,Cc,Bcc,Subject',
+ 'authors_maxlength': '30',
+ },
+ 'normal-theme': {
+ 'bufferlist_focus_bg': 'dark gray',
+ 'bufferlist_focus_fg': 'white',
+ 'bufferlist_results_even_bg': 'black',
+ 'bufferlist_results_even_fg': 'light gray',
+ 'bufferlist_results_odd_bg': 'black',
+ 'bufferlist_results_odd_fg': 'light gray',
+ 'footer_bg': 'dark blue',
+ 'footer_fg': 'white',
+ 'header_bg': 'dark blue',
+ 'header_fg': 'white',
+ 'message_body_bg': 'black',
+ 'message_body_fg': 'light gray',
+ 'message_header_bg': 'dark gray',
+ 'message_header_fg': 'white',
+ 'messagesummary_even_bg': 'light blue',
+ 'messagesummary_even_fg': 'white',
+ 'messagesummary_focus_bg': 'dark green',
+ 'messagesummary_focus_fg': 'white',
+ 'messagesummary_odd_bg': 'dark blue',
+ 'messagesummary_odd_fg': 'white',
+ 'prompt_bg': 'black',
+ 'prompt_fg': 'light gray',
+ 'taglist_focus_bg': 'dark gray',
+ 'taglist_focus_fg': 'white',
+ 'taglist_tag_bg': 'black',
+ 'taglist_tag_fg': 'light gray',
+ 'threadline_authors_bg': 'default',
+ 'threadline_authors_fg': 'dark green',
+ 'threadline_authors_linefocus_bg': 'dark gray',
+ 'threadline_authors_linefocus_fg': 'dark green,bold',
+ 'threadline_bg': 'default',
+ 'threadline_content_bg': 'default',
+ 'threadline_content_fg': 'dark gray',
+ 'threadline_date_bg': 'default',
+ 'threadline_date_fg': 'light gray',
+ 'threadline_date_linefocus_bg': 'dark gray',
+ 'threadline_date_linefocus_fg': 'light gray',
+ 'threadline_fg': 'default',
+ 'threadline_focus_bg': 'dark gray',
+ 'threadline_focus_fg': 'white',
+ 'threadline_mailcount_bg': 'default',
+ 'threadline_mailcount_fg': 'light gray',
+ 'threadline_mailcount_linefocus_bg': 'dark gray',
+ 'threadline_mailcount_linefocus_fg': 'light gray',
+ 'threadline_subject_bg': 'default',
+ 'threadline_subject_fg': 'light gray',
+ 'threadline_subject_linefocus_bg': 'dark gray',
+ 'threadline_subject_linefocus_fg': 'light gray',
+ 'threadline_tags_bg': 'default',
+ 'threadline_tags_fg': 'brown',
+ 'threadline_tags_linefocus_bg': 'dark gray',
+ 'threadline_tags_linefocus_fg': 'yellow,bold',
+ },
+ 'mono-theme': {
+ 'header': 'bold',
+ 'footer': 'bold',
+ 'prompt': 'standout',
+ 'threadline': 'default',
+ 'threadline_date': 'default',
+ 'threadline_mailcount': 'default',
+ 'threadline_tags': 'default',
+ 'threadline_authors': 'default',
+ 'threadline_subject': 'default',
+ 'threadline_content': 'default',
+ 'threadline_focus': 'standout',
+ 'threadline_date_linefocus': 'standout',
+ 'threadline_mailcount_linefocus': 'standout',
+ 'threadline_tags_linefocus': 'standout',
+ 'threadline_authors_linefocus': 'standout',
+ 'threadline_subject_linefocus': 'standout',
+ 'messagesummary_even': 'standout',
+ 'messagesummary_odd': 'standout',
+ 'messagesummary_focus': 'standout',
+ 'message_header': 'default',
+ 'message_body': 'default',
+ 'bufferlist_results_even': 'default',
+ 'bufferlist_results_odd': 'default',
+ 'bufferlist_focus': 'standout',
+ 'taglist_tag': 'default',
+ 'taglist_focus': 'standout',
+ },
+ 'highcolour-theme': {
+ 'bufferlist_focus_bg': 'g38',
+ 'bufferlist_focus_fg': '#ffa',
+ 'bufferlist_results_even_bg': 'g3',
+ 'bufferlist_results_even_fg': 'default',
+ 'bufferlist_results_odd_bg': 'default',
+ 'bufferlist_results_odd_fg': 'default',
+ 'footer_bg': '#006',
+ 'footer_fg': 'white',
+ 'header_bg': 'dark blue',
+ 'header_fg': 'white',
+ 'message_body_bg': 'default',
+ 'message_body_fg': 'light gray',
+ 'message_header_bg': 'dark gray',
+ 'message_header_fg': 'white',
+ 'messagesummary_even_bg': '#068',
+ 'messagesummary_even_fg': 'white',
+ 'messagesummary_focus_bg': 'g58',
+ 'messagesummary_focus_fg': '#ff8',
+ 'messagesummary_odd_bg': '#006',
+ 'messagesummary_odd_fg': 'white',
+ 'prompt_bg': 'default',
+ 'prompt_fg': 'light gray',
+ 'taglist_focus_bg': 'g38',
+ 'taglist_focus_fg': '#ffa',
+ 'taglist_tag_bg': 'default',
+ 'taglist_tag_fg': 'default',
+ 'threadline_authors_bg': 'default',
+ 'threadline_authors_fg': '#6d6',
+ 'threadline_authors_linefocus_bg': 'g11',
+ 'threadline_authors_linefocus_fg': '#8d6',
+ 'threadline_bg': 'default',
+ 'threadline_content_bg': 'default',
+ 'threadline_content_fg': '#866',
+ 'threadline_date_bg': 'default',
+ 'threadline_date_fg': 'g58',
+ 'threadline_date_linefocus_bg': 'g11',
+ 'threadline_date_linefocus_fg': 'g58',
+ 'threadline_fg': 'default',
+ 'threadline_focus_bg': 'g11',
+ 'threadline_focus_fg': 'white',
+ 'threadline_mailcount_bg': 'default',
+ 'threadline_mailcount_fg': 'light gray',
+ 'threadline_mailcount_linefocus_bg': 'g11',
+ 'threadline_mailcount_linefocus_fg': 'light gray',
+ 'threadline_subject_bg': 'default',
+ 'threadline_subject_fg': 'g58',
+ 'threadline_subject_linefocus_bg': 'g11',
+ 'threadline_subject_linefocus_fg': 'g58',
+ 'threadline_tags_bg': 'default',
+ 'threadline_tags_fg': '#a86',
+ 'threadline_tags_linefocus_bg': 'g11',
+ 'threadline_tags_linefocus_fg': '#ff8',
+ },
+}
+
+
+class CustomConfigParser(SafeConfigParser):
+ def __init__(self, defaults):
+ self.defaults = defaults
+ SafeConfigParser.__init__(self)
+ for sec in defaults.keys():
+ self.add_section(sec)
+
+ def get(self, section, option, *args, **kwargs):
+ if self.has_option(section, option):
+ return SafeConfigParser.get(self, section, option, *args, **kwargs)
+ else:
+ return self.defaults[section][option]
+
def getstringlist(self, section, option, **kwargs):
value = SafeConfigParser.get(self, section, option, **kwargs)
return [s.strip() for s in value.split(',')]
-DEFAULTS = {
- 'colourmode': '16',
- 'editor_cmd': "/usr/bin/vim -f -c 'set filetype=mail' ",
- 'pager_cmd': "/usr/bin/view -f -c 'set filetype=mail' ",
- 'terminal_cmd': 'urxvt -T notmuch -e',
- 'spawn_editor': 'True',
- 'spawn_pager': 'True',
- 'displayed_headers': 'From,To,Cc,Bcc,Subject',
- 'authors_maxlength': '30',
-}
-config = ListConfigParser(DEFAULTS)
-config.add_section('general')
+config = CustomConfigParser(DEFAULTS)
+
def setup(configfilename):
config.read(configfilename)
-# colour palette.
-# id, fg16, bg16, mono, fg256, bg256
-# see http://excess.org/urwid/reference.html#AttrSpec
-# http://excess.org/urwid/wiki/DisplayAttributes
-# interactive test-palette: http://excess.org/urwid/browser/palette_test.py
-palette = [
- ('header', 'white', 'dark blue', 'bold', 'white', 'dark blue'),
- ('footer', 'white', 'dark blue', 'bold,standout', 'white', '#006'),
- ('prompt', 'light gray', 'black', 'standout', 'light gray', ''),
- ('threadline', '', '', '', '', ''),
- ('threadline_date', 'light gray', '', '', 'g58', ''),
- ('threadline_mailcount', 'light gray', '', '', 'light gray', ''),
- ('threadline_tags', 'brown', '', '', '#a86', ''),
- ('threadline_authors', 'dark green', '', '', '#6d6', ''),
- ('threadline_subject', 'light gray', '', '', 'g58', ''),
- ('threadline_content', 'dark gray', '', '', '#866', ''),
- ('threadline_focus', 'white', 'dark gray', 'standout', 'white', 'g11'),
- ('threadline_date_linefocus', 'light gray', 'dark gray', 'standout', 'g58', 'g11'),
- ('threadline_mailcount_linefocus', 'light gray', 'dark gray', 'standout', 'light gray', 'g11'),
- ('threadline_tags_linefocus', 'yellow,bold', 'dark gray', 'standout', '#ff8', 'g11'),
- ('threadline_authors_linefocus', 'dark green,bold', 'dark gray', 'standout','#8d6', 'g11'),
- ('threadline_subject_linefocus', 'light gray', 'dark gray', 'standout','g58', 'g11'),
-
- ('messagesummary_even', 'white', 'light blue', 'standout', 'white', '#068'),
- ('messagesummary_odd', 'white', 'dark blue', 'standout', 'white', '#006'),
- ('messagesummary_focus', 'white', 'dark green', 'standout,bold', '#ff8', 'g58'),
- ('message_header', 'white', 'dark gray', '', 'white', 'dark gray'),
- ('message_body', 'light gray', 'black', '', 'light gray', ''),
-
- ('bufferlist_results_even', 'light gray', 'black', '', '', 'g3'),
- ('bufferlist_results_odd', 'light gray', 'black', '', '', ''),
- ('bufferlist_focus', 'white', 'dark gray', '', '#ffa', 'g38'),
-
- ('taglist_tag', 'light gray', 'black', '', '', ''),
- ('taglist_focus', 'white', 'dark gray', '', '#ffa', 'g38'),
-]
+
+def get_palette():
+ p = list()
+ for attr in DEFAULTS['mono-theme'].keys():
+ p.append((
+ attr,
+ config.get('normal-theme', attr + '_fg'),
+ config.get('normal-theme', attr + '_bg'),
+ config.get('mono-theme', attr),
+ config.get('highcolour-theme', attr + '_fg'),
+ config.get('highcolour-theme', attr + '_bg'),
+ ))
+ return p
hooks = {
'pre-shutdown': lambda ui: ui.logger.info('goodbye!'),
diff --git a/alot/ui.py b/alot/ui.py
index 817797da..6a4bb7f7 100644
--- a/alot/ui.py
+++ b/alot/ui.py
@@ -19,7 +19,7 @@ Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com>
import urwid
from settings import config
-from settings import palette
+from settings import get_palette
import command
from widgets import PromptWidget
from buffer import BufferListBuffer
@@ -38,7 +38,7 @@ class UI:
self.logger.info('setup gui in %d colours' % colourmode)
self.mainframe = urwid.Frame(urwid.SolidFill(' '))
self.mainloop = urwid.MainLoop(self.mainframe,
- palette,
+ get_palette(),
handle_mouse=False,
unhandled_input=self.keypress)
self.mainloop.screen.set_terminal_properties(colors=colourmode)
diff --git a/data/example.rc b/data/example.rc
index 2e218cf9..3a8f4982 100644
--- a/data/example.rc
+++ b/data/example.rc
@@ -1,5 +1,5 @@
[general]
-colourmode = 256 ; number of colours your terminal supports
+colourmode = 16 ; number of colours your terminal supports
colourpalette = palette.py
hooks = hooks.py
editor_cmd = /usr/bin/vim -f -c 'set filetype=mail'
@@ -8,4 +8,140 @@ terminal_cmd = /usr/bin/urxvt -T notmuch -e
spawn_editor = True
spawn_pager = True
authors_maxlength = 30
-displayed_headers = 'From,To,Cc,Bcc,Subject'
+displayed_headers = From,To,Cc,Bcc,Subject
+
+[normal-theme]
+threadline_bg = default
+threadline_date_bg = default
+bufferlist_results_even_bg = black
+messagesummary_even_fg = white
+footer_fg = white
+threadline_date_fg = light gray
+bufferlist_results_even_fg = light gray
+threadline_content_fg = dark gray
+threadline_date_linefocus_bg = dark gray
+threadline_subject_linefocus_bg = dark gray
+threadline_date_linefocus_fg = light gray
+messagesummary_even_bg = light blue
+message_body_fg = light gray
+threadline_fg = default
+taglist_focus_bg = dark gray
+threadline_mailcount_fg = light gray
+threadline_focus_fg = white
+taglist_focus_fg = white
+messagesummary_focus_bg = dark green
+threadline_mailcount_bg = default
+messagesummary_focus_fg = white
+message_body_bg = black
+threadline_tags_linefocus_bg = dark gray
+taglist_tag_bg = black
+threadline_focus_bg = dark gray
+threadline_tags_linefocus_fg = yellow,bold
+threadline_authors_bg = default
+threadline_authors_fg = dark green
+bufferlist_focus_fg = white
+bufferlist_focus_bg = dark gray
+threadline_subject_fg = light gray
+bufferlist_results_odd_fg = light gray
+threadline_mailcount_linefocus_bg = dark gray
+threadline_subject_bg = default
+messagesummary_odd_fg = white
+threadline_mailcount_linefocus_fg = light gray
+message_header_fg = white
+prompt_fg = light gray
+header_bg = dark blue
+messagesummary_odd_bg = dark blue
+threadline_subject_linefocus_fg = light gray
+threadline_content_bg = default
+prompt_bg = black
+header_fg = white
+taglist_tag_fg = light gray
+bufferlist_results_odd_bg = black
+threadline_tags_fg = brown
+threadline_tags_bg = default
+footer_bg = dark blue
+threadline_authors_linefocus_bg = dark gray
+threadline_authors_linefocus_fg = dark green,bold
+message_header_bg = dark gray
+
+[mono-theme]
+bufferlist_focus = standout
+bufferlist_results_even = default
+bufferlist_results_odd = default
+footer = bold
+header = bold
+message_body = default
+message_header = default
+messagesummary_even = standout
+messagesummary_focus = standout
+messagesummary_odd = standout
+prompt = standout
+taglist_focus = standout
+taglist_tag = default
+threadline = default
+threadline_authors = default
+threadline_authors_linefocus = standout
+threadline_content = default
+threadline_date = default
+threadline_date_linefocus = standout
+threadline_focus = standout
+threadline_mailcount = default
+threadline_mailcount_linefocus = standout
+threadline_subject = default
+threadline_subject_linefocus = standout
+threadline_tags = default
+threadline_tags_linefocus = standout
+
+[highcolour-theme]
+bufferlist_focus_bg = g38
+bufferlist_focus_fg = #ffa
+bufferlist_results_even_bg = g3
+bufferlist_results_even_fg = default
+bufferlist_results_odd_bg = default
+bufferlist_results_odd_fg = default
+footer_bg = #006
+footer_fg = white
+header_bg = dark blue
+header_fg = white
+message_body_bg = default
+message_body_fg = light gray
+message_header_bg = dark gray
+message_header_fg = white
+messagesummary_even_bg = #068
+messagesummary_even_fg = white
+messagesummary_focus_bg = g58
+messagesummary_focus_fg = #ff8
+messagesummary_odd_bg = #006
+messagesummary_odd_fg = white
+prompt_bg = default
+prompt_fg = light gray
+taglist_focus_bg = g38
+taglist_focus_fg = #ffa
+taglist_tag_bg = default
+taglist_tag_fg = default
+threadline_authors_bg = default
+threadline_authors_fg = #6d6
+threadline_authors_linefocus_bg = g11
+threadline_authors_linefocus_fg = #8d6
+threadline_bg = default
+threadline_content_bg = default
+threadline_content_fg = #866
+threadline_date_bg = default
+threadline_date_fg = g58
+threadline_date_linefocus_bg = g11
+threadline_date_linefocus_fg = g58
+threadline_fg = default
+threadline_focus_bg = g11
+threadline_focus_fg = white
+threadline_mailcount_bg = default
+threadline_mailcount_fg = light gray
+threadline_mailcount_linefocus_bg = g11
+threadline_mailcount_linefocus_fg = light gray
+threadline_subject_bg = default
+threadline_subject_fg = g58
+threadline_subject_linefocus_bg = g11
+threadline_subject_linefocus_fg = g58
+threadline_tags_bg = default
+threadline_tags_fg = #a86
+threadline_tags_linefocus_bg = g11
+threadline_tags_linefocus_fg = #ff8