Example #1
0
 def find_input_workspace_property(self, algorithm):
     algm_manager = AlgorithmManager.Instance()
     alg_instance = algm_manager.createUnmanaged(algorithm[0], algorithm[1])
     alg_instance.initialize()
     for prop in alg_instance.getProperties():
         if isinstance(prop, IWorkspaceProperty) and prop.direction in [Direction.Input, Direction.InOut]:
             return prop.name
     return None
Example #2
0
    def create_mantid_algorithm(self, algorithm_name, version=-1):
        """
        Create and initializes a Mantid algorithm.

        Args:
          algorithm_name (str): The name of the algorithm to use for the title.
          version (int): Version of the algorithm to create

        Returns:
          algorithm: An instance of a Mantid algorithm.
        """
        if version == -1:
            version = AlgorithmFactory.Instance().highestVersion(
                algorithm_name)
        alg = AlgorithmManager.Instance().createUnmanaged(
            algorithm_name, version)
        alg.initialize()
        return alg
Example #3
0
 def _create_parameters(self, alg_name):
     from mantid.api import AlgorithmManager
     alg_object = AlgorithmManager.Instance().createUnmanaged(alg_name)
     alg_object.initialize()
     from inspect import Parameter
     pos_or_keyword = Parameter.POSITIONAL_OR_KEYWORD
     parameters = []
     for name in alg_object.mandatoryProperties():
         prop = alg_object.getProperty(name)
         # Mandatory parameters are those for which the default value is not valid
         if isinstance(prop.isValid, str):
             valid_str = prop.isValid
         else:
             valid_str = prop.isValid()
         if len(valid_str) > 0:
             parameters.append(Parameter(name, pos_or_keyword))
         else:
             # None is not quite accurate here, but we are reproducing the
             # behavior found in the C++ code for SimpleAPI.
             parameters.append(Parameter(name, pos_or_keyword,
                                         default=None))
     # Add a self parameter since these are called from a class.
     parameters.insert(0, Parameter("self", Parameter.POSITIONAL_ONLY))
     return parameters
Example #4
0
    def closeEvent(self, event):
        if self.project is not None:
            if self.project.is_saving or self.project.is_loading:
                event.ignore()
                self.project.inform_user_not_possible()
                return

            # Check whether or not to save project
            if not self.project.saved:
                # Offer save
                if self.project.offer_save(self):
                    # Cancel has been clicked
                    event.ignore()
                    return

        # Close editors
        if self.editor is None or self.editor.app_closing():
            # write out any changes to the mantid config file
            ConfigService.saveConfig(ConfigService.getUserFilename())
            # write current window information to global settings object
            self.writeSettings(CONF)
            # Close all open plots
            # We don't want this at module scope here
            import matplotlib.pyplot as plt  # noqa
            plt.close('all')

            # Cancel all running (managed) algorithms
            AlgorithmManager.Instance().cancelAll()

            app = QApplication.instance()
            if app is not None:
                app.closeAllWindows()

            # Kill the project recovery thread and don't restart should a save be in progress and clear out current
            # recovery checkpoint as it is closing properly
            if self.project_recovery is not None:
                self.project_recovery.stop_recovery_thread()
                self.project_recovery.closing_workbench = True

            # Cancel memory widget thread
            if self.memorywidget is not None:
                self.memorywidget.presenter.cancel_memory_update()

            if self.interface_manager is not None:
                self.interface_manager.closeHelpWindow()

            if self.workspacecalculator is not None:
                self.workspacecalculator.view.closeEvent(event)

            if self.project_recovery is not None:
                # Do not merge this block with the above block that
                # starts with the same check.
                # We deliberately split the call to stop the recovery
                # thread and removal of the checkpoints folder to
                # allow for the maximum amount of time for the recovery
                # thread to finish. Any errors here are ignored as exceptions
                # on shutdown cannot be handled in a meaningful way.
                # Future runs of project recovery will clean any stale points
                # after a month
                self.project_recovery.remove_current_pid_folder(
                    ignore_errors=True)

            event.accept()
        else:
            # Cancel was pressed when closing an editor
            event.ignore()