(self, index, value)
Set items by [y, x] indexing or slicing.
Set items by [y, x] indexing or slicing.
Set items by [ y x ] indexing or slicing .
def __setitem__(self, index, value):
        """Set items by [y, x] indexing or slicing."""
        y, x = index
        if isinstance(value, int):
            if isinstance(x, slice):
                if isinstance(y, slice):
                    for row in self._rows[y]:
                        row[x] = bytearray(value for _ in iterbytes(row[x]))
                else:
                    self._rows[y][x] = bytearray(value for _ in iterbytes(self._rows[y][x]))
            else:
                if isinstance(y, slice):
                    for row in self._rows[y]:
                        row[x] = value
                else:
                    self._rows[y][x] = value
        else:
            if isinstance(value, ByteMatrix):
                value = value._rows
            elif type(value) not in (list, int):
                raise TypeError(
                    'Can only assign ByteMatrix, list of bytes-like or int, not %s.' % type(value)
                )
            if isinstance(y, slice):
                if isinstance(x, slice):
                    # this will fail if we're self-assigning a slice of a view to the original view
                    # as we'll be overwriting the source while writing to the destination.
                    # in those cases, we'll need to copy first
                    for _dst, _src in zip(self._rows[y], value):
                        # if x is a slice, this will copy too -> e.g. array[:] = another_array
                        # but not if rhs is a view?
                        _dst[x] = bytearray(_src)
                else:
                    for _dst, _src in zip(self._rows[y], value):
                        # if x is a slice, this will copy too -> e.g. array[:] = another_array
                        # but not if rhs is a view?
                        _dst[x] = _src[0]
            elif isinstance(x, slice):
                assert len(value) == 1
                self._rows[y][x] = value[0]
def __setitem__ ( self , index , value ) : y , x = index if isinstance ( value , int ) : if isinstance ( x , slice ) : if isinstance ( y , slice ) : for row in self . _rows [ y ] : row [ x ] = bytearray ( value for _ in iterbytes ( row [ x ] ) ) else : self . _rows [ y ] [ x ] = bytearray ( value for _ in iterbytes ( self . _rows [ y ] [ x ] ) ) else : if isinstance ( y , slice ) : for row in self . _rows [ y ] : row [ x ] = value else : self . _rows [ y ] [ x ] = value else : if isinstance ( value , ByteMatrix ) : value = value . _rows elif type ( value ) not in ( list , int ) : raise TypeError ( 'Can only assign ByteMatrix, list of bytes-like or int, not %s.' % type ( value ) ) if isinstance ( y , slice ) : if isinstance ( x , slice ) : # this will fail if we're self-assigning a slice of a view to the original view # as we'll be overwriting the source while writing to the destination. # in those cases, we'll need to copy first for _dst , _src in zip ( self . _rows [ y ] , value ) : # if x is a slice, this will copy too -> e.g. array[:] = another_array # but not if rhs is a view? _dst [ x ] = bytearray ( _src ) else : for _dst , _src in zip ( self . _rows [ y ] , value ) : # if x is a slice, this will copy too -> e.g. array[:] = another_array # but not if rhs is a view? _dst [ x ] = _src [ 0 ] elif isinstance ( x , slice ) : assert len ( value ) == 1 self . _rows [ y ] [ x ] = value [ 0 ]