summaryrefslogtreecommitdiff
path: root/alot/widgets/globals.py
diff options
context:
space:
mode:
authorPatrick Totzke <patricktotzke@gmail.com>2013-06-24 14:06:56 +0100
committerPatrick Totzke <patricktotzke@gmail.com>2013-07-07 18:06:18 +0100
commitbd34e0fe5310941f7288bb6062d22eb579205a09 (patch)
treef7ef24930ed07eb64f3e99f2afe8dd62aeffa131 /alot/widgets/globals.py
parentc4990d755add6c627ae9f780fd68b16bcca1da05 (diff)
handle CompletionErrors
this makes the CompleteEdit widget handle errors raised during completions by passing them on to a 'on_error' callback given to its constructor. This is then used in UI.prompt.
Diffstat (limited to 'alot/widgets/globals.py')
-rw-r--r--alot/widgets/globals.py20
1 files changed, 14 insertions, 6 deletions
diff --git a/alot/widgets/globals.py b/alot/widgets/globals.py
index d9e7fadb..785285af 100644
--- a/alot/widgets/globals.py
+++ b/alot/widgets/globals.py
@@ -10,6 +10,7 @@ import urwid
from alot.helper import string_decode
from alot.settings import settings
from alot.db.attachment import Attachment
+from alot.errors import CompletionError
class AttachmentWidget(urwid.WidgetWrap):
@@ -71,10 +72,11 @@ class ChoiceWidget(urwid.Text):
class CompleteEdit(urwid.Edit):
- def __init__(self, completer, on_exit, edit_text=u'',
- history=None, **kwargs):
+ def __init__(self, completer, on_exit, edit_text=u'', history=None,
+ on_error=None, **kwargs):
self.completer = completer
self.on_exit = on_exit
+ self.on_error = on_error
self.history = list(history) # we temporarily add stuff here
self.historypos = None
@@ -88,10 +90,16 @@ class CompleteEdit(urwid.Edit):
# if we tabcomplete
if key in ['tab', 'shift tab'] and self.completer:
# if not already in completion mode
- if not self.completions:
- self.completions = [(self.edit_text, self.edit_pos)] + \
- self.completer.complete(self.edit_text, self.edit_pos)
- self.focus_in_clist = 1
+ if self.completions is None:
+ self.completions = [(self.edit_text, self.edit_pos)]
+ try:
+ self.completions += self.completer.complete(self.edit_text,
+ self.edit_pos)
+ self.focus_in_clist = 1
+ except CompletionError, e:
+ if self.on_error is not None:
+ self.on_error(e)
+
else: # otherwise tab through results
if key == 'tab':
self.focus_in_clist += 1