Commits

Rodrigo Bistolfi committed b0c5659

core: handle controller's process_in_background()

If the controller has a process_in_background method, run it immediatly in
another thread. Wait for it until finished without accepting user input.

  • Participants
  • Parent commits 7c0cb28
  • Branches advanced_autopartition

Comments (0)

Files changed (1)

File vinstall/core/wizard.py

         self.current_render = render = self.current_controller.render()
         render.main_window.clear_callbacks()
         render.update_main_window()
-        render.main_window.add_next_callback(self.next)
+        render.main_window.add_next_callback(self.run_controller)
         render.main_window.add_previous_callback(self.previous)
 
-    def run_controller(self):
+    def run_controller(self, *_):
         "Execute tasks specified by the controller"
         args = self.current_render.get_user_input()
         self.handle_process_method(args)
+        self.handle_process_in_background_method(args)
 
     def handle_process_method(self, args):
+        "If there is a process method, call it"
         process_method = getattr(self.current_controller, "process", None)
+        if process_method:
+            self.execute(process_method, args, {})
+
+    def handle_process_in_background_method(self, args):
+        """If there is a process_in_background method, call it in a thread and
+        after finished, call process_command_method and jump to the next state
+        
+        """
+        process_method = getattr(self.current_controller, 
+                "process_in_background", None)
 
         if process_method:
-            #self.current_render.main_window.disable_buttons()
+            self.current_render.main_window.disable_buttons()
 
             def callback(f=None):
                 self.handle_command_method(args)
-                #self.current_render.main_window.enable_buttons()
-                self._next()
+                self.current_render.main_window.enable_buttons()
+                self.next()
 
             future = self.pool.submit(lambda: self.execute(process_method, 
                 args, {}))
             future.add_done_callback(callback)
         else:
             self.handle_command_method(args)
-            self._next()
+            self.next()
 
     def handle_command_method(self, args):
+        "If there is a command method, add it to the queue"
         command_method = getattr(self.current_controller, "command", None)
         if command_method:
             self.commands.append((command_method, args))
 
-    def next(self, *_):
+    def next(self):
         "Jump to the next state of the application"
-        self.run_controller()
-
-    def _next(self):
         next_controller = self.current_controller.next()
         if next_controller:
             instance = self.factory.make_controller_instance(next_controller)