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):
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):
"""
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):
"""