def clone(self, parent=None) -> 'TerminalTextDocument': """Create a new TerminalTextDocument that is a copy of this document.""" clone = type(self)() clone.setParent(parent) clone.setDocumentLayout(QPlainTextDocumentLayout(clone)) cursor = QTextCursor(clone) cursor.insertFragment(QTextDocumentFragment(self)) clone.rootFrame().setFrameFormat(self.rootFrame().frameFormat()) clone.setDefaultStyleSheet(self.defaultStyleSheet()) clone.setDefaultFont(self.defaultFont()) clone.setDefaultTextOption(self.defaultTextOption()) clone.setCurrentCharFormat(self.currentCharFormat()) for s, w in self.__streams: clone.connectStream(s, w.charformat if w is not None else None) return clone
def copy(): cursor = item.textCursor() if cursor.hasSelection(): mime = createMimeDataFromSelection(QTextDocumentFragment(cursor)) QApplication.clipboard().setMimeData(mime)