From: Michael Tremer Date: Sat, 8 May 2021 17:09:37 +0000 (+0000) Subject: tui: Allow user to cancel the installation process X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=c58dff5a93f21060fd3b758598220eae858048bc;p=people%2Fms%2Fbricklayer.git tui: Allow user to cancel the installation process Signed-off-by: Michael Tremer --- diff --git a/src/python/__init__.py b/src/python/__init__.py index cfd9df6..58667bf 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -101,6 +101,14 @@ class Bricklayer(object): except InstallAbortedError: return 1 + # The user requested to cancel the installation process + except UserCanceledError: + if self.tui.confirm( + _("Cancel Installation?"), + _("Are you sure that you want to cancel the installation process?"), + ): + return 0 + # Catch any failed commands except subprocess.CalledProcessError as e: args = { diff --git a/src/python/tui.py b/src/python/tui.py index 82407f7..b8b659a 100644 --- a/src/python/tui.py +++ b/src/python/tui.py @@ -21,6 +21,7 @@ import logging import snack +from .errors import * from .i18n import _ # Setup logging @@ -118,7 +119,7 @@ class Tui(object): self.screen.pushHelpLine(helpline) - def message(self, title, text, buttons=None, help=None, width=40): + def message(self, title, text, buttons=None, height=None, width=40, help=None): """ Shows a message to the user """ @@ -129,7 +130,7 @@ class Tui(object): buttons = (_("OK"), _("Cancel")) window = ButtonsWindow(self, title=title, text=text, - buttons=buttons, width=width, help=help) + buttons=buttons, height=height, width=width, help=help) return window.run() @@ -141,6 +142,18 @@ class Tui(object): return self.message(title, text, buttons=buttons, width=width) + def confirm(self, title, text, height=None, width=40, help=None): + """ + Asks the user a yes/no question + """ + buttons = ( + (_("No"), False), + (_("Yes"), True), + ) + + return self.message(title, text, buttons=buttons, + height=height, width=width, help=help) + def progress(self, title, text, max_value=None, height=None, width=60, help=None): return ProgressWindow(self, title, text, max_value=max_value, height=height, width=width, help=help)