diff options
author | Dylan Baker <baker.dylan.c@gmail.com> | 2018-02-08 11:06:06 -0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-02-08 11:06:06 -0800 |
commit | 7091048adf3e4455fb2e3adfe27ce1e10165a5e3 (patch) | |
tree | 7dce25542adaed372aed78122b7ee29a049bb53a | |
parent | 7a37daee30c271e2aca7546bee910d419e4c2998 (diff) | |
parent | d16bc108a17786e0bacc174106dfce779361e548 (diff) |
Merge pull request #1172 from Dica-Developer/patch-4
Fix for issue 1164 - Cannot select key for encryption by number keys
-rw-r--r-- | alot/commands/utils.py | 17 | ||||
-rw-r--r-- | alot/ui.py | 12 | ||||
-rw-r--r-- | alot/widgets/globals.py | 5 |
3 files changed, 22 insertions, 12 deletions
diff --git a/alot/commands/utils.py b/alot/commands/utils.py index 7e4e0307..b7915378 100644 --- a/alot/commands/utils.py +++ b/alot/commands/utils.py @@ -90,15 +90,16 @@ def _get_keys(ui, encrypt_keyids, block_error=False, signed_only=False): signed_only=signed_only) except GPGProblem as e: if e.code == GPGCode.AMBIGUOUS_NAME: - tmp_choices = [k.uids[0].uid for k in + tmp_choices = ['{} ({})'.format(k.uids[0].uid, k.fpr) for k in crypto.list_keys(hint=keyid)] - choices = {str(i): t for i, t in - enumerate(reversed(tmp_choices), 1)} - keyid = yield ui.choice("ambiguous keyid! Which " + - "key do you want to use?", - choices, cancel=None) - if keyid: - encrypt_keyids.append(keyid) + choices = {str(i): t for i, t in enumerate(tmp_choices, 1)} + keys_to_return = {str(i): t for i, t in enumerate([k for k in + crypto.list_keys(hint=keyid)], 1)} + choosen_key = yield ui.choice("ambiguous keyid! Which " + + "key do you want to use?", + choices, keys_to_return) + if choosen_key: + keys[choosen_key.fpr] = choosen_key continue else: ui.notify(str(e), priority='error', block=block_error) @@ -484,7 +484,7 @@ class UI(object): self.update() def choice(self, message, choices=None, select=None, cancel=None, - msg_position='above'): + msg_position='above', choices_to_return=None): """ prompt user to make a choice. @@ -492,6 +492,9 @@ class UI(object): :type message: unicode :param choices: dict of possible choices :type choices: dict: keymap->choice (both str) + :param choices_to_return: dict of possible choices to return for the + choices of the choices of paramter + :type choices: dict: keymap->choice key is str and value is any obj) :param select: choice to return if enter/return is hit. Ignored if set to `None`. :type select: str @@ -504,6 +507,7 @@ class UI(object): :rtype: :class:`twisted.defer.Deferred` """ choices = choices or {'y': 'yes', 'n': 'no'} + choices_to_return = choices_to_return or {} assert select is None or select in choices.itervalues() assert cancel is None or cancel in choices.itervalues() assert msg_position in ['left', 'above'] @@ -520,8 +524,10 @@ class UI(object): # set up widgets msgpart = urwid.Text(message) - choicespart = ChoiceWidget(choices, callback=select_or_cancel, - select=select, cancel=cancel) + choicespart = ChoiceWidget(choices, + choices_to_return=choices_to_return, + callback=select_or_cancel, select=select, + cancel=cancel) # build widget if msg_position == 'left': diff --git a/alot/widgets/globals.py b/alot/widgets/globals.py index 3aea7622..1a8688fe 100644 --- a/alot/widgets/globals.py +++ b/alot/widgets/globals.py @@ -45,8 +45,9 @@ class AttachmentWidget(urwid.WidgetWrap): class ChoiceWidget(urwid.Text): def __init__(self, choices, callback, cancel=None, select=None, - separator=' '): + separator=' ', choices_to_return=None): self.choices = choices + self.choices_to_return = choices_to_return or {} self.callback = callback self.cancel = cancel self.select = select @@ -69,6 +70,8 @@ class ChoiceWidget(urwid.Text): self.callback(self.select) elif key == 'esc' and self.cancel is not None: self.callback(self.cancel) + elif key in self.choices_to_return: + self.callback(self.choices_to_return[key]) elif key in self.choices: self.callback(self.choices[key]) else: |