def reset(self):
        """Request that host re-discovers plug-ins and re-processes selectors

        A reset completely flushes the state of the GUI and reverts
        back to how it was when it first got launched.

        Pipeline:
              ______________     ____________     ______________
             |              |   |            |   |              |
             | host.reset() |-->| on_reset() |-->| on_context() |--
             |______________|   |____________|   |______________| |
             _______________     __________     _______________   |
            |               |   |          |   |               |  |
            | on_finished() |<--| on_run() |<--| on_discover() |<--
            |_______________|   |__________|   |_______________|

        """

        if not any(state in self.states for state in ("ready", "finished")):
            return self.error.emit("Not ready")

        self.initialising.emit()

        util.timer("resetting..")
        stats = {"requestCount": self.host.stats()["totalRequestCount"]}

        # Clear models
        self.data["models"]["item"].reset()
        self.data["models"]["result"].reset()

        def on_finished(plugins, context):
            # Compute compatibility
            for plugin in self.data["models"]["item"].plugins:
                if plugin.instanceEnabled:
                    instances = pyblish.logic.instances_by_plugin(context,
                                                                  plugin)
                    plugin.compatibleInstances = list(i.id for i in instances)
                else:
                    plugin.compatibleInstances = [context.id]

            self.data["models"]["item"].reorder(context)

            # Report statistics
            stats["requestCount"] -= self.host.stats()["totalRequestCount"]
            util.timer_end("resetting..", "Spent %.2f ms resetting")
            util.echo("Made %i requests during reset."
                      % abs(stats["requestCount"]))

            # Reset Context
            context_item = self.data["models"]["item"].instances[0]
            context_item.hasError = False
            context_item.succeeded = False
            context_item.processed = False
            context_item.isProcessing = False
            context_item.currentProgress = 0
            context_item.label = context.data.get("label")

            self.initialised.emit()

            self.data["models"]["item"].update_compatibility()

            # Remember comment across resets
            comment = self.data["comment"]
            if comment:
                print("Installing local comment..")
                self.host.cached_context.data["comment"] = comment
            else:
                print("No local comment, reading from context..")
                comment = self.host.cached_context.data.get("comment", "")
                self.data["comment"] = comment

            # Notify subscribers of the comment
            self.comment_sync(comment)

            first_run = self.data["firstRun"]
            if first_run:
                self.firstRun.emit()
                self.data["firstRun"] = False

            self.host.emit("reset", context=None)

            # Hidden sections
            for section in self.data["models"]["item"].sections:
                if section.name in settings.HiddenSections:
                    self.hideSection(True, section.name)

            # Run selected procedure on first run
            if first_run:
                if self.data.get('autoPublish'):
                    print("Starting auto-publish at first run..")
                    util.schedule(self.publish, 1)
                elif self.data.get('autoValidate'):
                    print("Starting auto-validate at first run..")
                    util.schedule(self.validate, 1)

        def on_run(plugins):
            """Fetch instances in their current state, right after reset"""

            util.defer(self.host.context,
                       callback=lambda context: on_finished(plugins, context))

        def on_discover(plugins, context):
            collectors = list()

            # For backwards compatibility check for existance of
            # "plugins_by_targets" method.
            if hasattr(pyblish.api, "plugins_by_targets"):
                plugins = pyblish.api.plugins_by_targets(plugins, self.targets)

            for plugin in plugins:
                self.data["models"]["item"].add_plugin(plugin.to_json())

                # Sort out which of these are Collectors
                if not pyblish.lib.inrange(
                        number=plugin.order,
                        base=pyblish.api.Collector.order):
                    continue

                if not plugin.active:
                    continue

                collectors.append(plugin)

            self.collecting.emit()

            self.run(collectors, context,
                     callback=on_run,
                     callback_args=[plugins])

        def on_context(context):
            context.data["pyblishQmlVersion"] = version
            context.data["targets"] = ", ".join(self.targets)

            self.data["models"]["item"].add_context(context.to_json())
            self.data["models"]["result"].add_context(context.to_json())

            util.defer(
                self.host.discover,
                callback=lambda plugins: on_discover(plugins, context)
            )

        def on_reset():
            util.defer(self.host.context, callback=on_context)

        util.defer(self.host.reset, callback=on_reset)
