From: Michael Tremer Date: Thu, 9 Dec 2021 10:50:09 +0000 (+0000) Subject: tui: Export some callbacks for the progress window X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fc385a8902d5231bc3f0e23f3882b4c98e5602bf;p=people%2Fms%2Fbricklayer.git tui: Export some callbacks for the progress window Signed-off-by: Michael Tremer --- diff --git a/src/python/step.py b/src/python/step.py index d4d08a5..ed0ecc4 100644 --- a/src/python/step.py +++ b/src/python/step.py @@ -193,11 +193,11 @@ class UnattendedWarning(Step): max_value=seconds * 10, ) - with p: + with p as w: for i in range(seconds * 10): time.sleep(0.1) - p.update(i + 1) + w.progress(i + 1) class RootPassword(InteractiveStep): diff --git a/src/python/tui.py b/src/python/tui.py index 8a088eb..c37e73c 100644 --- a/src/python/tui.py +++ b/src/python/tui.py @@ -357,6 +357,9 @@ class ProgressWindow(Window): self.max_value = max_value + # Make textbox + self.textbox = snack.TextboxReflowed(self.width, self.text) + # Make progressbar self.scale = snack.Scale(self.width, self.max_value or 0) @@ -365,8 +368,7 @@ class ProgressWindow(Window): grid = snack.GridFormHelp(self.tui.screen, self.title, self.help, 1, 2) # Add the textbox - textbox = snack.TextboxReflowed(self.width, self.text) - grid.add(textbox, 0, 0) + grid.add(self.textbox, 0, 0) # Optionally add the progress bar if self.max_value: @@ -381,16 +383,41 @@ class ProgressWindow(Window): self.tui.refresh() + # Return the callbacks + return ProgressWindowCallbacks(self) + def __exit__(self, type, value, traceback): self.tui.screen.popWindow() - def update(self, value): + +class ProgressWindowCallbacks(object): + def __init__(self, window): + self.window = window + + def progress(self, value): """ Updates the progressbar value """ - if self.max_value: - self.scale.set(value) - self.tui.refresh() + if self.window.max_value: + self.window.scale.set(value) + self.window.tui.refresh() + + def status(self, text): + """ + Updates the text in the textbox + """ + self.window.textbox.setText(text) + self.window.tui.refresh() + + @property + def callbacks(self): + """ + Returns callbacks that can be passed to Pakfire + """ + return { + "status_callback" : self.status, + "progress_callback" : self.progress, + } class PasswordWindow(ButtonsWindow):