diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2012-01-21 23:13:11 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2012-01-21 23:13:11 +0000 |
commit | 35f0e9d37af17ab69f591e4bdbcfeb767bf75453 (patch) | |
tree | f07ac2fb3840d036da968e33bb95973326b8fc0f | |
parent | 53be4831e8a183c4f0fd56f73294acb509fda51c (diff) |
replace buffer.typename with class var 'modename'
this allows for easier mode name extraction at class level
for auto-generating the user docs
-rw-r--r-- | alot/buffers.py | 34 | ||||
-rw-r--r-- | alot/commands/globals.py | 4 | ||||
-rw-r--r-- | alot/ui.py | 2 |
3 files changed, 28 insertions, 12 deletions
diff --git a/alot/buffers.py b/alot/buffers.py index bf16d1d4..b544c06d 100644 --- a/alot/buffers.py +++ b/alot/buffers.py @@ -11,13 +11,15 @@ from db import NonexistantObjectError class Buffer(object): """Abstract base class for buffers.""" - def __init__(self, ui, widget, name): + + modename = None # mode identifier for subclasses + + def __init__(self, ui, widget): self.ui = ui - self.typename = name self.body = widget def __str__(self): - return '[%s]' % self.typename + return '[%s]' % self.modename def render(self, size, focus=False): return self.body.render(size, focus) @@ -39,12 +41,15 @@ class Buffer(object): class BufferlistBuffer(Buffer): """selectable list of active buffers""" + + modename = 'bufferlist' + def __init__(self, ui, filtfun=None): self.filtfun = filtfun self.ui = ui self.isinitialized = False self.rebuild() - Buffer.__init__(self, ui, self.body, 'bufferlist') + Buffer.__init__(self, ui, self.body) def index_of(self, b): """ @@ -84,16 +89,19 @@ class BufferlistBuffer(Buffer): class EnvelopeBuffer(Buffer): """message composition mode""" + + modename = 'envelope' + def __init__(self, ui, envelope): self.ui = ui self.envelope = envelope self.all_headers = False self.rebuild() - Buffer.__init__(self, ui, self.body, 'envelope') + Buffer.__init__(self, ui, self.body) def __str__(self): to = self.envelope.get('To', fallback='unset') - return '[%s] to: %s' % (self.typename, shorten_author_string(to, 400)) + return '[envelope] to: %s' % (shorten_author_string(to, 400)) def rebuild(self): displayed_widgets = [] @@ -132,6 +140,8 @@ class SearchBuffer(Buffer): shows a result set for a Thread query, one line per :class:`~alot.db.Thread` """ + + modename = 'search' threads = [] def __init__(self, ui, initialquery='', sort_order=None): @@ -145,7 +155,7 @@ class SearchBuffer(Buffer): self.isinitialized = False self.proc = None # process that fills our pipe self.rebuild() - Buffer.__init__(self, ui, self.body, 'search') + Buffer.__init__(self, ui, self.body) def __str__(self): formatstring = '[search] for "%s" (%d thread%s)' @@ -212,11 +222,14 @@ class SearchBuffer(Buffer): class ThreadBuffer(Buffer): """shows a single mailthread as a (collapsible) tree of :class:`MessageWidgets <alot.widgets.MessageWidget>`.""" + + modename = 'thread' + def __init__(self, ui, thread): self.message_count = thread.get_total_messages() self.thread = thread self.rebuild() - Buffer.__init__(self, ui, self.body, 'thread') + Buffer.__init__(self, ui, self.body) def __str__(self): return '[thread] %s (%d message%s)' % (self.thread.get_subject(), @@ -311,13 +324,16 @@ class ThreadBuffer(Buffer): class TagListBuffer(Buffer): """selectable list of tagstrings present in the database""" + + modename = 'taglist' + def __init__(self, ui, alltags=[], filtfun=None): self.filtfun = filtfun self.ui = ui self.tags = alltags self.isinitialized = False self.rebuild() - Buffer.__init__(self, ui, self.body, 'taglist') + Buffer.__init__(self, ui, self.body) def rebuild(self): if self.isinitialized: diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 12d82dcb..28903894 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -87,7 +87,7 @@ class PromptCommand(Command): @inlineCallbacks def apply(self, ui): logging.info('open command shell') - mode = ui.current_buffer.typename + mode = ui.current_buffer.modename cmdline = yield ui.prompt(prefix=':', text=self.startwith, completer=CommandLineCompleter(ui.dbman, @@ -104,7 +104,7 @@ class PromptCommand(Command): # save into prompt history ui.commandprompthistory.append(cmdline) - mode = ui.current_buffer.typename + mode = ui.current_buffer.modename try: cmd = commandfactory(cmdline, mode) ui.apply_command(cmd) @@ -226,7 +226,7 @@ class UI(object): if self.current_buffer != buf: self.current_buffer = buf self.inputwrap.set_root(self.mainframe) - self.mode = buf.typename + self.mode = buf.modename if isinstance(self.current_buffer, BufferlistBuffer): self.current_buffer.rebuild() self.update() |