forked from mailpile/Mailpile
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathretrydialog.py
More file actions
58 lines (49 loc) · 1.82 KB
/
Copy pathretrydialog.py
File metadata and controls
58 lines (49 loc) · 1.82 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import logging
import urwid
from .widgets import *
from .messagedialog import MessageDialog
class RetryDialog(MessageDialog):
def __init__(self, tui_frame, emsg):
self.emsg = emsg
self.doingit = False
self.needed_info = emsg['exc_data'].get('need')
self.retry = emsg['request']
super().__init__(tui_frame, emsg['error'])
def make_buttons(self):
return [
CancelButton(lambda x: self._emit('close'), style='popsubtle'),
SimpleButton('Retry', lambda x: self.on_ok(), style='popsubtle')]
def make_widgets(self):
e_args = [
('allow_tab', False),
('wrap', 'clip'),
('multiline', False)]
e_more = {
'password': [('mask', '*')]}
widgets = []
for need in (self.needed_info or []):
a = dict(e_args + e_more.get(need['datatype'], []))
w = EditLine(need['label'] + ': ', **a)
widgets.append(w)
urwid.connect_signal(w, 'enter', lambda b: self.focus_next())
widgets.append(urwid.Divider())
return widgets
def validate(self):
valid = 0
for i, widget in enumerate(self.widgets):
logging.debug('Validating %d/%s' % (i, widget))
if i >= len(self.needed_info):
break
need = self.needed_info[i]
info = widget.edit_text.replace('\n', '')
# FIXME: Actual validation? Give user feedback?
if info:
self.retry[need['field']] = info
valid += 1
logging.debug('Validated %d fields' % valid)
return valid
def on_ok(self):
completed = self.validate()
if completed == len(self.needed_info):
self._emit('close')
self.tui_frame.conn_manager.send(self.retry)