Esempio n. 1
0
 def append(self, text):
     """Append line to the end
     """
     cursor = QTextCursor(self._doc)
     cursor.movePosition(QTextCursor.End)
     cursor.insertBlock()
     cursor.insertText(text)
Esempio n. 2
0
 def insert(self, index, text):
     """Insert line to the document
     """
     if index < 0 or index > self._doc.blockCount():
         raise IndexError('Invalid block index', index)
     
     if index == 0:  # first
         cursor = QTextCursor(self._doc.firstBlock())
         cursor.insertText(text)
         cursor.insertBlock()
     elif index != self._doc.blockCount():  # not the last
         cursor = QTextCursor(self._doc.findBlockByNumber(index).previous())
         cursor.movePosition(QTextCursor.EndOfBlock)
         cursor.insertBlock()
         cursor.insertText(text)
     else:  # last append to the end
         self.append(text)