]> git.ipfire.org Git - pakfire.git/commitdiff
progressbar: Add widget to show any errors
authorMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Dec 2016 20:07:46 +0000 (21:07 +0100)
committerMichael Tremer <michael.tremer@ipfire.org>
Wed, 7 Dec 2016 20:07:46 +0000 (21:07 +0100)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/pakfire/ui/progressbar.py

index 8805ed3629f8eda9367803002044d5ee67b94de2..143434b87a0f7c33715372a5bd8bd53325958791 100644 (file)
@@ -40,6 +40,7 @@ class ProgressBar(object):
 
                self.time_start = None
                self.finished = False
+               self.error = None
 
                # Use the error console as default output.
                self.fd = sys.stderr
@@ -69,12 +70,15 @@ class ProgressBar(object):
 
                return self
 
-       def finish(self):
+       def finish(self, error=None):
                if self.finished:
                        return
 
                self.finished = True
 
+               # Save an exception we could print
+               self.error = error
+
                # Complete the progress bar.
                self.update(self.value_max)
 
@@ -187,7 +191,7 @@ class ProgressBar(object):
                return self
 
        def __exit__(self, type, value, traceback):
-               self.finish()
+               self.finish(error=value)
 
 
 def format_updatable(widget, pbar):
@@ -203,6 +207,15 @@ class Widget(object):
        def update(self, pbar):
                pass
 
+
+class WidgetError(Widget):
+       def update(self, pbar):
+               if pbar.finished and pbar.error:
+                       return _("Error: %s") % pbar.error
+
+               return ""
+
+
 class WidgetFill(Widget):
        expandable = True