示例#1
0
文件: lines.py 项目: Darriall/editor
 def append(self, text):
     """Append line to the end
     """
     cursor = QTextCursor(self._doc)
     cursor.movePosition(QTextCursor.End)
     cursor.insertBlock()
     cursor.insertText(text)
示例#2
0
文件: lines.py 项目: Darriall/editor
 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)