From: Michael Tremer Date: Fri, 14 Mar 2025 18:12:00 +0000 (+0000) Subject: tui: Set maximum value later on progress windows X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e44a8c278402cfccbe995b01a8f38ef30f576b1f;p=people%2Fms%2Fbricklayer.git tui: Set maximum value later on progress windows 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 --- diff --git a/src/python/tui.py b/src/python/tui.py index ab9176a..e0c2b45 100644 --- a/src/python/tui.py +++ b/src/python/tui.py @@ -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()