From 308a29c75b1bbc9b8446f1c0efcbd24e22093d3e Mon Sep 17 00:00:00 2001 From: Michael Hudson-Doyle Date: Mon, 13 Feb 2017 12:18:48 +1300 Subject: [PATCH] move help to an overlay --- subiquity/ui/views/filesystem/add_format.py | 2 +- .../ui/views/filesystem/add_partition.py | 2 +- subiquity/ui/views/identity.py | 2 +- subiquitycore/ui/form.py | 27 +++++++----------- subiquitycore/ui/interactive.py | 28 +++++++++++++++++++ .../network_configure_manual_interface.py | 2 +- subiquitycore/view.py | 9 +++--- 7 files changed, 47 insertions(+), 25 deletions(-) diff --git a/subiquity/ui/views/filesystem/add_format.py b/subiquity/ui/views/filesystem/add_format.py index 4305af1f..da53ba6a 100644 --- a/subiquity/ui/views/filesystem/add_format.py +++ b/subiquity/ui/views/filesystem/add_format.py @@ -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) ] diff --git a/subiquity/ui/views/filesystem/add_partition.py b/subiquity/ui/views/filesystem/add_partition.py index 8f23c182..71005c54 100644 --- a/subiquity/ui/views/filesystem/add_partition.py +++ b/subiquity/ui/views/filesystem/add_partition.py @@ -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), ] diff --git a/subiquity/ui/views/identity.py b/subiquity/ui/views/identity.py index 7a65b0b7..66aed7b8 100644 --- a/subiquity/ui/views/identity.py +++ b/subiquity/ui/views/identity.py @@ -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), ] diff --git a/subiquitycore/ui/form.py b/subiquitycore/ui/form.py index 3b130705..9293c349 100644 --- a/subiquitycore/ui/form.py +++ b/subiquitycore/ui/form.py @@ -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): diff --git a/subiquitycore/ui/interactive.py b/subiquitycore/ui/interactive.py index 289c2639..bafedf76 100644 --- a/subiquitycore/ui/interactive.py +++ b/subiquitycore/ui/interactive.py @@ -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)) diff --git a/subiquitycore/ui/views/network_configure_manual_interface.py b/subiquitycore/ui/views/network_configure_manual_interface.py index 21d89286..1033c230 100644 --- a/subiquitycore/ui/views/network_configure_manual_interface.py +++ b/subiquitycore/ui/views/network_configure_manual_interface.py @@ -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(""), diff --git a/subiquitycore/view.py b/subiquitycore/view.py index 98fbb2de..cfe4e646 100644 --- a/subiquitycore/view.py +++ b/subiquitycore/view.py @@ -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