From cf1d24bee09b20a61321aa70b6169a56d2abf8db Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Sat, 18 Feb 2012 16:59:43 +0000 Subject: replace config.get_* with settings.get this changes all "small" calls to a config getter toa theyr counterparts that call SettingsManager.get --- alot/buffers.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'alot/buffers.py') diff --git a/alot/buffers.py b/alot/buffers.py index b7d7cd8b..8e5d4c77 100644 --- a/alot/buffers.py +++ b/alot/buffers.py @@ -2,13 +2,14 @@ import urwid from notmuch.globals import NotmuchError import widgets -import settings +from settings import settings import commands from walker import PipeWalker from helper import shorten_author_string from db import NonexistantObjectError + class Buffer(object): """Abstract base class for buffers.""" @@ -105,8 +106,7 @@ class EnvelopeBuffer(Buffer): def rebuild(self): displayed_widgets = [] - hidden = settings.config.getstringlist('general', - 'envelope_headers_blacklist') + hidden = settings.get('envelope_headers_blacklist') #build lines lines = [] for (k, vlist) in self.envelope.headers.items(): @@ -145,8 +145,7 @@ class SearchBuffer(Buffer): self.dbman = ui.dbman self.ui = ui self.querystring = initialquery - default_order = settings.config.get('general', - 'search_threads_sort_order') + default_order = settings.get('search_threads_sort_order') self.sort_order = sort_order or default_order self.result_count = 0 self.isinitialized = False -- cgit v1.2.3 From 813a563735e76bdb2517f9e0fc314cc27e939269 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Sat, 18 Feb 2012 23:45:25 +0000 Subject: switch to new theming handling in widgets and UI --- alot/buffers.py | 7 ++++--- alot/commands/globals.py | 6 ++++-- alot/ui.py | 13 ++++++++----- alot/widgets.py | 29 ++++++++++++++++++----------- setup.py | 1 + 5 files changed, 35 insertions(+), 21 deletions(-) (limited to 'alot/buffers.py') diff --git a/alot/buffers.py b/alot/buffers.py index 8e5d4c77..43982369 100644 --- a/alot/buffers.py +++ b/alot/buffers.py @@ -71,10 +71,11 @@ class BufferlistBuffer(Buffer): for (num, b) in enumerate(displayedbuffers): line = widgets.BufferlineWidget(b) if (num % 2) == 0: - attr = 'bufferlist_results_even' + attr = settings.get_theming_attribute('bufferlist', 'results_even') else: - attr = 'bufferlist_results_odd' - buf = urwid.AttrMap(line, attr, 'bufferlist_focus') + attr = settings.get_theming_attribute('bufferlist', 'results_odd') + focus_att = settings.get_theming_attribute('bufferlist', 'focus') + buf = urwid.AttrMap(line, attr, focus_att) num = urwid.Text('%3d:' % self.index_of(b)) lines.append(urwid.Columns([('fixed', 4, num), buf])) self.bufferlist = urwid.ListBox(urwid.SimpleListWalker(lines)) diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 81385456..48f52cb0 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -414,9 +414,11 @@ class HelpCommand(Command): ckey = 'cancel' titletext = 'Bindings Help (%s cancels)' % ckey + text_att = settings.get_theming_attribute('help', 'text') + title_att = settings.get_theming_attribute('help', 'title') box = widgets.DialogBox(body, titletext, - bodyattr='help_text', - titleattr='help_title') + bodyattr=text_att, + titleattr=title_att) # put promptwidget as overlay on main widget overlay = urwid.Overlay(box, ui.mainframe, 'center', diff --git a/alot/ui.py b/alot/ui.py index 99678a7d..f2ac65cf 100644 --- a/alot/ui.py +++ b/alot/ui.py @@ -94,7 +94,6 @@ class UI(object): self.mainframe = urwid.Frame(urwid.SolidFill()) self.inputwrap = InputWrap(self, self.mainframe) self.mainloop = urwid.MainLoop(self.inputwrap, - config.get_palette(), #todo: remove handle_mouse=False, event_loop=urwid.TwistedEventLoop(), unhandled_input=self.unhandeled_input) @@ -171,7 +170,8 @@ class UI(object): ('fixed', len(prefix), leftpart), ('weight', 1, editpart), ]) - both = urwid.AttrMap(both, 'global_prompt') + att = settings.get_theming_attribute('global', 'prompt') + both = urwid.AttrMap(both, att) # put promptwidget as overlay on main widget overlay = urwid.Overlay(both, oldroot, @@ -315,7 +315,8 @@ class UI(object): ], dividechars=1) else: # above both = urwid.Pile([msgpart, choicespart]) - both = urwid.AttrMap(both, 'prompt', 'prompt') + att = settings.get_theming_attribute('global', 'prompt') + both = urwid.AttrMap(both, att, att) # put promptwidget as overlay on main widget overlay = urwid.Overlay(both, oldroot, @@ -349,7 +350,8 @@ class UI(object): """ def build_line(msg, prio): cols = urwid.Columns([urwid.Text(msg)]) - return urwid.AttrMap(cols, 'global_notify_' + prio) + att = settings.get_theming_attribute('global', 'notify_' + prio) + return urwid.AttrMap(cols, att) msgs = [build_line(message, priority)] if not self.notificationbar: @@ -422,7 +424,8 @@ class UI(object): columns = urwid.Columns([ footerleft, ('fixed', len(righttxt), footerright)]) - return urwid.AttrMap(columns, 'global_footer') + footer_att = settings.get_theming_attribute('global', 'footer') + return urwid.AttrMap(columns, footer_att) def apply_command(self, cmd): """ diff --git a/alot/widgets.py b/alot/widgets.py index da3e4d73..01e7363e 100644 --- a/alot/widgets.py +++ b/alot/widgets.py @@ -77,8 +77,9 @@ class ThreadlineWidget(urwid.AttrMap): self.tag_widgets = [] self.display_content = settings.get('display_content_in_threadline') self.rebuild() - urwid.AttrMap.__init__(self, self.columns, - 'search_thread', 'search_thread_focus') + normal = settings.get_theming_attribute('search', 'thread') + focussed = settings.get_theming_attribute('search', 'thread_focus') + urwid.AttrMap.__init__(self, self.columns, normal, focussed) def rebuild(self): cols = [] @@ -563,9 +564,9 @@ class MessageSummaryWidget(urwid.WidgetWrap): self.message = message self.even = even if even: - attr = 'thread_summary_even' + attr = settings.get_theming_attribute('thread', 'summary_even') else: - attr = 'thread_summary_odd' + attr = settings.get_theming_attribute('thread', 'summary_odd') cols = [] sumstr = self.__str__() @@ -578,8 +579,9 @@ class MessageSummaryWidget(urwid.WidgetWrap): tag_widgets.sort(tag_cmp, lambda tag_widget: tag_widget.translated) for tag_widget in tag_widgets: cols.append(('fixed', tag_widget.width(), tag_widget)) + focus_att = settings.get_theming_attribute('thread', 'summary_focus') line = urwid.AttrMap(urwid.Columns(cols, dividechars=1), attr, - 'thread_summary_focus') + focus_att) urwid.WidgetWrap.__init__(self, line) def __str__(self): @@ -609,7 +611,8 @@ class HeadersList(urwid.WidgetWrap): def __init__(self, headerslist): self.headers = headerslist pile = urwid.Pile(self._build_lines(headerslist)) - pile = urwid.AttrMap(pile, 'thread_header') + att = settings.get_theming_attribute('thread', 'header') + pile = urwid.AttrMap(pile, att) urwid.WidgetWrap.__init__(self, pile) def __str__(self): @@ -618,6 +621,8 @@ class HeadersList(urwid.WidgetWrap): def _build_lines(self, lines): max_key_len = 1 headerlines = [] + key_att = settings.get_theming_attribute('thread', 'header_key') + value_att = settings.get_theming_attribute('thread', 'header_value') #calc max length of key-string for key, value in lines: if len(key) > max_key_len: @@ -625,8 +630,8 @@ class HeadersList(urwid.WidgetWrap): for key, value in lines: ##todo : even/odd keyw = ('fixed', max_key_len + 1, - urwid.Text(('thread_header_key', key))) - valuew = urwid.Text(('thread_header_value', value)) + urwid.Text((key_att, key))) + valuew = urwid.Text((value_att, value)) line = urwid.Columns([keyw, valuew]) headerlines.append(line) return headerlines @@ -642,7 +647,8 @@ class MessageBodyWidget(urwid.AttrMap): def __init__(self, msg): bodytxt = message.extract_body(msg) - urwid.AttrMap.__init__(self, urwid.Text(bodytxt), 'thread_body') + att = settings.get_theming_attribute('thread', 'body') + urwid.AttrMap.__init__(self, urwid.Text(bodytxt), att) class AttachmentWidget(urwid.WidgetWrap): @@ -658,9 +664,10 @@ class AttachmentWidget(urwid.WidgetWrap): self.attachment = attachment if not isinstance(attachment, message.Attachment): self.attachment = message.Attachment(self.attachment) + att = settings.get_theming_attribute('thread', 'attachment') + focus_att = settings.get_theming_attribute('thread', 'attachment_focus') widget = urwid.AttrMap(urwid.Text(self.attachment.__str__()), - 'thread_attachment', - 'thread_attachment_focus') + att, focus_att) urwid.WidgetWrap.__init__(self, widget) def get_attachment(self): diff --git a/setup.py b/setup.py index d6e6b4e0..98ee78f6 100755 --- a/setup.py +++ b/setup.py @@ -14,6 +14,7 @@ setup(name='alot', packages=['alot', 'alot.commands'], package_data={'alot': [ 'defaults/alot.rc', # only old-style default values + 'defaults/alot.rc.new', 'defaults/alot.rc.spec', 'defaults/notmuch.rc.spec', 'defaults/default.theme', # default theme -- cgit v1.2.3 From 278e20ba759cc9045c9273f4e64314305f108f24 Mon Sep 17 00:00:00 2001 From: Patrick Totzke Date: Sun, 19 Feb 2012 15:37:30 +0000 Subject: pep8/pyflakes cleanup --- alot/buffers.py | 7 ++++--- alot/commands/envelope.py | 5 ++--- alot/commands/globals.py | 1 - alot/commands/thread.py | 2 -- alot/completion.py | 5 ++++- alot/helper.py | 1 - alot/message.py | 1 - alot/settings.py | 29 +++++++++++++++-------------- alot/ui.py | 4 +--- 9 files changed, 26 insertions(+), 29 deletions(-) (limited to 'alot/buffers.py') diff --git a/alot/buffers.py b/alot/buffers.py index 43982369..3f4a6353 100644 --- a/alot/buffers.py +++ b/alot/buffers.py @@ -9,7 +9,6 @@ from helper import shorten_author_string from db import NonexistantObjectError - class Buffer(object): """Abstract base class for buffers.""" @@ -71,9 +70,11 @@ class BufferlistBuffer(Buffer): for (num, b) in enumerate(displayedbuffers): line = widgets.BufferlineWidget(b) if (num % 2) == 0: - attr = settings.get_theming_attribute('bufferlist', 'results_even') + attr = settings.get_theming_attribute('bufferlist', + 'results_even') else: - attr = settings.get_theming_attribute('bufferlist', 'results_odd') + attr = settings.get_theming_attribute('bufferlist', + 'results_odd') focus_att = settings.get_theming_attribute('bufferlist', 'focus') buf = urwid.AttrMap(line, attr, focus_att) num = urwid.Text('%3d:' % self.index_of(b)) diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index d821d47b..8b95783b 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -5,7 +5,6 @@ import logging import email import tempfile from twisted.internet.defer import inlineCallbacks -from twisted.internet import threads import datetime from alot.account import SendingMailFailed @@ -121,7 +120,6 @@ class SendCommand(Command): return frm = envelope.get('From') sname, saddr = email.Utils.parseaddr(frm) - omit_signature = False # determine account to use for sending account = settings.get_account_by_address(saddr) @@ -218,7 +216,8 @@ class EditCommand(Command): # call post-edit translate hook translate = settings.get_hook('post_edit_translate') if translate: - template = translate(template, ui=ui, dbm=ui.dbman, config=settings) + template = translate(template, ui=ui, dbm=ui.dbman, + config=settings) self.envelope.parse_template(template) if self.openNew: ui.buffer_open(buffers.EnvelopeBuffer(ui, self.envelope)) diff --git a/alot/commands/globals.py b/alot/commands/globals.py index f5c52a1b..db944a00 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -15,7 +15,6 @@ from alot.completion import CommandLineCompleter from alot.commands import CommandParseError from alot.commands import commandfactory from alot import buffers -from alot import settings from alot import widgets from alot import helper from alot.db import DatabaseLockedError diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 2707a533..7ffb9b98 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -12,7 +12,6 @@ from alot.commands.globals import ExternalCommand from alot.commands.globals import FlushCommand from alot.commands.globals import ComposeCommand from alot.commands.globals import RefreshCommand -from alot import settings from alot import widgets from alot import completion from alot.message import decode_header @@ -21,7 +20,6 @@ from alot.message import extract_headers from alot.message import extract_body from alot.message import Envelope from alot.db import DatabaseROError -from alot.db import DatabaseError from alot.settings import settings MODE = 'thread' diff --git a/alot/completion.py b/alot/completion.py index caa13c00..e9e44226 100644 --- a/alot/completion.py +++ b/alot/completion.py @@ -8,6 +8,7 @@ import alot.commands as commands from alot.buffers import EnvelopeBuffer from alot.settings import settings + class Completer(object): """base class for completers""" def complete(self, original, pos): @@ -207,6 +208,7 @@ class AbooksCompleter(Completer): returnlist.append((newtext, len(newtext))) return returnlist + class ArgparseOptionCompleter(Completer): """completes option parameters for a given argparse.Parser""" def __init__(self, parser): @@ -223,7 +225,7 @@ class ArgparseOptionCompleter(Completer): res = [] for act in self.actions: if '=' in pref: - optionstring = pref[:pref.rfind('=')+1] + optionstring = pref[:pref.rfind('=') + 1] # get choices if 'choices' in act.__dict__: choices = act.choices or [] @@ -238,6 +240,7 @@ class ArgparseOptionCompleter(Completer): return [(a, len(a)) for a in res] + class AccountCompleter(StringlistCompleter): """completes users' own mailaddresses""" diff --git a/alot/helper.py b/alot/helper.py index bc5dc962..bfd9e1d0 100644 --- a/alot/helper.py +++ b/alot/helper.py @@ -18,7 +18,6 @@ import StringIO import logging - def safely_get(clb, E, on_error=''): """ returns result of :func:`clb` and falls back to `on_error` diff --git a/alot/message.py b/alot/message.py index 1557b7fa..75f204c2 100644 --- a/alot/message.py +++ b/alot/message.py @@ -16,7 +16,6 @@ from alot import __version__ import logging import helper from settings import get_mime_handler -from settings import config from settings import settings from helper import string_sanitize from helper import string_decode diff --git a/alot/settings.py b/alot/settings.py index f18a9ec8..aec7adfb 100644 --- a/alot/settings.py +++ b/alot/settings.py @@ -18,9 +18,11 @@ from ConfigParser import SafeConfigParser, ParsingError, NoOptionError DEFAULTSPATH = os.path.join(os.path.dirname(__file__), 'defaults') + class ConfigError(Exception): pass + def read_config(configpath=None, specpath=None): try: config = ConfigObj(infile=configpath, configspec=specpath, @@ -57,7 +59,7 @@ class Theme(object): try: colours = int(sec) except ValueError: - err_msg='section %s is not an integer indicating a colour mode' + err_msg = 'section name %s is not a valid colour mode' raise ConfigError(err_msg % sec) attributes[colours] = {} for mode in c[sec].sections: @@ -79,7 +81,6 @@ class Theme(object): attributes[colours][mode][themable] = att return attributes - def get_attribute(self, mode, name, colourmode): return self.attributes[colourmode][mode][name] @@ -99,7 +100,6 @@ class SettingsManager(object): self._accounts = self.parse_accounts(self._config) self._accountmap = self._account_table(self._accounts) - def read_notmuch_config(self, path): spec = os.path.join(DEFAULTSPATH, 'notmuch.rc.spec') self._notmuchconfig = read_config(path, spec) @@ -183,24 +183,24 @@ class SettingsManager(object): def get_tagstring_representation(self, tag): colours = int(self._config.get('colourmode')) - default_att = self.theme.get_attribute('global', 'tag', colours) - default_focus_att = self.theme.get_attribute('global', 'tag_focus', - colours) + # default attributes: normal and focussed + default = self.theme.get_attribute('global', 'tag', colours) + default_f = self.theme.get_attribute('global', 'tag_focus', colours) if tag in self._config['tags']: - fg = self._config['tags'][tag]['fg'] or default_att.foreground - bg = self._config['tags'][tag]['bg'] or default_att.background + fg = self._config['tags'][tag]['fg'] or default.foreground + bg = self._config['tags'][tag]['bg'] or default.background normal = urwid.AttrSpec(fg, bg, colours) - ffg = self._config['tags'][tag]['focus_fg'] or default_focus_att.foreground - fbg = self._config['tags'][tag]['focus_bg'] or default_focus_att.background + ffg = self._config['tags'][tag]['focus_fg'] or default_f.foreground + fbg = self._config['tags'][tag]['focus_bg'] or default_f.background focussed = urwid.AttrSpec(ffg, fbg, colours) translated = self._config['tags'][tag]['translated'] or tag else: - normal = default_att - focussed = default_focus_att + normal = default + focussed = default_f translated = tag - return {'normal': normal, 'focussed': focussed, 'translated': translated} - + return {'normal': normal, 'focussed': focussed, + 'translated': translated} def get_hook(self, key): """return hook (`callable`) identified by `key`""" @@ -270,6 +270,7 @@ class SettingsManager(object): abooks.append(a.abook) return abooks + class FallbackConfigParser(SafeConfigParser): """:class:`~ConfigParser.SafeConfigParser` that allows fallback values""" def __init__(self): diff --git a/alot/ui.py b/alot/ui.py index b9de9c8c..032f627b 100644 --- a/alot/ui.py +++ b/alot/ui.py @@ -1,9 +1,7 @@ import urwid import logging from twisted.internet import reactor, defer -from twisted.python.failure import Failure -from settings import config from settings import settings from buffers import BufferlistBuffer import commands @@ -84,7 +82,7 @@ class UI(object): self.dbman = dbman if not colourmode: - # needs explicit int-constructor because we used "options" in specfile + # explicit int-constructor because we used "options" in specfile colourmode = int(settings.get('colourmode')) logging.info('setup gui in %d colours' % colourmode) self.mainframe = urwid.Frame(urwid.SolidFill()) -- cgit v1.2.3