def set_value(self, row, column, value):
        """ Return the Python value for the row and column.

        Parameters
        ----------
        row : sequence of int
            The indices of the row as a sequence from root to leaf.
        column : sequence of int
            The indices of the column as a sequence of length 1.

        Returns
        -------
        value : any
            The value represented by the given row and column.
        """
        if self.can_set_value(row, column):
            index = tuple(row + column)
            self.data[index] = value
            self.values_changed = (row, column, row, column)
        else:
            raise DataViewSetError()
Example #2
0
    def set_editor_value(self, model, row, column, value):
        """ Set the edited value.

        Parameters
        ----------
        model : AbstractDataModel
            The data model holding the data.
        row : sequence of int
            The row in the data model being set.
        column : sequence of int
            The column in the data model being set.
        value : any
            The value being set.

        Raises
        -------
        DataViewSetError
            If the value cannot be set.
        """
        if self.is_valid(model, row, column, value):
            model.set_value(row, column, value)
        else:
            raise DataViewSetError("Invalid value set: {!r}".format(value))
Example #3
0
    def set_text(self, model, row, column, text):
        """ Set the text of the underlying value.

        Parameters
        ----------
        model : AbstractDataModel
            The data model holding the data.
        row : sequence of int
            The row in the data model being queried.
        column : sequence of int
            The column in the data model being queried.
        text : str
            The text to set.

        Raises
        -------
        DataViewSetError
            If the value cannot be set.
        """
        try:
            value = self.evaluate(self.unformat(text))
        except ValueError:
            raise DataViewSetError("Can't evaluate value: {!r}".format(text))
        self.set_editor_value(model, row, column, value)