]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
tui: Set maximum value later on progress windows
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Mar 2025 18:12:00 +0000 (18:12 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Mar 2025 18:12:00 +0000 (18:12 +0000)
This is required because Pakfire will only tell us what the maximum is
when the progress start function is being called.

Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/python/tui.py

index ab9176ab26647d699944ff8f941a1cbe7cae04a8..e0c2b451fb5e405ecf928eacd29107aa6fcc8165 100644 (file)
@@ -375,15 +375,13 @@ class ProgressWindow(Window):
        """
        def __init__(self, tui, title, text, max_value=0, height=None, width=None, help=None):
                Window.__init__(self, tui, title, text, height=height, width=width, help=help)
+               self.scale = None
 
                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)
-
        def _make_window(self):
                # Create the grid
                grid = snack.GridFormHelp(self.tui.screen, self.title, self.help, 1, 2)
@@ -393,6 +391,10 @@ class ProgressWindow(Window):
 
                # Optionally add the progress bar
                if self.max_value:
+                       # Make progressbar
+                       self.scale = snack.Scale(self.width, self.max_value or 0)
+
+                       # Add it to the grid
                        grid.add(self.scale, 0, 1, padding=(0, 1, 0, 0))
 
                return grid
@@ -408,12 +410,13 @@ class ProgressWindow(Window):
                # Close the window
                self.finish()
 
-       def start(self, value=None):
+       def start(self, max_value=None):
                """
                        Starts the progress, i.e. shows the window
                """
-               if value:
-                       pass # XXX update max value
+               # Update the maximum value
+               if max_value:
+                       self.max_value = max_value
 
                # Render the window
                window = self._make_window()
@@ -431,7 +434,7 @@ class ProgressWindow(Window):
                """
                        Updates the current status
                """
-               if self.max_value:
+               if self.scale:
                        self.scale.set(value)
                        self.tui.refresh()