move help to an overlay
This commit is contained in:
parent
65f9d1ef62
commit
308a29c75b
|
@ -56,7 +56,7 @@ class AddFormatView(BaseView):
|
|||
|
||||
body = [
|
||||
Padding.line_break(""),
|
||||
self.form.as_rows(),
|
||||
self.form.as_rows(self),
|
||||
Padding.line_break(""),
|
||||
Padding.fixed_10(self.form.buttons)
|
||||
]
|
||||
|
|
|
@ -120,7 +120,7 @@ class AddPartitionView(BaseView):
|
|||
]
|
||||
),
|
||||
Padding.line_break(""),
|
||||
self.form.as_rows(),
|
||||
self.form.as_rows(self),
|
||||
Padding.line_break(""),
|
||||
Padding.fixed_10(self.form.buttons),
|
||||
]
|
||||
|
|
|
@ -108,7 +108,7 @@ class IdentityView(BaseView):
|
|||
self.ssh_import_confirmed = True
|
||||
|
||||
body = [
|
||||
Padding.center_90(self.form.as_rows()),
|
||||
Padding.center_90(self.form.as_rows(self)),
|
||||
Padding.line_break(""),
|
||||
Padding.fixed_10(self.form.buttons),
|
||||
]
|
||||
|
|
|
@ -27,7 +27,7 @@ from urwid import (
|
|||
|
||||
from subiquitycore.ui.buttons import cancel_btn, done_btn
|
||||
from subiquitycore.ui.container import Columns, Pile
|
||||
from subiquitycore.ui.interactive import IntegerEditor, StringEditor
|
||||
from subiquitycore.ui.interactive import Help, IntegerEditor, StringEditor
|
||||
from subiquitycore.ui.utils import Color
|
||||
|
||||
class Toggleable(delegate_to_widget_mixin('_original_widget'), WidgetDecoration):
|
||||
|
@ -174,34 +174,27 @@ class BoundFormField(object):
|
|||
input = Color.string_input(_Validator(self, self.widget))
|
||||
else:
|
||||
input = self.widget
|
||||
if self.help is not None:
|
||||
help = Help(self.parent_view, self.help)
|
||||
else:
|
||||
help = Text("")
|
||||
cols = [
|
||||
("weight", 0.2, text),
|
||||
("weight", 0.3, input),
|
||||
(3, help),
|
||||
]
|
||||
if self.help_style == 'right':
|
||||
if self.help is not None:
|
||||
help = self.help
|
||||
else:
|
||||
help = ""
|
||||
cols.append(
|
||||
("weight", 0.5, Text(help)))
|
||||
cols = Columns(cols, dividechars=4)
|
||||
if self._enabled:
|
||||
return cols
|
||||
else:
|
||||
return WidgetDisable(Color.info_minor(cols))
|
||||
|
||||
def as_row(self):
|
||||
def as_row(self, view):
|
||||
if self.pile is not None:
|
||||
raise RuntimeError("do not call as_row more than once!")
|
||||
self.parent_view = view
|
||||
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
|
||||
|
@ -264,10 +257,10 @@ class Form(object, metaclass=MetaForm):
|
|||
def _click_cancel(self, sender):
|
||||
emit_signal(self, 'cancel', self)
|
||||
|
||||
def as_rows(self):
|
||||
def as_rows(self, view):
|
||||
rows = []
|
||||
for field in self._fields:
|
||||
rows.append(field.as_row())
|
||||
rows.append(field.as_row(view))
|
||||
return Pile(rows)
|
||||
|
||||
def validated(self):
|
||||
|
|
|
@ -35,7 +35,9 @@ from urwid import (
|
|||
WidgetWrap,
|
||||
)
|
||||
|
||||
from subiquitycore.ui.buttons import PlainButton
|
||||
from subiquitycore.ui.container import Pile
|
||||
from subiquitycore.ui.utils import Color, Padding
|
||||
|
||||
log = logging.getLogger("subiquitycore.ui.input")
|
||||
|
||||
|
@ -226,3 +228,29 @@ class YesNo(Selector):
|
|||
def __init__(self):
|
||||
opts = ['Yes', 'No']
|
||||
super().__init__(opts)
|
||||
|
||||
|
||||
class _HelpDisplay(WidgetWrap):
|
||||
def __init__(self, closer, help_text):
|
||||
self._closer = closer
|
||||
button = Color.button(PlainButton(label="Close", on_press=lambda btn:self._closer()))
|
||||
super().__init__(LineBox(Pile([Text(help_text), Padding.fixed_10(button)]), title="Help"))
|
||||
def keypress(self, size, key):
|
||||
if key == 'esc':
|
||||
self._closer()
|
||||
else:
|
||||
return super().keypress(size, key)
|
||||
|
||||
|
||||
class Help(WidgetWrap):
|
||||
|
||||
def __init__(self, view, help_text):
|
||||
self._view = view
|
||||
self._help_text = help_text
|
||||
self._button = Padding.fixed_3(Color.button(SelectableIcon("[?]", 1)))
|
||||
super().__init__(self._button)
|
||||
|
||||
def keypress(self, size, key):
|
||||
if self._command_map[key] != ACTIVATE:
|
||||
return key
|
||||
self._view.show_overlay(_HelpDisplay(self._view.remove_overlay, self._help_text))
|
||||
|
|
|
@ -132,7 +132,7 @@ class BaseNetworkConfigureManualView(BaseView):
|
|||
self.error = Text("", align='center')
|
||||
#self.set_as_default_gw_button = Pile(self._build_set_as_default_gw_button())
|
||||
body = [
|
||||
Padding.center_79(self.form.as_rows()),
|
||||
Padding.center_79(self.form.as_rows(self)),
|
||||
#Padding.line_break(""),
|
||||
#Padding.center_79(self.set_as_default_gw_button),
|
||||
Padding.line_break(""),
|
||||
|
|
|
@ -39,10 +39,11 @@ class BaseView(WidgetWrap):
|
|||
self.orig_w = None
|
||||
|
||||
def keypress(self, size, key):
|
||||
if key in ['ctrl x']:
|
||||
self.controller.signal.emit_signal('control-x-quit')
|
||||
return None
|
||||
key = super().keypress(size, key)
|
||||
if key == 'esc':
|
||||
self.controller.cancel()
|
||||
return None
|
||||
if key in ['ctrl x']:
|
||||
self.controller.signal.emit_signal('control-x-quit')
|
||||
|
||||
return super().keypress(size, key)
|
||||
return key
|
||||
|
|
Loading…
Reference in New Issue