]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
unattended: Show warning before starting installation
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 May 2021 18:13:43 +0000 (18:13 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 5 May 2021 18:13:43 +0000 (18:13 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/__init__.py
src/python/step.py
src/python/tui/__init__.py

index 80e02182dc0af68ed9438e824bb60b135d996657..f613a3fd4a708b3ca0549e5fe4dbac0c17d6b210 100644 (file)
@@ -50,6 +50,7 @@ class Bricklayer(object):
 
        # An ordered list of all available steps
        steps = (
+               step.UnattendedWarning,
                step.Welcome,
        )
 
index 49aefc6236787e2c08133dafa8a22315b6f03558..e3a3a275573035050907e7a4f02da0bcb0bfe533 100644 (file)
@@ -19,6 +19,7 @@
 ###############################################################################
 
 import logging
+import time
 
 import snack
 
@@ -72,3 +73,25 @@ class Welcome(Step):
                                "Selecting Cancel on any of the following screens will reboot the computer."),
                        buttons=(_("Start Installation"), _("Cancel"))
                )
+
+
+class UnattendedWarning(Step):
+       @property
+       def enabled(self):
+               # Only enabled in unattended mode
+               return self.bricklayer.unattended
+
+       def run(self, tui):
+               seconds = 10
+
+               p = tui.progress(
+                       _("Unattended Installation"),
+                       _("Unattended installation is starting in %s seconds") % seconds,
+                       max_value=seconds * 10,
+               )
+
+               with p:
+                       for i in range(seconds * 10):
+                               time.sleep(0.1)
+
+                               p.update(i + 1)
index 4d80373e89f90bc36112601d40c17ebfeb65bbc2..afeb8b4c753367c5c0954cc48ba0e82c8ae3e1a1 100644 (file)
@@ -103,3 +103,38 @@ class Tui(object):
 
                return snack.ButtonChoiceWindow(self.screen, title=title, text=text,
                        buttons=buttons, help=help)
+
+       def progress(self, *args, **kwargs):
+               return ProgressWindow(self, *args, **kwargs)
+
+
+class ProgressWindow(object):
+       def __init__(self, tui, title, text, max_value=1, width=60, help=None):
+               self.tui = tui
+
+               # Compose the window
+               textbox = snack.TextboxReflowed(width, text)
+
+               # Add the progressbar
+               scale = snack.Scale(width, total=max_value)
+               self.update_callback = scale.set
+
+               # Create the grid
+               self.grid = snack.GridFormHelp(tui.screen, title, help, 1, 3)
+               self.grid.add(textbox, 0, 0, padding=(0, 0, 0, 1))
+               self.grid.add(scale, 0, 1, growx=1)
+
+       def __enter__(self):
+               # Render the window
+               self.grid.draw()
+               self.tui.refresh()
+
+       def __exit__(self, type, value, traceback):
+               pass
+
+       def update(self, value):
+               """
+                       Updates the progressbar value
+               """
+               self.update_callback(value)
+               self.tui.refresh()