Commits

Rodrigo Bistolfi committed d2d1b15

urwid: Update progressbar from pipe callback

  • Participants
  • Parent commits fb59566

Comments (0)

Files changed (2)

vinstall/core/render.py

 
         """
         ModelClass = type(model)
-        return get_view(ModelClass)
+        renderer = get_view(ModelClass)
+        renderer.window = self.main_window_instance
+        return renderer
 
     def setup_widgets(self):
         """Initialize the widgets for each model.

vinstall/ui/urwid.py

         self.frame = self.get_frame()
         self.loop = urwid.MainLoop(self.frame,
                 unhandled_input=self.unhandled_input, pop_ups=True)
-        type(self).pipe = self.loop.watch_pipe(lambda x: {'close': False}.get(x, True))
+        #type(self).pipe = self.loop.watch_pipe(lambda f, x: {'close': False}.get(x, True))
 
         self.palettes = cycle([self.default_palette, self.blue_palette])
         self.set_palette()
 
         ce.delegate = self
         self.ce = ce
-        self.finished = False
-        self.running = False
 
         # Widgets
         self.caption = urwid.Text("")
         self.progress_bar = urwid.ProgressBar('pb normal', 'pb complete')
 
+        self.pipe = self.window.loop.watch_pipe(self.notify)
+
     def configure(self):
         """Setup widgets
 
         """
         return None
 
+    def notify(self, msg):
+        "Notify window about changes"
+        pass
+        try:
+            m = float(msg)
+        except ValueError:
+            self.caption.set_text(msg)
+        else:
+            self.progress_bar.set_completion(m)
+            if m == 100.0:
+                return False
+        return True
+
     def on_execution_started(self, queue):
         """Called before starting to process the input queue
 
         """
-        self.running = True
-        self.progress_bar.set_completion(1)
-        os.write(UrwidMainWindow.pipe, "update")
+        os.write(self.pipe, "1")
 
     def on_execution_ended(self, queue):
         """Called when the input queue is done
 
         """
-        self.running = False
-        self.finished = True
-        self.progress_bar.set_completion(100)
-        os.write(UrwidMainWindow.pipe, "update")
-        os.write(UrwidMainWindow.pipe, "close")
+        os.write(self.pipe, "100")
 
     def on_command_start(self, item):
         """Called before processing the item
 
         """
-        self.caption.set_text(item.description)
-        os.write(UrwidMainWindow.pipe, "update")
+        os.write(self.pipe, item.description)
 
     def on_command_end(self, item, total, done):
         """Called after item is complete.
 
         """
-        self.progress_bar.set_completion(done * self.progress_bar.done / total)
-        os.write(UrwidMainWindow.pipe, "update")
+        os.write(self.pipe, done * self.progress_bar.done / total)
 
     def accept(self):
         """Return the top level widget.