Exemplo n.º 1
0
    def __init__(self):
        """Dedicated to the attributes initialisation/instanciation.

        The input and output plugs are defined here. The special
        'self.requirement' attribute (optional) is used to define the
        third-party products necessary for the running of the brick.
        """
        # initialisation of the objects needed for the launch of the brick
        super(Input_Filter, self).__init__()

        # Third party softwares required for the execution of the brick
        self.requirement = []  # no need of third party software!

        # Inputs description
        input_desc = ('A list corresponding to the data from the Data Browser '
                      'or the output data from another brick.')

        # Outputs description
        output_desc = 'A list with the result of the filter applied.'

        # Inputs traits
        self.add_trait("input",
                       traits.List(traits.File, output=False, desc=input_desc))

        # Outputs traits
        self.add_trait("output",
                       traits.List(traits.File, output=True, desc=output_desc))

        # Instantiation of the filter object
        self.filter = Filter(None, [''], [''], [['FileName']], [],
                             ['CONTAINS'], "")
Exemplo n.º 2
0
    def save_current_filter(self, custom_filters):
        """Save the current filter.

        :param custom_filters: The customized filter
        """

        (fields, conditions, values, links, nots) = custom_filters
        self.currentFilter.fields = fields
        self.currentFilter.conditions = conditions
        self.currentFilter.values = values
        self.currentFilter.links = links
        self.currentFilter.nots = nots

        # Getting the path
        filters_path = os.path.join(self.folder, "filters")

        # Filters folder created if it does not already exists
        if not os.path.exists(filters_path):
            os.mkdir(filters_path)

        filter_name = self.getFilterName()

        # We save the filter only if we have a filter name from
        # populse_mia.e popup
        if filter_name != None:
            file_path = os.path.join(filters_path, filter_name + ".json")

            if os.path.exists(file_path):
                # Filter already exists
                msg = QMessageBox()
                msg.setIcon(QMessageBox.Warning)
                msg.setText("The filter already exists in the project")
                msg.setInformativeText(
                    "The project already has a filter named " + filter_name)
                msg.setWindowTitle("Warning")
                msg.setStandardButtons(QMessageBox.Ok)
                msg.buttonClicked.connect(msg.close)
                msg.exec()

            else:
                # Json filter file written
                with open(file_path, 'w') as outfile:

                    new_filter = Filter(
                        filter_name,
                        self.currentFilter.nots,
                        self.currentFilter.values,
                        self.currentFilter.fields,
                        self.currentFilter.links,
                        self.currentFilter.conditions,
                        self.currentFilter.search_bar)

                    json.dump(new_filter.json_format(), outfile)
                    self.filters.append(new_filter)
Exemplo n.º 3
0
    def __init__(self):
        super(Input_Filter, self).__init__()

        self.filter = Filter(None, [''], [''], [['FileName']], [],
                             ['CONTAINS'], "")
        self.add_trait("input", traits.List(traits.File, output=False))
        self.add_trait("output", traits.List(traits.File, output=True))
Exemplo n.º 4
0
    def init_filters(self):
        """Initialize the filters at project opening."""

        self.currentFilter = Filter(None, [], [], [], [], [], "")
        self.filters = []

        filters_folder = os.path.join(self.folder, "filters")

        for filename in glob.glob(os.path.join(filters_folder, '*')):
            filter, extension = os.path.splitext(os.path.basename(filename))
            # make sure this gets closed automatically
            # as soon as we are done reading
            with open(filename, 'r') as f:
                data = json.load(f)
            filter_object = Filter(filter, data["nots"], data["values"],
                                   data["fields"], data["links"],
                                   data["conditions"], data["search_bar_text"])
            self.filters.append(filter_object)
