]> git.ipfire.org Git - people/ms/bricklayer.git/commitdiff
tui: Register with the Pakfire progress callback
authorMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Mar 2025 18:02:06 +0000 (18:02 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Fri, 14 Mar 2025 18:02:06 +0000 (18:02 +0000)
That way, Pakfire can inform us about what is happening...

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

index d35ba32025753405bca632928bf335e169bbea84..98b8d2a7644629347d676aefd2a9353117612193 100644 (file)
@@ -341,6 +341,9 @@ class Bricklayer(object):
                # Configure the logger
                ctx.set_logger(logger)
 
+               # Set the progress callback
+               ctx.set_progress_callback(self.tui._progress)
+
                return ctx
 
        def setup_pakfire(self, **kwargs):
index c9c302898afd1b9e25d0d2eb38a0571b2a84b2f7..ab9176ab26647d699944ff8f941a1cbe7cae04a8 100644 (file)
@@ -199,6 +199,19 @@ class Tui(object):
 
                return window.run()
 
+       # Callbacks
+       # These functions will be invoked by Pakfire directly
+
+       def _progress(self, title):
+               """
+                       Called if there is some progress being presented to the user
+               """
+               # snack really needs a title
+               if title is None:
+                       title = _("No Title Given")
+
+               return self.progress(title=title, text="")
+
 
 class Window(object):
        def __init__(self, tui, title, text, height=None, width=None, help=None):
@@ -385,18 +398,43 @@ class ProgressWindow(Window):
                return grid
 
        def __enter__(self):
+               # Show the window
+               self.start()
+
+               # Return the callbacks
+               return ProgressWindowCallbacks(self)
+
+       def __exit__(self, type, value, traceback):
+               # Close the window
+               self.finish()
+
+       def start(self, value=None):
+               """
+                       Starts the progress, i.e. shows the window
+               """
+               if value:
+                       pass # XXX update max value
+
                # Render the window
                window = self._make_window()
                window.draw()
 
                self.tui.refresh()
 
-               # Return the callbacks
-               return ProgressWindowCallbacks(self)
-
-       def __exit__(self, type, value, traceback):
+       def finish(self):
+               """
+                       Called when everything is done, i.e. will close the window
+               """
                self.tui.screen.popWindow()
 
+       def update(self, value):
+               """
+                       Updates the current status
+               """
+               if self.max_value:
+                       self.scale.set(value)
+                       self.tui.refresh()
+
 
 class ProgressWindowCallbacks(object):
        def __init__(self, window):
@@ -406,9 +444,7 @@ class ProgressWindowCallbacks(object):
                """
                        Updates the progressbar value
                """
-               if self.window.max_value:
-                       self.window.scale.set(value)
-                       self.window.tui.refresh()
+               self.window.update(value)
 
        def message(self, text):
                """