From: Michael Tremer Date: Wed, 5 May 2021 18:13:43 +0000 (+0000) Subject: unattended: Show warning before starting installation X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=de130d0047b6adced3dacbaca9b0ad3de4b42787;p=people%2Fms%2Fbricklayer.git unattended: Show warning before starting installation Signed-off-by: Michael Tremer --- diff --git a/src/python/__init__.py b/src/python/__init__.py index 80e0218..f613a3f 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -50,6 +50,7 @@ class Bricklayer(object): # An ordered list of all available steps steps = ( + step.UnattendedWarning, step.Welcome, ) diff --git a/src/python/step.py b/src/python/step.py index 49aefc6..e3a3a27 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -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) diff --git a/src/python/tui/__init__.py b/src/python/tui/__init__.py index 4d80373..afeb8b4 100644 --- a/src/python/tui/__init__.py +++ b/src/python/tui/__init__.py @@ -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()