Exemplo n.º 5
0
    def ok_clicked(self):
        """Set the filter to the process and closes the widget."""
        if isinstance(self.process, ProcessMIA):
            (fields, conditions, values, links,
             nots) = self.advanced_search.get_filters(False)
            filt = Filter(None, nots, values, fields, links, conditions,
                          self.rapid_search.text())
            self.process.filter = filt

        self.set_output_value()
        self.close()
Exemplo n.º 6
0
class Input_Filter(ProcessMIA):
    """
    *To filter the content of the Data Browser tab or the output data of another brick*

    Please, see the complete documention for the `Input_Filter in the populse.mia_processes web site
    <https://populse.github.io/mia_processes/documentation/bricks/tools/Input_Filter.html>`_

    """
    def __init__(self):
        """Dedicated to the attributes initialisation/instanciation.

        The input and output plugs are defined here. The special
        'self.requirement' attribute (optional) is used to define the
        third-party products necessary for the running of the brick.
        """
        # initialisation of the objects needed for the launch of the brick
        super(Input_Filter, self).__init__()

        # Third party softwares required for the execution of the brick
        self.requirement = []  # no need of third party software!

        # Inputs description
        input_desc = ('A list corresponding to the data from the Data Browser '
                      'or the output data from another brick.')

        # Outputs description
        output_desc = 'A list with the result of the filter applied.'

        # Inputs traits
        self.add_trait("input",
                       traits.List(traits.File, output=False, desc=input_desc))

        # Outputs traits
        self.add_trait("output",
                       traits.List(traits.File, output=True, desc=output_desc))

        # Instantiation of the filter object
        self.filter = Filter(None, [''], [''], [['FileName']], [],
                             ['CONTAINS'], "")

    def list_outputs(self, is_plugged=None):
        """Dedicated to the initialisation step of the brick.

        The main objective of this method is to produce the outputs of the
        bricks (self.outputs) and the associated tags (self.inheritance_dic),
        if defined here. In order not to include an output in the database,
        this output must be a value of the optional key 'notInDb' of the
        self.outputs dictionary. To work properly this method must return 
        self.make_initResult() object.

        :param is_plugged: the state, linked or not, of the plugs.
        :returns: a dictionary with requirement, outputs and inheritance_dict.
        """
        # Using the inheritance to ProcessMIA class, list_outputs method
        super(Input_Filter, self).list_outputs()

        # TODO: MAYBE WE DON'T NEED THAT, IT SHOULD BE DONE IN
        # open_filter OF PipelineEditor?

        # Outputs definition and tags inheritance (optional)

        # Getting the input:
        # The current way for obtaining input data and filtering them is very
        # permissive. Indeed, it is possible to obtain the data from the output
        # of a previous brick or from the database (using Export to
        # database_scans, or not) and of course to perform a filtering from it.
        # But also, if no data is sent in, we get all the data from the database
        # (self.project.session.get_documents_names(COLLECTION_CURRENT), below).
        # It can maybe lead to side effects (however it also allows for example
        # not to connect the input to something and to have the whole database
        # by default... Is it really desirable????
        if self.input:
            self.scans_list = self.input

        else:
            self.scans_list = self.project.session.get_documents_names(
                COLLECTION_CURRENT)

        # The data to filter are always a relative path
        if (self.scans_list) and (os.path.isabs(self.scans_list[0])):
            self.scans_list = [
                os.path.relpath(i, self.project.folder)
                for i in self.scans_list
            ]

        # Apply the filter to the input
        self.outputs['output'] = self.filter.generate_filter(
            self.project, self.scans_list,
            self.project.session.get_shown_tags())
        self.outputs["notInDb"] = ["output"]

        # The output data are always an absolute path
        for idx, element in enumerate(self.outputs['output']):
            full_path = os.path.abspath(
                os.path.join(self.project.folder, element))
            self.outputs['output'][idx] = full_path

        # Return the requirement, outputs and inheritance_dict
        return self.make_initResult()

    def run_process_mia(self):
        """Dedicated to the process launch step of the brick."""
        return