make help appear in same place on identity view as before

This commit is contained in:
Michael Hudson-Doyle 2017-02-13 15:50:39 +13:00
parent a2062aaf57
commit 3353c851ee
3 changed files with 31 additions and 24 deletions

View File

@ -15,20 +15,20 @@
import logging
from urwid import Text
from urwid import connect_signal
from subiquitycore.ui.buttons import done_btn, cancel_btn
from subiquitycore.ui.interactive import (PasswordEditor,
RealnameEditor,
StringEditor,
UsernameEditor)
from subiquitycore.ui.interactive import (
PasswordEditor,
RealnameEditor,
UsernameEditor,
)
from subiquitycore.ui.form import (
simple_field,
Form,
StringField,
)
from subiquitycore.ui.container import Columns, ListBox, Pile
from subiquitycore.ui.utils import Padding, Color
from subiquitycore.ui.container import ListBox
from subiquitycore.ui.utils import Padding
from subiquitycore.view import BaseView
@ -101,6 +101,8 @@ class IdentityView(BaseView):
self.items = []
self.form = IdentityForm()
connect_signal(self.form, 'submit', self.done)
connect_signal(self.form, 'cancel', self.cancel)
self.ssh_import_confirmed = True

View File

@ -84,6 +84,7 @@ class BoundFormField(object):
self._caption = None
self.pile = None
self._enabled = True
self.showing_extra = False
self.widget = self._make_widget()
def _make_widget(self):
@ -124,15 +125,17 @@ class BoundFormField(object):
self.form.validated()
def hide_extra(self):
if len(self.pile.contents) > 1:
self.pile.contents = self.pile.contents[:1]
if self.showing_extra:
del self.pile.contents[1]
self.showing_extra = False
def show_extra(self, extra):
t = (extra, self.pile.options('pack'))
if len(self.pile.contents) > 1:
if self.showing_extra:
self.pile.contents[1] = t
else:
self.pile.contents.append(t)
self.pile.contents[1:1] = [t]
self.showing_extra = True
@property
def value(self):
@ -164,7 +167,7 @@ class BoundFormField(object):
def caption(self, val):
self._caption = val
def cols(self):
def _cols(self):
text = Text(self.caption, align="right")
if self._enabled:
input = Color.string_input(_Validator(self, self.widget))
@ -174,7 +177,7 @@ class BoundFormField(object):
("weight", 0.2, text),
("weight", 0.3, input),
]
if self.include_help:
if self.help_style == 'right':
if self.help is not None:
help = self.help
else:
@ -187,11 +190,17 @@ class BoundFormField(object):
else:
return WidgetDisable(Color.info_minor(cols))
def as_row(self, include_help):
def as_row(self):
if self.pile is not None:
raise RuntimeError("do not call as_row more than once!")
self.include_help = include_help
self.pile = Pile([self.cols()])
self.help_style = self.form.opts.get('help_style')
self.pile = Pile([self._cols()])
if self.help_style == 'below' and self.help is not None:
cols = [
("weight", 0.2, Text("")),
("weight", 0.3, Color.info_minor(Text(self.help))),
]
self.pile.contents.append((Columns(cols, dividechars=4), self.pile.options('pack')))
return self.pile
@property
@ -202,7 +211,7 @@ class BoundFormField(object):
def enabled(self, val):
if val != self._enabled:
self._enabled = val
self.pile.contents[0] = (self.cols(), self.pile.contents[0][1])
self.pile.contents[0] = (self._cols(), self.pile.contents[0][1])
def simple_field(widget_maker):
@ -258,14 +267,9 @@ class Form(object, metaclass=MetaForm):
emit_signal(self, 'cancel', self)
def as_rows(self):
has_help = False
for field in self._fields:
if field.help is not None:
has_help = True
break
rows = []
for field in self._fields:
rows.append(field.as_row(has_help))
rows.append(field.as_row())
return Pile(rows)
def validated(self):

View File

@ -39,6 +39,7 @@ ip_families = {
}
class NetworkConfigForm(Form):
opts = {'help_style': 'right'}
def __init__(self, ip_version):
super().__init__()