(self, index, value)
Set item by index
Set item by index
Set item by index
def __setitem__(self, index, value):
        """Set item by index
        """
        def _setBlockText(blockIndex, text):
            cursor = QTextCursor(self._doc.findBlockByNumber(blockIndex))
            cursor.movePosition(QTextCursor.EndOfBlock, QTextCursor.KeepAnchor)
            cursor.insertText(text)

        if isinstance(index, int):
            index = self._checkAndConvertIndex(index)
            _setBlockText(index, value)
        elif isinstance(index, slice):
            # List of indexes is reversed for make sure
            # not processed indexes are not shifted during document modification
            start, stop, step = index.indices(self._doc.blockCount())
            if step > 0:
                start, stop, step = stop - 1, start - 1, step * -1

            blockIndexes = list(range(start, stop, step))

            if len(blockIndexes) != len(value):
                raise ValueError('Attempt to replace %d lines with %d lines' %
                                 (len(blockIndexes), len(value)))

            for blockIndex, text in zip(blockIndexes, value[::-1]):
                _setBlockText(blockIndex, text)
def __setitem__ ( self , index , value ) : def _setBlockText ( blockIndex , text ) : cursor = QTextCursor ( self . _doc . findBlockByNumber ( blockIndex ) ) cursor . movePosition ( QTextCursor . EndOfBlock , QTextCursor . KeepAnchor ) cursor . insertText ( text ) if isinstance ( index , int ) : index = self . _checkAndConvertIndex ( index ) _setBlockText ( index , value ) elif isinstance ( index , slice ) : # List of indexes is reversed for make sure # not processed indexes are not shifted during document modification start , stop , step = index . indices ( self . _doc . blockCount ( ) ) if step > 0 : start , stop , step = stop - 1 , start - 1 , step * - 1 blockIndexes = list ( range ( start , stop , step ) ) if len ( blockIndexes ) != len ( value ) : raise ValueError ( 'Attempt to replace %d lines with %d lines' % ( len ( blockIndexes ) , len ( value ) ) ) for blockIndex , text in zip ( blockIndexes , value [ : : - 1 ] ) : _setBlockText ( blockIndex , text )