Esempio n. 1
0
 def set_value(self, row, column, value):
     if self.can_set_value(row, column):
         row_index = row[0]
         key = list(self.data)[row_index]
         self.data[key] = value
     else:
         raise DataViewSetError()
    def set_value(self, row, column, value):
        """ Set the Python value for the row and column.

        This uses the row_header_data and column_data accessors to set
        the value.

        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 0 or 1.
        value : any
            The new value for the given row and column.

        Raises
        -------
        DataViewSetError
            If the value cannot be set.
        """
        if len(row) == 0:
            raise DataViewSetError("Can't set column titles.")
        if len(column) == 0:
            column_data = self.row_header_data
        else:
            column_data = self.column_data[column[0]]
        obj = self.data[row[0]]
        column_data.set_value(obj, value)
        self.values_changed = (row, column, row, column)
Esempio n. 3
0
    def set_editor_value(self, model, row, column, value):
        """ Set the editable representation of the underlying value.

        The default expects a string that can be parsed to a color 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.
        value : str
            A string that can be parsed to a color value.

        Returns
        -------
        success : bool
            Whether or not the value was successfully set.
        """
        try:
            color = Color.from_str(value)
        except Exception:
            raise DataViewSetError()
        return super().set_editor_value(model, row, column, color)
Esempio n. 4
0
    def set_value(self, obj, value):
        """ Set the value on the provided object.

        Parameters
        ----------
        obj : any
            The object that contains the data.
        value : any
            The data value to set.

        Raises
        -------
        DataViewSetError
            If setting the value fails.
        """
        raise DataViewSetError("Cannot set {!r} column of {!r}.".format(
            self.title, obj))
Esempio n. 5
0
    def set_value(self, obj, value):
        """ Set the value on the provided object.

        Parameters
        ----------
        obj : any
            The object that contains the data.
        value : any
            The data value to set.

        Raises
        -------
        DataViewSetError
            If setting the value fails.
        """
        if not self.can_set_value(obj):
            raise DataViewSetError("Cannot set {!r} key of {!r}.".format(
                self.key, obj))
        obj[self.key] = value
Esempio n. 6
0
    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()
Esempio n. 7
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))
Esempio n. 8
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)
Esempio n. 9
0
 def set_value(self, obj, value):
     if not self.can_set_value(obj):
         raise DataViewSetError(
             "Attribute is not specified for {!r}".format(self))
     xsetattr(obj, self.attr, value)