def reset ( self ) : if not any ( state in self . states for state in ( "ready" , "finished" ) ) : return self . error . emit ( "Not ready" ) self . initialising . emit ( ) util . timer ( "resetting.." ) stats = { "requestCount" : self . host . stats ( ) [ "totalRequestCount" ] } self . data [ "models" ] [ "item" ] . reset ( ) self . data [ "models" ] [ "result" ] . reset ( ) def on_finished ( plugins , context ) : for plugin in self . data [ "models" ] [ "item" ] . plugins : if plugin . instanceEnabled : instances = pyblish . logic . instances_by_plugin ( context , plugin ) plugin . compatibleInstances = list ( i . id for i in instances ) else : plugin . compatibleInstances = [ context . id ] self . data [ "models" ] [ "item" ] . reorder ( context ) stats [ "requestCount" ] -= self . host . stats ( ) [ "totalRequestCount" ] util . timer_end ( "resetting.." , "Spent %.2f ms resetting" ) util . echo ( "Made %i requests during reset." % abs ( stats [ "requestCount" ] ) ) context_item = self . data [ "models" ] [ "item" ] . instances [ 0 ] context_item . hasError = False context_item . succeeded = False context_item . processed = False context_item . isProcessing = False context_item . currentProgress = 0 context_item . label = context . data . get ( "label" ) self . initialised . emit ( ) self . data [ "models" ] [ "item" ] . update_compatibility ( ) comment = self . data [ "comment" ] if comment : print ( "Installing local comment.." ) self . host . cached_context . data [ "comment" ] = comment else : print ( "No local comment, reading from context.." ) comment = self . host . cached_context . data . get ( "comment" , "" ) self . data [ "comment" ] = comment self . comment_sync ( comment ) first_run = self . data [ "firstRun" ] if first_run : self . firstRun . emit ( ) self . data [ "firstRun" ] = False self . host . emit ( "reset" , context = None ) for section in self . data [ "models" ] [ "item" ] . sections : if section . name in settings . HiddenSections : self . hideSection ( True , section . name ) if first_run : if self . data . get ( 'autoPublish' ) : print ( "Starting auto-publish at first run.." ) util . schedule ( self . publish , 1 ) elif self . data . get ( 'autoValidate' ) : print ( "Starting auto-validate at first run.." ) util . schedule ( self . validate , 1 ) def on_run ( plugins ) : util . defer ( self . host . context , callback = lambda context : on_finished ( plugins , context ) ) def on_discover ( plugins , context ) : collectors = list ( ) if hasattr ( pyblish . api , "plugins_by_targets" ) : plugins = pyblish . api . plugins_by_targets ( plugins , self . targets ) for plugin in plugins : self . data [ "models" ] [ "item" ] . add_plugin ( plugin . to_json ( ) ) if not pyblish . lib . inrange ( number = plugin . order , base = pyblish . api . Collector . order ) : continue if not plugin . active : continue collectors . append ( plugin ) self . collecting . emit ( ) self . run ( collectors , context , callback = on_run , callback_args = [ plugins ] ) def on_context ( context ) : context . data [ "pyblishQmlVersion" ] = version context . data [ "targets" ] = ", " . join ( self . targets ) self . data [ "models" ] [ "item" ] . add_context ( context . to_json ( ) ) self . data [ "models" ] [ "result" ] . add_context ( context . to_json ( ) ) util . defer ( self . host . discover , callback = lambda plugins : on_discover ( plugins , context ) ) def on_reset ( ) : util . defer ( self . host . context , callback = on_context ) util . defer ( self . host . reset , callback = on_reset )
Request that host re-discovers plug-ins and re-processes selectors

        A reset completely flushes the state of the GUI and reverts
        back to how it was when it first got launched.

        Pipeline:
              ______________     ____________     ______________
             |              |   |            |   |              |
             | host.reset() |-->| on_reset() |-->| on_context() |--
             |______________|   |____________|   |______________| |
             _______________     __________     _______________   |
            |               |   |          |   |               |  |
            | on_finished() |<--| on_run() |<--| on_discover() |<--
            |_______________|   |__________|   |_______________|