]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
tui: Export some callbacks for the progress window
authorMichael Tremer <michael.tremer@ipfire.org>
Thu, 9 Dec 2021 10:50:09 +0000 (10:50 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Thu, 9 Dec 2021 10:50:09 +0000 (10:50 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/step.py
src/python/tui.py

index d4d08a59a5468eea4b1b00940add037a68aa47cc..ed0ecc498d55a5044fac920113b4801fb4685564 100644 (file)
@@ -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):
index 8a088ebc6a4cb9c6316362ddebe69dd5a27a5d26..c37e73c527fea29715492eb0b43845dad66e108d 100644 (file)
@@ -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):