]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
tui: Allow user to cancel the installation process
authorMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 May 2021 17:09:37 +0000 (17:09 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sat, 8 May 2021 17:09:37 +0000 (17:09 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/__init__.py
src/python/tui.py

index cfd9df691c2af7af348d3d9e8f31732963834e22..58667bf11e666439cebd64dd6f39733f2b58f712 100644 (file)
@@ -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 = {
index 82407f7529a289a177b7bce7adbd038f6c77b575..b8b659a28fcdba61c2da41c0825344cb3e554214 100644 (file)
@@ -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)