From: Michael Tremer Date: Fri, 14 Mar 2025 18:02:06 +0000 (+0000) Subject: tui: Register with the Pakfire progress callback X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8501a60bfe57f070338a78a63bf27c7f2b9a730d;p=people%2Fms%2Fbricklayer.git tui: Register with the Pakfire progress callback That way, Pakfire can inform us about what is happening... Signed-off-by: Michael Tremer --- diff --git a/src/python/__init__.py b/src/python/__init__.py index d35ba32..98b8d2a 100644 --- a/src/python/__init__.py +++ b/src/python/__init__.py @@ -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): diff --git a/src/python/tui.py b/src/python/tui.py index c9c3028..ab9176a 100644 --- a/src/python/tui.py +++ b/src/python/tui.py @@ -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): """